ML Ecosystem in PHP

Learning examples

These examples will help you understand how you can use ML in PHP. They are not full-fledged applications, but they will help you understand the basics of working with ML in PHP.

Example with MITIE PHP

MITIE PHP is a PHP wrapper over MITIE (MIT Information Extraction) for classic NLP tasks. The snippet below extracts named entities from text and returns their types, such as person, organization, and location.

 
<?php

use Mitie\NER;

$modelPath 'ner_model.dat';

$text 'Barack Obama visited Microsoft headquarters in Seattle.';

$ner = new NER($modelPath);
$entities $ner->entities($text);

print_r($entities);
Result: Memory: 0.002 Mb Time running: < 0.001 sec.
Array
(
    [0] => Array
        (
            [text] => Barack Obama
            [tag] => PERSON
        )

    [1] => Array
        (
            [text] => Microsoft
            [tag] => ORGANIZATION
        )

    [2] => Array
        (
            [text] => Seattle
            [tag] => LOCATION
        )

)