PHPackages                             jbainpro/mitie - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jbainpro/mitie

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jbainpro/mitie
==============

Named-entity recognition for PHP

01PHP

Since Nov 14Pushed 2y agoCompare

[ Source](https://github.com/jbainpro/mitie-nlp-php)[ Packagist](https://packagist.org/packages/jbainpro/mitie)[ RSS](/packages/jbainpro-mitie/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

MITIE PHP
=========

[](#mitie-php)

[MITIE](https://github.com/mit-nlp/MITIE) - named-entity recognition, binary relation detection, and text categorization - for PHP

- Finds people, organizations, and locations in text
- Detects relationships between entities, like `PERSON` was born in `LOCATION`

[![Build Status](https://github.com/ankane/mitie-php/workflows/build/badge.svg?branch=master)](https://github.com/ankane/mitie-php/actions)

Installation
------------

[](#installation)

Run:

```
composer require ankane/mitie
```

Download the shared library:

```
composer exec -- php -r "require 'vendor/autoload.php'; Mitie\Vendor::check(true);"
```

And download the pre-trained models for your language:

- [English](https://github.com/mit-nlp/MITIE/releases/download/v0.4/MITIE-models-v0.2.tar.bz2)
- [Spanish](https://github.com/mit-nlp/MITIE/releases/download/v0.4/MITIE-models-v0.2-Spanish.zip)
- [German](https://github.com/mit-nlp/MITIE/releases/download/v0.4/MITIE-models-v0.2-German.tar.bz2)

Getting Started
---------------

[](#getting-started)

- [Named Entity Recognition](#named-entity-recognition)
- [Binary Relation Detection](#binary-relation-detection)
- [Text Categorization](#text-categorization)

Named Entity Recognition
------------------------

[](#named-entity-recognition)

Load an NER model

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

Create a document

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

Get entities

```
$doc->entities();
```

This returns

```
[
    ['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]
]
```

Get tokens

```
$doc->tokens();
```

Get tokens and their offset

```
$doc->tokensWithOffset();
```

Get all tags for a model

```
$model->tags();
```

### Training

[](#training)

Load an NER model into a trainer

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

Create training instances

```
$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
```

Add the training instances to the trainer

```
$trainer->add($instance);
```

Train the model

```
$model = $trainer->train();
```

Save the model

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

Binary Relation Detection
-------------------------

[](#binary-relation-detection)

Detect relationships betweens two entities, like:

- `PERSON` was born in `LOCATION`
- `ORGANIZATION` was founded in `LOCATION`
- `FILM` was directed by `PERSON`

There are 21 detectors for English. You can find them in the `binary_relations` directory in the model download.

Load a detector

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

And create a document

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

Get relations

```
$detector->relations($doc);
```

This returns

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

### Training

[](#training-1)

Load an NER model into a trainer

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

Add positive and negative examples to the trainer

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

Train the detector

```
$detector = $trainer->train();
```

Save the detector

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

Text Categorization
-------------------

[](#text-categorization)

Load a model into a trainer

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

Add labeled text to the trainer

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

Train the model

```
$model = $trainer->train();
```

Save the model

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

Load a saved model

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

Categorize text

```
$model->categorize('What a super nice day');
```

History
-------

[](#history)

View the [changelog](CHANGELOG.md)

Contributing
------------

[](#contributing)

Everyone is encouraged to help improve this project. Here are a few ways you can help:

- [Report bugs](https://github.com/ankane/mitie-php/issues)
- Fix bugs and [submit pull requests](https://github.com/ankane/mitie-php/pulls)
- Write, clarify, or fix documentation
- Suggest or add new features

To get started with development:

```
git clone https://github.com/ankane/mitie-php.git
cd mitie-php
composer install
composer test
```

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity20

Early-stage or recently created project

 Bus Factor1

Top contributor holds 87% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/eb1bdeb4ee185cc8c56b9f60a1fdcc65cfbdef6f3e9107242e4e1807bed7b712?d=identicon)[jbainpro](/maintainers/jbainpro)

---

Top Contributors

[![ankane](https://avatars.githubusercontent.com/u/220358?v=4)](https://github.com/ankane "ankane (20 commits)")[![jbainpro](https://avatars.githubusercontent.com/u/60293260?v=4)](https://github.com/jbainpro "jbainpro (3 commits)")

### Embed Badge

![Health badge](/badges/jbainpro-mitie/health.svg)

```
[![Health](https://phpackages.com/badges/jbainpro-mitie/health.svg)](https://phpackages.com/packages/jbainpro-mitie)
```

###  Alternatives

[bennettstone/magicmin

MagicMin is a PHP based javascript and stylesheet minification and merging class designed to generate minified, merged, and automatically updating files to simplify the process of minified file usage and updating when going between production and development environments.

495.4k](/packages/bennettstone-magicmin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
