'Train a new maxent classifier based on the given corpus of
training samples.  This classifier will have its weights
chosen to maximize entropy while remaining empirically
consistent with the training corpus.
:rtype: MaxentClassifier
:return: The new maxent classifier
:type train_toks: list
:param train_toks: Training data, represented as a list of
pairs, the first member of which is a featureset,
and the second of which is a classification label.
:type algorithm: str
:param algorithm: A case-insensitive string, specifying which
algorithm should be used to train the classifier.  The
following algorithms are currently available.
- Iterative Scaling Methods: Generalized Iterative Scaling (``\'GIS\'``),
Improved Iterative Scaling (``\'IIS\'``)
- External Libraries (requiring megam):
LM-BFGS algorithm, with training performed by Megam (``\'megam\'``)
The default algorithm is ``\'IIS\'``.
:type trace: int
:param trace: The level of diagnostic tracing output to produce.
Higher values produce more verbose output.
:type encoding: MaxentFeatureEncodingI
:param encoding: A feature encoding, used to convert featuresets
into feature vectors.  If none is specified, then a
``BinaryMaxentFeatureEncoding`` will be built based on the
features that are attested in the training corpus.
:type labels: list(str)
:param labels: The set of possible labels.  If none is given, then
the set of all labels attested in the training data will be
used instead.
:param gaussian_prior_sigma: The sigma value for a gaussian
prior on model weights.  Currently, this is supported by
``megam``. For other algorithms, its value is ignored.
:param cutoffs: Arguments specifying various conditions under
which the training should be halted.  (Some of the cutoff
conditions are not supported by some algorithms.)
- ``max_iter=v``: Terminate after ``v`` iterations.
- ``min_ll=v``: Terminate after the negative average
log-likelihood drops under ``v``.
- ``min_lldelta=v``: Terminate if a single iteration improves
log likelihood by less than ``v``.'

@classmethod
def train(cls, train_toks, algorithm=None, trace=3, encoding=None, labels=None, gaussian_prior_sigma=0, **cutoffs):

    if (algorithm is None):
        algorithm = u'iis'
    for key in cutoffs:
        if (key not in (u'max_iter', u'min_ll', u'min_lldelta', u'max_acc', u'min_accdelta', u'count_cutoff', u'norm', u'explicit', u'bernoulli')):
            raise TypeError((u'Unexpected    keyword    arg    %r' % key))
    algorithm = algorithm.lower()
    if (algorithm == u'iis'):
        return train_maxent_classifier_with_iis(train_toks, trace, encoding, labels, **cutoffs)
    elif (algorithm == u'gis'):
        return train_maxent_classifier_with_gis(train_toks, trace, encoding, labels, **cutoffs)
    elif (algorithm == u'megam'):
        return train_maxent_classifier_with_megam(train_toks, trace, encoding, labels, gaussian_prior_sigma, **cutoffs)
    elif (algorithm == u'tadm'):
        kwargs = cutoffs
        kwargs[u'trace'] = trace
        kwargs[u'encoding'] = encoding
        kwargs[u'labels'] = labels
        kwargs[u'gaussian_prior_sigma'] = gaussian_prior_sigma
        return TadmMaxentClassifier.train(train_toks, **kwargs)
    else:
        raise ValueError((u'Unknown    algorithm    %s' % algorithm))
