PHP code example of ankane / mitie

1. Go to this page and download the library: Download ankane/mitie library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ankane / mitie example snippets


$model = new Mitie\NER('ner_model.dat');

$doc = $model->doc('Nat works at GitHub in San Francisco');

$doc->entities();

[
    ['text' => 'Nat',           'tag' => 'PERSON',       'score' => 0.3112371212688382, 'offset' => 0],
    ['text' => 'GitHub',        'tag' => 'ORGANIZATION', 'score' => 0.5660115198329334, 'offset' => 13],
    ['text' => 'San Francisco', 'tag' => 'LOCATION',     'score' => 1.3890524313885309, 'offset' => 23]
]

$doc->tokens();

$doc->tokensWithOffset();

$model->tags();

$trainer = new Mitie\NERTrainer('total_word_feature_extractor.dat');

$tokens = ['You', 'can', 'do', 'machine', 'learning', 'in', 'PHP', '!'];
$instance = new Mitie\NERTrainingInstance($tokens);
$instance->addEntity(3, 4, 'topic');    // machine learning
$instance->addEntity(6, 6, 'language'); // PHP

$trainer->add($instance);

$model = $trainer->train();

$model->saveToDisk('ner_model.dat');

$detector = new Mitie\BinaryRelationDetector('rel_classifier_organization.organization.place_founded.svm');

$doc = $model->doc('Shopify was founded in Ottawa');

$detector->relations($doc);

[['first' => 'Shopify', 'second' => 'Ottawa', 'score' => 0.17649169745814464]]

$trainer = new Mitie\BinaryRelationTrainer($model);

$tokens = ['Shopify', 'was', 'founded', 'in', 'Ottawa'];
$trainer->addPositiveBinaryRelation($tokens, [0, 0], [4, 4]);
$trainer->addNegativeBinaryRelation($tokens, [4, 4], [0, 0]);

$detector = $trainer->train();

$detector->saveToDisk('binary_relation_detector.svm');

$trainer = new Mitie\TextCategorizerTrainer('total_word_feature_extractor.dat');

$trainer->add('This is super cool', 'positive');

$model = $trainer->train();

$model->saveToDisk('text_categorization_model.dat');

$model = new Mitie\TextCategorizer('text_categorization_model.dat');

$model->categorize('What a super nice day');
sh
git clone https://github.com/ankane/mitie-php.git
cd mitie-php
composer install
composer test