NlpTools API
Class

NlpTools\Optimizers\ExternalMaxentOptimizer

class ExternalMaxentOptimizer implements MaxentOptimizerInterface

This class enables the use of a program written in a different language to optimize our model and return the weights for use in php.

Mostly common use: Optimize in a fast compiled language (ex.: C) or
a language with great libraries (ex.: Matlab)

Output a json array that contains all the necessary information to
train the model and determine the weights that maximize the
conditional log likelihood of the training data

The array has one element for each training document. The element is
a map with each possible class as key and an array of features that
fire for each class. There is a special key called '__label__' that
contains a string value which is the actual class of this document

Ex.:
[
{
"class1": ["feature1","feature2","feature3"],
"class2": ["feature1","feature4","feature5"],
"__label__": "class1"
},
{
"class1": ["feature2","feature3"],
"class2": ["feature1","feature4","feature5"],
"__label__": "class1"
},
{
"class1": ["feature1","feature2","feature3"],
"class2": ["feature1"],
"__label__": "class2"
}
]

Send this array to an external program that will return a map of
floats in json that will contain the weight for each feature.

Methods

__construct(string $optimizer)

array optimize(array $feature_array)

This function receives an array that contains an array for each document which contains an array of feature identifiers for each class and at the special key '__label__' the actual class of the training document.

Details

at line 51
public __construct(string $optimizer)

Parameters

string $optimizer The path for an external optimizer executable

at line 63
public array optimize(array $feature_array)

This function receives an array that contains an array for each document which contains an array of feature identifiers for each class and at the special key '__label__' the actual class of the training document.

As a result it contains all the information needed to train a
set of weights with any target. Ex.: If we were training a maxent
model we would try to maximize the CLogLik that can be calculated
from this array.

Parameters

array $feature_array The features that fired for any document for any class see NlpTools\Models\Maxent

Return Value

array The optimized weights