Class GISTrainer

Namespace
NOpenNLP.Tools.Ml.Maxent
Assembly
NOpenNLP.Tools.dll

An implementation of Generalized Iterative Scaling. The reference paper for this implementation was Adwait Ratnaparkhi's tech report at the University of Pennsylvania's Institute for Research in Cognitive Science, and is available at ftp://ftp.cis.upenn.edu/pub/ircs/tr/97-08.ps.Z.

The slack parameter used in the above implementation has been removed by default from the computation and a method for updating with Gaussian smoothing has been added per Investigating GIS and Smoothing for Maximum Entropy Taggers, Clark and Curran (2002). http://acl.ldc.upenn.edu/E/E03/E03-1071.pdf Gaussian smoothing can be used by setting useGaussianSmoothing to true.

A prior can be used to train models which converge to the distribution which minimizes the relative entropy between the distribution specified by the empirical constraints of the training data and the specified prior. By default, the uniform distribution is used as the prior.

public class GISTrainer : AbstractEventTrainer, IEventTrainer
Inheritance
GISTrainer
Implements
Inherited Members

Constructors

GISTrainer()

Creates a new GISTrainer instance which does not print progress messages about training to the console.

public GISTrainer()

Fields

LOG_LIKELIHOOD_THRESHOLD_DEFAULT

public const double LOG_LIKELIHOOD_THRESHOLD_DEFAULT = 0.0001

Field Value

double

LOG_LIKELIHOOD_THRESHOLD_PARAM

public const string LOG_LIKELIHOOD_THRESHOLD_PARAM = "LLThreshold"

Field Value

string

MAXENT_VALUE

public const string MAXENT_VALUE = "MAXENT"

Field Value

string

OLD_LL_THRESHOLD_PARAM

[Obsolete("Use LOG_LIKELIHOOD_THRESHOLD_PARAM instead.")]
public const string OLD_LL_THRESHOLD_PARAM = "llthreshold"

Field Value

string

Properties

GaussianSigma

Turns on Gaussian smoothing and sets its sigma value.

public virtual double GaussianSigma { set; }

Property Value

double

IsSortAndMerge

Whether the data indexer should sort and merge the indexed events.

public override bool IsSortAndMerge { get; }

Property Value

bool

Smoothing

Sets whether this trainer will use smoothing while training the model. This can improve model accuracy, though training will potentially take longer and use more memory. Model size will also be larger.

public virtual bool Smoothing { set; }

Property Value

bool

SmoothingObservation

Sets the "number" of times we want the trainer to imagine it saw a feature that it actually didn't see.

public virtual double SmoothingObservation { set; }

Property Value

double

Methods

DoTrain(IDataIndexer)

Trains a model from the given, already indexed, training data.

public override IMaxentModel DoTrain(IDataIndexer indexer)

Parameters

indexer IDataIndexer

Returns

IMaxentModel

Init(TrainingParameters, IDictionary<string, string>?)

Initializes this trainer with the given parameters and report map.

public override void Init(TrainingParameters trainingParameters, IDictionary<string, string>? reportMap)

Parameters

trainingParameters TrainingParameters
reportMap IDictionary<string, string>

TrainModel(IObjectStream<Event?>)

Trains a model using the GIS algorithm, assuming 100 iterations and no cutoff.

public virtual GISModel TrainModel(IObjectStream<Event?> eventStream)

Parameters

eventStream IObjectStream<Event>

The event stream holding the data on which this model will be trained.

Returns

GISModel

The newly trained model, which can be used immediately or saved to disk using a GISModelWriter.

TrainModel(IObjectStream<Event?>, int, int)

Trains a GIS model on the events in the specified event stream, using the specified number of iterations and the specified count cutoff.

public virtual GISModel TrainModel(IObjectStream<Event?> eventStream, int iterations, int cutoff)

Parameters

eventStream IObjectStream<Event>

A stream of all events.

iterations int

The number of iterations to use for GIS.

cutoff int

The number of times a feature must occur to be included.

Returns

GISModel

A GIS model trained with the specified parameters.

TrainModel(int, IDataIndexer)

Trains a model using the GIS algorithm.

public virtual GISModel TrainModel(int iterations, IDataIndexer di)

Parameters

iterations int

The number of GIS iterations to perform.

di IDataIndexer

The data indexer used to compress events in memory.

Returns

GISModel

TrainModel(int, IDataIndexer, IPrior, int)

Trains a model using the GIS algorithm.

public virtual GISModel TrainModel(int iterations, IDataIndexer di, IPrior modelPrior, int threads)

Parameters

iterations int

The number of GIS iterations to perform.

di IDataIndexer

The data indexer used to compress events in memory.

modelPrior IPrior

The prior distribution used to train this model.

threads int

The number of threads to compute model expectations with.

Returns

GISModel

TrainModel(int, IDataIndexer, int)

Trains a model using the GIS algorithm.

public virtual GISModel TrainModel(int iterations, IDataIndexer di, int threads)

Parameters

iterations int

The number of GIS iterations to perform.

di IDataIndexer

The data indexer used to compress events in memory.

threads int

The number of threads to compute model expectations with.

Returns

GISModel