language detection example
This commit is contained in:
commit
c24978693b
6 files changed
+195
No files matched your search
@@ -0,0 +1,3 @@
|
||||
/vendor/
|
||||
humbuglog.*
|
||||
/bin/phpunit
|
||||
@@ -0,0 +1,15 @@
|
||||
# PHP-ML - Machine Learning library for PHP - Examples
|
||||
|
||||
Examples of the use of PHP-ML library
|
||||
|
||||
## Examples
|
||||
|
||||
* LanguageDetection.php - classifier build for language detection
|
||||
|
||||
## License
|
||||
|
||||
PHP-ML is released under the MIT Licence. See the bundled LICENSE file for details.
|
||||
|
||||
## Author
|
||||
|
||||
Arkadiusz Kondas (@ArkadiuszKondas)
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "php-ai/php-ml-examples",
|
||||
"type": "project",
|
||||
"description": "Examples of the use of PHP-ML library",
|
||||
"license": "MIT",
|
||||
"keywords": ["machine learning","pattern recognition","computational learning theory","artificial intelligence"],
|
||||
"homepage": "https://github.com/php-ai/php-ml-examples",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Arkadiusz Kondas",
|
||||
"email": "arkadiusz.kondas@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php-ai/php-ml": "dev-develop"
|
||||
}
|
||||
}
|
||||
Generated
+67
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "1342a147b788083a903bdd811cf8b1a8",
|
||||
"content-hash": "073a4d8adce8080a2e60222db7a59192",
|
||||
"packages": [
|
||||
{
|
||||
"name": "php-ai/php-ml",
|
||||
"version": "dev-develop",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-ai/php-ml.git",
|
||||
"reference": "6c7416a9c40b596afce625617dce07892ccaa2fc"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-ai/php-ml/zipball/6c7416a9c40b596afce625617dce07892ccaa2fc",
|
||||
"reference": "6c7416a9c40b596afce625617dce07892ccaa2fc",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.2"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Phpml": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Arkadiusz Kondas",
|
||||
"email": "arkadiusz.kondas@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "PHP-ML - Machine Learning library for PHP",
|
||||
"homepage": "https://github.com/php-ai/php-ml",
|
||||
"keywords": [
|
||||
"artificial intelligence",
|
||||
"computational learning theory",
|
||||
"machine learning",
|
||||
"pattern recognition"
|
||||
],
|
||||
"time": "2016-07-06 22:29:58"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {
|
||||
"php-ai/php-ml": 20
|
||||
},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": []
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
"sentence","language"
|
||||
"Hello, do you know what time the movie is tonight?","english"
|
||||
"I am calling to make reservations","english"
|
||||
"I would like to know if it is at all possible to check in","english"
|
||||
"What time does the swimming pool open?","english"
|
||||
"Where is the games room?","english"
|
||||
"We must call the police.","english"
|
||||
"How many pupils are there in your school?","english"
|
||||
"Twenty litres of unleaded, please.","english"
|
||||
"Is it near here?","english"
|
||||
"Do I have to change?","english"
|
||||
"Which counter do I go to to change money?","english"
|
||||
"I would like two postcards, please.","english"
|
||||
"There was a big explosion.","english"
|
||||
"Where is the television room?","english"
|
||||
"Where's the nearest railway station?","english"
|
||||
"The storms caused flooding.","english"
|
||||
"Where is the duty free shop?","english"
|
||||
"I witnessed it happening.","english"
|
||||
"I would like two postcards, please.","english"
|
||||
"How about going to the cinema?","english"
|
||||
"Où est la boulangerie?","french"
|
||||
"Je voudrais une boîte de chocolates.","french"
|
||||
"Y a-t-il un autre hôtel près d'ici?","french"
|
||||
"Vérifiez la batterie, s'il vous plaît.","french"
|
||||
"La banque ouvre à quelle heure?","french"
|
||||
"Est-ce que je peux l'écouter?","french"
|
||||
"Vous devez faire une déclaration de perte.","french"
|
||||
"Combien des élèves y a-t-il dans votre collège?","french"
|
||||
"Est-ce qu-il ya un car qui va à l'aéroport?","french"
|
||||
"Nous voudrions rester jusqu'à Dimanche prochain.","french"
|
||||
"Je ne comprends pas.","french"
|
||||
"Voici une ordonnance pour des comprimés.","french"
|
||||
"Je n'ai qu'un billet de cinquante francs.","french"
|
||||
"À quelle heure commence le dernière séance?","french"
|
||||
"Faut-il changer?","french"
|
||||
"Il n'avait pas la priorité.","french"
|
||||
"Puis-je prendre les places à l'avance?","french"
|
||||
"Elle a trente et un ans.","french"
|
||||
"Pour aller à la pharmacie, s'il vous plaît?","french"
|
||||
"Voulez-vous me peser ce colis, s'il vous plaît.","french"
|
||||
"Ciao, ti va di andare al cinema?","italian"
|
||||
"Mi sai dire quando aprono il negozio?","italian"
|
||||
"Quando c'è l'ultimo autobus?","italian"
|
||||
"Lo posso provare addosso?","italian"
|
||||
"C'è una presa elettrica per il nostro caravan?","italian"
|
||||
"Vorrei una scatola di cioccolatini.","italian"
|
||||
"Non e' stata colpa mia.","italian"
|
||||
"Sono molto scarso in fisica.","italian"
|
||||
"Vorrei del vino bianco.","italian"
|
||||
"Me lo puo' spiegare, per piacere.","italian"
|
||||
"Vorrei chiamare a spese del ricevente.","italian"
|
||||
"Ho perso il mio passaporto.","italian"
|
||||
"Posso avere i biglietti del cinema per favore?","italian"
|
||||
"Vorrei un pacchetto di biscotti.","italian"
|
||||
"Quali materie studi (studia)?","italian"
|
||||
"Quanto frequenti sono gli autobus?","italian"
|
||||
"A che ora sara' la prossima raccolta?","italian"
|
||||
"Vorrei prenotare un posto.","italian"
|
||||
"Per favore, quanto costa spedire una lettera in Germania?","italian"
|
||||
"Mio padre e' un programmatore.","italian"
|
||||
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
include 'vendor/autoload.php';
|
||||
|
||||
use Phpml\Dataset\CsvDataset;
|
||||
use Phpml\Dataset\ArrayDataset;
|
||||
use Phpml\FeatureExtraction\TokenCountVectorizer;
|
||||
use Phpml\Tokenization\WordTokenizer;
|
||||
use Phpml\CrossValidation\RandomSplit;
|
||||
use Phpml\Metric\Accuracy;
|
||||
use Phpml\Classification\SVC;
|
||||
use Phpml\SupportVectorMachine\Kernel;
|
||||
|
||||
$dataset = new CsvDataset('data/languages.csv', 1);
|
||||
$vectorizer = new TokenCountVectorizer(new WordTokenizer());
|
||||
|
||||
$samples = [];
|
||||
foreach ($dataset->getSamples() as $sample) {
|
||||
$samples[] = $sample[0];
|
||||
}
|
||||
|
||||
$vectorizer->transform($samples);
|
||||
$dataset = new ArrayDataset($samples, $dataset->getTargets());
|
||||
|
||||
$randomSplit = new RandomSplit($dataset, 0.25);
|
||||
|
||||
$classifier = new SVC(Kernel::RBF, 100);
|
||||
$classifier->train($randomSplit->getTrainSamples(), $randomSplit->getTrainLabels());
|
||||
|
||||
$predictedLabels = $classifier->predict($randomSplit->getTestSamples());
|
||||
|
||||
echo Accuracy::score($randomSplit->getTestLabels(), $predictedLabels);
|
||||
Reference in new issue
Block a user