§
    'ê[fùí  ã                   óú  — d Z 	 ddlZn# e$ r Y nw xY wddlZddlZddlmZ ddlmZ ddl	m
Z
mZmZ ddlmZmZmZ ddlmZmZmZ ddlmZ dd	lmZ dd
lmZ dZ G d„ de¦  «        ZeZ G d„ d¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z  G d„ de ¦  «        Z! G d„ de ¦  «        Z" G d„ de¦  «        Z#	 d&d„Z$d„ Z%d„ Z&	 d&d„Z'd„ Z(d „ Z)	 d'd!„Z* G d"„ d#e¦  «        Z+d$„ Z,e-d%k    r e,¦   «          dS dS )(aä  
A classifier model based on maximum entropy modeling framework.  This
framework considers all of the probability distributions that are
empirically consistent with the training data; and chooses the
distribution with the highest entropy.  A probability distribution is
"empirically consistent" with a set of training data if its estimated
frequency with which a class and a feature vector value co-occur is
equal to the actual frequency in the data.

Terminology: 'feature'
======================
The term *feature* is usually used to refer to some property of an
unlabeled token.  For example, when performing word sense
disambiguation, we might define a ``'prevword'`` feature whose value is
the word preceding the target word.  However, in the context of
maxent modeling, the term *feature* is typically used to refer to a
property of a "labeled" token.  In order to prevent confusion, we
will introduce two distinct terms to disambiguate these two different
concepts:

  - An "input-feature" is a property of an unlabeled token.
  - A "joint-feature" is a property of a labeled token.

In the rest of the ``nltk.classify`` module, the term "features" is
used to refer to what we will call "input-features" in this module.

In literature that describes and discusses maximum entropy models,
input-features are typically called "contexts", and joint-features
are simply referred to as "features".

Converting Input-Features to Joint-Features
-------------------------------------------
In maximum entropy models, joint-features are required to have numeric
values.  Typically, each input-feature ``input_feat`` is mapped to a
set of joint-features of the form:

|   joint_feat(token, label) = { 1 if input_feat(token) == feat_val
|                              {      and label == some_label
|                              {
|                              { 0 otherwise

For all values of ``feat_val`` and ``some_label``.  This mapping is
performed by classes that implement the ``MaxentFeatureEncodingI``
interface.
é    N)Údefaultdict)ÚClassifierI)Ú
call_megamÚparse_megam_weightsÚwrite_megam_file)Ú	call_tadmÚparse_tadm_weightsÚwrite_tadm_file)ÚCutoffCheckerÚaccuracyÚlog_likelihood)Úgzip_open_unicode)ÚDictionaryProbDist)ÚOrderedDictz
epytext enc                   ó€   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	dd
„Z
dd„Zdd„Zd„ Zg d¢Ze	 	 	 	 	 dd„¦   «         ZdS )ÚMaxentClassifieraî  
    A maximum entropy classifier (also known as a "conditional
    exponential classifier").  This classifier is parameterized by a
    set of "weights", which are used to combine the joint-features
    that are generated from a featureset by an "encoding".  In
    particular, the encoding maps each ``(featureset, label)`` pair to
    a vector.  The probability of each label is then computed using
    the following equation::

                                dotprod(weights, encode(fs,label))
      prob(fs|label) = ---------------------------------------------------
                       sum(dotprod(weights, encode(fs,l)) for l in labels)

    Where ``dotprod`` is the dot product::

      dotprod(a,b) = sum(x*y for (x,y) in zip(a,b))
    Tc                 ó~   — || _         || _        || _        |                     ¦   «         t	          |¦  «        k    sJ ‚dS )a{  
        Construct a new maxent classifier model.  Typically, new
        classifier models are created using the ``train()`` method.

        :type encoding: MaxentFeatureEncodingI
        :param encoding: An encoding that is used to convert the
            featuresets that are given to the ``classify`` method into
            joint-feature vectors, which are used by the maxent
            classifier model.

        :type weights: list of float
        :param weights:  The feature weight vector for this classifier.

        :type logarithmic: bool
        :param logarithmic: If false, then use non-logarithmic weights.
        N)Ú	_encodingÚ_weightsÚ_logarithmicÚlengthÚlen)ÚselfÚencodingÚweightsÚlogarithmics       úH/var/www/piapp/venv/lib/python3.11/site-packages/nltk/classify/maxent.pyÚ__init__zMaxentClassifier.__init__a   sA   € ð" "ˆŒØˆŒØ'ˆÔà�ŠÑ Ô ¥C¨¡L¤LÒ0Ð0Ð0Ð0Ð0Ð0ó    c                 ó4   — | j                              ¦   «         S ©N)r   Úlabels©r   s    r   r"   zMaxentClassifier.labelsx   s   € ØŒ~×$Ò$Ñ&Ô&Ð&r   c                 ól   — || _         | j                             ¦   «         t          |¦  «        k    sJ ‚dS )z¨
        Set the feature weight vector for this classifier.
        :param new_weights: The new feature weight vector.
        :type new_weights: list of float
        N)r   r   r   r   )r   Únew_weightss     r   Úset_weightszMaxentClassifier.set_weights{   s8   € ð $ˆŒØŒ~×$Ò$Ñ&Ô&­#¨kÑ*:Ô*:Ò:Ð:Ð:Ð:Ð:Ð:r   c                 ó   — | j         S )zg
        :return: The feature weight vector for this classifier.
        :rtype: list of float
        ©r   r#   s    r   r   zMaxentClassifier.weights„   s   € ð
 Œ}Ðr   c                 óP   — |                       |¦  «                             ¦   «         S r!   )Úprob_classifyÚmax)r   Ú
featuresets     r   ÚclassifyzMaxentClassifier.classify‹   s"   € Ø×!Ò! *Ñ-Ô-×1Ò1Ñ3Ô3Ð3r   c                 ó:  — i }| j                              ¦   «         D ]i}| j                              ||¦  «        }| j        r#d}|D ]\  }}|| j        |         |z  z  }Œ|||<   ŒGd}|D ]\  }}|| j        |         |z  z  }Œ|||<   Œjt          || j        d¬¦  «        S )Ng        ç      ð?T)ÚlogÚ	normalize)r   r"   Úencoder   r   r   )	r   r,   Ú	prob_dictÚlabelÚfeature_vectorÚtotalÚf_idÚf_valÚprods	            r   r*   zMaxentClassifier.prob_classifyŽ   sÜ   € Øˆ	Ø”^×*Ò*Ñ,Ô,ð 	(ð 	(ˆEØ!œ^×2Ò2°:¸uÑEÔEˆNàÔ ð 
(Ø�Ø%3ð 9ð 9‘M�T˜5Ø˜Tœ]¨4Ô0°5Ñ8Ñ8�E�EØ#(�	˜%Ñ Ð ð �Ø%3ð 9ð 9‘M�T˜5Ø˜DœM¨$Ô/°5Ñ8Ñ8�D�DØ#'�	˜%Ñ Ð õ " )°Ô1BÈdÐSÑSÔSÐSr   é   c           	      ó<  ‡ ‡‡— d}dt          |dz
  ¦  «        z   dz   }‰                      |¦  «        Št          ‰                     ¦   «         ‰j        d¬¦  «        }|d|…         }t          d                     |¦  «        d	                     d
„ |D ¦   «         ¦  «        z   ¦  «         t          dd|dz
  dt          |¦  «        z  z   z  z   ¦  «         t          t          ¦  «        Št          |¦  «        D ]ò\  }}‰ j                             ||¦  «        }|                     ˆ fd„d¬¦  «         |D ]µ\  }	}
‰ j        r‰ j        |	         |
z  }n‰ j        |	         |
z  }‰ j                             |	¦  «        }|                     d¦  «        d         }|d|
z  z  }t          |¦  «        dk    r|dd…         dz   }t          |||dz  dz  |fz  ¦  «         ‰|xx         |z  cc<   Œ¶Œót          dd|dz
  dt          |¦  «        z  z   z  z   ¦  «         t          d                     |¦  «        d	                     ˆfd„|D ¦   «         ¦  «        z   ¦  «         t          d                     |¦  «        d	                     ˆfd„|D ¦   «         ¦  «        z   ¦  «         dS )zË
        Print a table showing the effect of each of the features in
        the given feature set, and how they combine to determine the
        probabilities of each label for that featureset.
        é2   z  %-é   zs%s%8.3fT©ÚkeyÚreverseNz	  FeatureÚ c              3   ó6   K  — | ]}d d|z  dd…         z  V — ŒdS )z%8sú%sNé   © )Ú.0Úls     r   ú	<genexpr>z+MaxentClassifier.explain.<locals>.<genexpr>°   s3   è è € Ð?Ð?°1�e  q¡¨"¨1¨"œ~Ñ.Ð?Ð?Ð?Ð?Ð?Ð?r   z  Ú-é   c                 óD   •— t          ‰j        | d                  ¦  «        S )Nr   ©Úabsr   )Úfid__r   s    €r   ú<lambda>z*MaxentClassifier.explain.<locals>.<lambda>·   s   ø€ ¥# d¤m°E¸!´HÔ&=Ñ">Ô">€ r   ú and label is r   z (%s)é/   é,   z...Ú é   z  TOTAL:c              3   ó.   •K  — | ]}d ‰|         z  V — ŒdS ©z%8.3fNrE   )rF   rG   Úsumss     €r   rH   z+MaxentClassifier.explain.<locals>.<genexpr>Ç   s,   øè è € Ð3VÐ3VÈ!°G¸dÀ1¼gÑ4EÐ3VÐ3VÐ3VÐ3VÐ3VÐ3Vr   z  PROBS:c              3   óH   •K  — | ]}d ‰                      |¦  «        z  V — ŒdS rV   )Úprob)rF   rG   Úpdists     €r   rH   z+MaxentClassifier.explain.<locals>.<genexpr>Ë   s2   øè è € Ð>Ð>°!�g §
¢
¨1¡¤Ñ-Ð>Ð>Ð>Ð>Ð>Ð>r   )Ústrr*   ÚsortedÚsamplesrY   ÚprintÚljustÚjoinr   r   ÚintÚ	enumerater   r2   Úsortr   r   ÚdescribeÚsplit)r   r,   ÚcolumnsÚdescr_widthÚTEMPLATEr"   Úir4   r5   r7   r8   ÚscoreÚdescrrZ   rW   s   `            @@r   ÚexplainzMaxentClassifier.explain¢   sð  øøø€ ð ˆØ�C ¨a¡Ñ0Ô0Ñ0°:Ñ=ˆà×"Ò" :Ñ.Ô.ˆÝ˜Ÿš™œ¨U¬ZÀÐFÑFÔFˆØ˜˜˜Ô!ˆÝØ×Ò˜kÑ*Ô*Ø�gŠgÐ?Ð?¸Ð?Ñ?Ô?Ñ?Ô?ñ@ñ	
ô 	
ð 	
õ 	ˆd�S˜K¨!™O¨aµ#°f±+´+©oÑ=Ñ>Ñ>Ñ?Ô?Ð?Ý�3ÑÔˆÝ! &Ñ)Ô)ð 	%ð 	%‰HˆAˆuØ!œ^×2Ò2°:¸uÑEÔEˆNØ×ÒØ>Ð>Ð>Ð>Èð  ñ ô ð ð "0ð %ð %‘��uØÔ$ð 9Ø œM¨$Ô/°%Ñ7�E�Eà œM¨$Ô/°5Ñ8�EØœ×/Ò/°Ñ5Ô5�ØŸšÐ$4Ñ5Ô5°aÔ8�Ø˜ 5™Ñ(�Ý�u‘:”: ’?�?Ø! # 2 #œJ¨Ñ.�EÝ�h %¨¨Q©°©°eÐ!<Ñ<Ñ=Ô=Ð=Ø�U��”˜uÑ$��‘�ð%õ 	ˆd�S˜K¨!™O¨aµ#°f±+´+©oÑ=Ñ>Ñ>Ñ?Ô?Ð?ÝØ×Ò˜[Ñ)Ô)¨B¯GªGÐ3VÐ3VÐ3VÐ3VÈvÐ3VÑ3VÔ3VÑ,VÔ,VÑVñ	
ô 	
ð 	
õ 	Ø×Ò˜[Ñ)Ô)Ø�gŠgÐ>Ð>Ð>Ð>°vÐ>Ñ>Ô>Ñ>Ô>ñ?ñ	
ô 	
ð 	
ð 	
ð 	
r   é
   c           	      óì   ‡ — t          ‰ d¦  «        r‰ j        d|…         S t          t          t	          t          ‰ j        ¦  «        ¦  «        ¦  «        ˆ fd„d¬¦  «        ‰ _        ‰ j        d|…         S )zW
        Generates the ranked list of informative features from most to least.
        Ú_most_informative_featuresNc                 ó8   •— t          ‰j        |          ¦  «        S r!   rL   )Úfidr   s    €r   rO   z<MaxentClassifier.most_informative_features.<locals>.<lambda>×   s   ø€ ¥ D¤M°#Ô$6Ñ 7Ô 7€ r   Tr>   )Úhasattrro   r\   ÚlistÚranger   r   )r   Úns   ` r   Úmost_informative_featuresz*MaxentClassifier.most_informative_featuresÎ   s�   ø€ õ �4Ð5Ñ6Ô6ð 	7ØÔ2°2°A°2Ô6Ð6å.4Ý•U�3˜tœ}Ñ-Ô-Ñ.Ô.Ñ/Ô/Ø7Ð7Ð7Ð7Øð/ñ /ô /ˆDÔ+ð
 Ô2°2°A°2Ô6Ð6r   Úallc                 ó  ‡ — ‰                       d¦  «        }|dk    rˆ fd„|D ¦   «         }n|dk    rˆ fd„|D ¦   «         }|d|…         D ]:}t          ‰ j        |         d›d‰ j                             |¦  «        › �¦  «         Œ;dS )z«
        :param show: all, neg, or pos (for negative-only or positive-only)
        :type show: str
        :param n: The no. of top features
        :type n: int
        NÚposc                 ó6   •— g | ]}‰j         |         d k    ¯|‘ŒS ©r   r(   ©rF   rq   r   s     €r   ú
<listcomp>zCMaxentClassifier.show_most_informative_features.<locals>.<listcomp>æ   ó*   ø€ ÐBÐBÐB˜C¨4¬=¸Ô+=ÀÒ+AÐ+A�CÐ+AÐ+AÐ+Ar   Únegc                 ó6   •— g | ]}‰j         |         d k     ¯|‘ŒS r{   r(   r|   s     €r   r}   zCMaxentClassifier.show_most_informative_features.<locals>.<listcomp>è   r~   r   z8.3frS   )rv   r^   r   r   rd   )r   ru   ÚshowÚfidsrq   s   `    r   Úshow_most_informative_featuresz/MaxentClassifier.show_most_informative_featuresÜ   s¼   ø€ ð ×-Ò-¨dÑ3Ô3ˆØ�5Š=ˆ=ØBÐBÐBÐB 4ÐBÑBÔBˆDˆDØ�UŠ]ˆ]ØBÐBÐBÐB 4ÐBÑBÔBˆDØ˜˜˜”8ð 	Oð 	OˆCÝ�T”] 3Ô'ÐMÐMÐM¨t¬~×/FÒ/FÀsÑ/KÔ/KÐMÐMÑNÔNÐNÐNð	Oð 	Or   c                 ó†   — dt          | j                             ¦   «         ¦  «        | j                             ¦   «         fz  S )Nz:<ConditionalExponentialClassifier: %d labels, %d features>)r   r   r"   r   r#   s    r   Ú__repr__zMaxentClassifier.__repr__ì   s?   € ØKÝ�”×%Ò%Ñ'Ô'Ñ(Ô(ØŒN×!Ò!Ñ#Ô#ðO
ñ 
ð 	
r   )ÚGISÚIISÚMEGAMÚTADMNé   r   c                 ón  — |€d}|D ]}|dvrt          d|z  ¦  «        ‚Œ|                     ¦   «         }|dk    rt          ||||fi |¤ŽS |dk    rt          ||||fi |¤ŽS |dk    rt	          |||||fi |¤ŽS |dk    r(|}	||	d<   ||	d	<   ||	d
<   ||	d<   t          j        |fi |	¤ŽS t          d|z  ¦  «        ‚)a®	  
        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``.
        NÚiis)	Úmax_iterÚmin_llÚmin_lldeltaÚmax_accÚmin_accdeltaÚcount_cutoffÚnormÚexplicitÚ	bernoullizUnexpected keyword arg %rÚgisÚmegamÚtadmÚtracer   r"   Úgaussian_prior_sigmazUnknown algorithm %s)Ú	TypeErrorÚlowerÚ train_maxent_classifier_with_iisÚ train_maxent_classifier_with_gisÚ"train_maxent_classifier_with_megamÚTadmMaxentClassifierÚtrainÚ
ValueError)
ÚclsÚ
train_toksÚ	algorithmr™   r   r"   rš   Úcutoffsr?   Úkwargss
             r   r¡   zMaxentClassifier.trainö   sf  € ð| ÐØˆIØð 	Cð 	CˆCØð 
ð 
ð 
õ  Ð ;¸cÑ AÑBÔBÐBð
ð —O’OÑ%Ô%ˆ	Ø˜ÒÐÝ3Ø˜E 8¨Vðð Ø7>ðð ð ð ˜%ÒÐÝ3Ø˜E 8¨Vðð Ø7>ðð ð ð ˜'Ò!Ð!Ý5Ø˜E 8¨VÐ5Iðð ØMTðð ð ð ˜&Ò Ð ØˆFØ#ˆF�7‰OØ!)ˆF�:ÑØ%ˆF�8ÑØ-AˆFÐ)Ñ*Ý'Ô-¨jÐCÐC¸FÐCÐCÐCåÐ3°iÑ?Ñ@Ô@Ð@r   )T)r:   )rm   )rm   rw   )NrŠ   NNr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   r&   r   r-   r*   rl   rv   rƒ   r…   Ú
ALGORITHMSÚclassmethodr¡   rE   r   r   r   r   N   s  € € € € € ðð ð$1ð 1ð 1ð 1ð.'ð 'ð 'ð;ð ;ð ;ðð ð ð4ð 4ð 4ðTð Tð Tð(*
ð *
ð *
ð *
ðX7ð 7ð 7ð 7ðOð Oð Oð Oð 
ð 
ð 
ð 1Ð0Ð0€Jàð ØØØØðaAð aAð aAñ „[ðaAð aAð aAr   r   c                   ó0   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚMaxentFeatureEncodingIa´  
    A mapping that converts a set of input-feature values to a vector
    of joint-feature values, given a label.  This conversion is
    necessary to translate featuresets into a format that can be used
    by maximum entropy models.

    The set of joint-features used by a given encoding is fixed, and
    each index in the generated joint-feature vectors corresponds to a
    single joint-feature.  The length of the generated joint-feature
    vectors is therefore constant (for a given encoding).

    Because the joint-feature vectors generated by
    ``MaxentFeatureEncodingI`` are typically very sparse, they are
    represented as a list of ``(index, value)`` tuples, specifying the
    value of each non-zero joint-feature.

    Feature encodings are generally created using the ``train()``
    method, which generates an appropriate encoding based on the
    input-feature values and labels that are present in a given
    corpus.
    c                 ó   — t          ¦   «         ‚)aC  
        Given a (featureset, label) pair, return the corresponding
        vector of joint-feature values.  This vector is represented as
        a list of ``(index, value)`` tuples, specifying the value of
        each non-zero joint-feature.

        :type featureset: dict
        :rtype: list(tuple(int, int))
        ©ÚNotImplementedError©r   r,   r4   s      r   r2   zMaxentFeatureEncodingI.encode{  ó   € õ "Ñ#Ô#Ð#r   c                 ó   — t          ¦   «         ‚)z’
        :return: The size of the fixed-length joint-feature vectors
            that are generated by this encoding.
        :rtype: int
        r±   r#   s    r   r   zMaxentFeatureEncodingI.length‡  ó   € õ "Ñ#Ô#Ð#r   c                 ó   — t          ¦   «         ‚)zÞ
        :return: A list of the "known labels" -- i.e., all labels
            ``l`` such that ``self.encode(fs,l)`` can be a nonzero
            joint-feature vector for some value of ``fs``.
        :rtype: list
        r±   r#   s    r   r"   zMaxentFeatureEncodingI.labels�  s   € õ "Ñ#Ô#Ð#r   c                 ó   — t          ¦   «         ‚)z¦
        :return: A string describing the value of the joint-feature
            whose index in the generated feature vectors is ``fid``.
        :rtype: str
        r±   ©r   rq   s     r   rd   zMaxentFeatureEncodingI.describe˜  r¶   r   c                 ó   — t          ¦   «         ‚)ao  
        Construct and return new feature encoding, based on a given
        training corpus ``train_toks``.

        :type train_toks: list(tuple(dict, str))
        :param train_toks: Training data, represented as a list of
            pairs, the first member of which is a feature dictionary,
            and the second of which is a classification label.
        r±   )r£   r¤   s     r   r¡   zMaxentFeatureEncodingI.train   r´   r   N)	r¨   r©   rª   r«   r2   r   r"   rd   r¡   rE   r   r   r¯   r¯   d  si   € € € € € ðð ð,
$ð 
$ð 
$ð$ð $ð $ð$ð $ð $ð$ð $ð $ð
$ð 
$ð 
$ð 
$ð 
$r   r¯   c                   ó0   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ ZdS )Ú#FunctionBackedMaxentFeatureEncodingz‹
    A feature encoding that calls a user-supplied function to map a
    given featureset/label pair to a sparse joint-feature vector.
    c                 ó0   — || _         || _        || _        dS )ag  
        Construct a new feature encoding based on the given function.

        :type func: (callable)
        :param func: A function that takes two arguments, a featureset
             and a label, and returns the sparse joint feature vector
             that encodes them::

                 func(featureset, label) -> feature_vector

             This sparse joint feature vector (``feature_vector``) is a
             list of ``(index,value)`` tuples.

        :type length: int
        :param length: The size of the fixed-length joint-feature
            vectors that are generated by this encoding.

        :type labels: list
        :param labels: A list of the "known labels" for this
            encoding -- i.e., all labels ``l`` such that
            ``self.encode(fs,l)`` can be a nonzero joint-feature vector
            for some value of ``fs``.
        N)Ú_lengthÚ_funcÚ_labels)r   Úfuncr   r"   s       r   r   z,FunctionBackedMaxentFeatureEncoding.__init__³  s   € ð0 ˆŒØˆŒ
ØˆŒˆˆr   c                 ó.   — |                       ||¦  «        S r!   )r¿   r³   s      r   r2   z*FunctionBackedMaxentFeatureEncoding.encodeÏ  s   € Ø�zŠz˜* eÑ,Ô,Ð,r   c                 ó   — | j         S r!   ©r¾   r#   s    r   r   z*FunctionBackedMaxentFeatureEncoding.lengthÒ  ó
   € ØŒ|Ðr   c                 ó   — | j         S r!   ©rÀ   r#   s    r   r"   z*FunctionBackedMaxentFeatureEncoding.labelsÕ  rÅ   r   c                 ó   — dS )Nzno description availablerE   r¹   s     r   rd   z,FunctionBackedMaxentFeatureEncoding.describeØ  s   € Ø)Ð)r   N)	r¨   r©   rª   r«   r   r2   r   r"   rd   rE   r   r   r¼   r¼   ­  si   € € € € € ðð ð
ð ð ð8-ð -ð -ðð ð ðð ð ð*ð *ð *ð *ð *r   r¼   c                   óJ   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Ze	dd
„¦   «         Z
d	S )ÚBinaryMaxentFeatureEncodingaø  
    A feature encoding that generates vectors containing a binary
    joint-features of the form:

    |  joint_feat(fs, l) = { 1 if (fs[fname] == fval) and (l == label)
    |                      {
    |                      { 0 otherwise

    Where ``fname`` is the name of an input-feature, ``fval`` is a value
    for that input-feature, and ``label`` is a label.

    Typically, these features are constructed based on a training
    corpus, using the ``train()`` method.  This method will create one
    feature for each combination of ``fname``, ``fval``, and ``label``
    that occurs at least once in the training corpus.

    The ``unseen_features`` parameter can be used to add "unseen-value
    features", which are used whenever an input feature has a value
    that was not encountered in the training corpus.  These features
    have the form:

    |  joint_feat(fs, l) = { 1 if is_unseen(fname, fs[fname])
    |                      {      and l == label
    |                      {
    |                      { 0 otherwise

    Where ``is_unseen(fname, fval)`` is true if the encoding does not
    contain any joint features that are true when ``fs[fname]==fval``.

    The ``alwayson_features`` parameter can be used to add "always-on
    features", which have the form::

    |  joint_feat(fs, l) = { 1 if (l == label)
    |                      {
    |                      { 0 otherwise

    These always-on features allow the maxent model to directly model
    the prior probabilities of each label.
    Fc                 ód  ‡ — t          |                     ¦   «         ¦  «        t          t          t          |¦  «        ¦  «        ¦  «        k    rt	          d¦  «        ‚t          |¦  «        ‰ _        	 |‰ _        	 t          |¦  «        ‰ _        	 d‰ _	        	 d‰ _
        	 |rBˆ fd„t          |¦  «        D ¦   «         ‰ _	        ‰ xj        t          ‰ j	        ¦  «        z  c_        |rKd„ |D ¦   «         }ˆ fd„t          |¦  «        D ¦   «         ‰ _
        ‰ xj        t          |¦  «        z  c_        dS dS )a»  
        :param labels: A list of the "known labels" for this encoding.

        :param mapping: A dictionary mapping from ``(fname,fval,label)``
            tuples to corresponding joint-feature indexes.  These
            indexes must be the set of integers from 0...len(mapping).
            If ``mapping[fname,fval,label]=id``, then
            ``self.encode(..., fname:fval, ..., label)[id]`` is 1;
            otherwise, it is 0.

        :param unseen_features: If true, then include unseen value
           features in the generated joint-feature vectors.

        :param alwayson_features: If true, then include always-on
           features in the generated joint-feature vectors.
        úHMapping values must be exactly the set of integers from 0...len(mapping)Nc                 ó,   •— i | ]\  }}||‰j         z   “ŒS rE   rÄ   ©rF   ri   r4   r   s      €r   ú
<dictcomp>z8BinaryMaxentFeatureEncoding.__init__.<locals>.<dictcomp>,  ó3   ø€ ð ð ð Ù,6¨Q°��q˜4œ<Ñ'ðð ð r   c                 ó   — h | ]\  }}}|’Œ	S rE   rE   ©rF   ÚfnameÚfvalr4   s       r   ú	<setcomp>z7BinaryMaxentFeatureEncoding.__init__.<locals>.<setcomp>2  ó   € Ð@Ð@Ð@Ñ 4 ¨¨e�eÐ@Ð@Ð@r   c                 ó,   •— i | ]\  }}||‰j         z   “ŒS rE   rÄ   ©rF   ri   rÓ   r   s      €r   rÏ   z8BinaryMaxentFeatureEncoding.__init__.<locals>.<dictcomp>3  ó&   ø€ ÐXÐXÐX¹
¸¸E˜E 1 t¤|Ñ#3ÐXÐXÐXr   ©ÚsetÚvaluesrt   r   r¢   rs   rÀ   Ú_mappingr¾   Ú	_alwaysonÚ_unseenrb   ©r   r"   ÚmappingÚunseen_featuresÚalwayson_featuresÚfnamess   `     r   r   z$BinaryMaxentFeatureEncoding.__init__  óH  ø€ õ" ˆw�~Š~ÑÔÑ Ô ¥C­­c°'©l¬lÑ(;Ô(;Ñ$<Ô$<Ò<Ð<Ýð8ñô ð õ
 ˜F‘|”|ˆŒØ(àˆŒØ9å˜7‘|”|ˆŒØ<àˆŒØ,àˆŒØ,àð 	0ðð ð ð Ý:CÀFÑ:KÔ:Kðñ ô ˆDŒNð ˆLŒL�C ¤Ñ/Ô/Ñ/ˆLŒLàð 	(Ø@Ð@¸Ð@Ñ@Ô@ˆFØXÐXÐXÐXÅiÐPVÑFWÔFWÐXÑXÔXˆDŒLØˆLŒL�C ™KœKÑ'ˆLŒLˆLˆLð	(ð 	(r   c                 óš  — g }|                      ¦   «         D ]�\  }}|||f| j        v r&|                     | j        |||f         df¦  «         Œ7| j        rC| j        D ]}|||f| j        v r n,Œ|| j        v r"|                     | j        |         df¦  «         Œ‚| j        r+|| j        v r"|                     | j        |         df¦  «         |S ©NrT   )ÚitemsrÝ   Úappendrß   rÀ   rÞ   ©r   r,   r4   r   rÓ   rÔ   Úlabel2s          r   r2   z"BinaryMaxentFeatureEncoding.encode6  s  € àˆð &×+Ò+Ñ-Ô-ð 	Bð 	B‰KˆE�4à�t˜UÐ# t¤}Ð4Ð4Ø—’ ¤¨u°d¸EÐ/AÔ!BÀAÐ FÑGÔGÐGÐGð ”ð Bà"œlð Bð B�FØ˜t VÐ,°´Ð=Ð=Ø˜ð >ð  ¤Ð,Ð,Ø Ÿš¨¬°eÔ)<¸aÐ(@ÑAÔAÐAøð Œ>ð 	8˜e t¤~Ð5Ð5Ø�OŠO˜Tœ^¨EÔ2°AÐ6Ñ7Ô7Ð7àˆr   c                 óÌ  — t          |t          ¦  «        st          d¦  «        ‚	 | j         nV# t          $ rI dgt          | j        ¦  «        z  | _        | j                             ¦   «         D ]\  }}|| j        |<   ŒY nw xY w|t          | j        ¦  «        k     r| j        |         \  }}}|› d|›d|›�S | j        rI|| j         	                    ¦   «         v r.| j                             ¦   «         D ]\  }}||k    rd|z  c S Œd S | j
        rI|| j
         	                    ¦   «         v r.| j
                             ¦   «         D ]\  }}||k    rd|z  c S Œd S t          d¦  «        ‚©Nzdescribe() expected an intéÿÿÿÿz==rP   zlabel is %rz%s is unseenzBad feature id©Ú
isinstancera   r›   Ú_inv_mappingÚAttributeErrorr   rÝ   rè   rÞ   rÜ   rß   r¢   ©r   r7   Úinfori   rÓ   rÔ   r4   Úf_id2s           r   rd   z$BinaryMaxentFeatureEncoding.describeQ  óÕ  € å˜$¥Ñ$Ô$ð 	:ÝÐ8Ñ9Ô9Ð9ð	,ØÔÐÐøÝð 	,ð 	,ð 	,Ø!# ¥s¨4¬=Ñ'9Ô'9Ñ 9ˆDÔØ!œ]×0Ò0Ñ2Ô2ð ,ð ,‘	��qØ'+�Ô! !Ñ$Ð$ð,ð ,ð	,øøøð
 •#�d”mÑ$Ô$Ò$Ð$Ø#'Ô#4°TÔ#:Ñ ˆU�D˜%ØÐ>Ð>˜tÐ>Ð>°UÐ>Ð>Ð>ØŒ^ð 		/ ¨¬×(=Ò(=Ñ(?Ô(?Ð ?Ð ?Ø"&¤.×"6Ò"6Ñ"8Ô"8ð 1ð 1‘�˜Ø˜5’=�=Ø(¨5Ñ0Ð0Ð0Ð0ð !ð1ð 1ð Œ\ð 	/˜d d¤l×&9Ò&9Ñ&;Ô&;Ð;Ð;Ø"&¤,×"4Ò"4Ñ"6Ô"6ð 2ð 2‘�˜Ø˜5’=�=Ø)¨EÑ1Ð1Ð1Ð1ð !ð2ð 2õ Ð-Ñ.Ô.Ð.ó   ¦. ®ABÂ Bc                 ó   — | j         S r!   rÇ   r#   s    r   r"   z"BinaryMaxentFeatureEncoding.labelsj  ó
   € àŒ|Ðr   c                 ó   — | j         S r!   rÄ   r#   s    r   r   z"BinaryMaxentFeatureEncoding.lengthn  rù   r   r   Nc                 ó|  — i }t          ¦   «         }t          t          ¦  «        }|D ]ˆ\  }}	|r|	|vrt          d|	z  ¦  «        ‚|                     |	¦  «         |                     ¦   «         D ]A\  }
}||
|fxx         dz  cc<   ||
|f         |k    r|
||	f|vrt          |¦  «        ||
||	f<   ŒBŒ‰|€|} | ||fi |¤ŽS )aª  
        Construct and return new feature encoding, based on a given
        training corpus ``train_toks``.  See the class description
        ``BinaryMaxentFeatureEncoding`` for a description of the
        joint-features that will be included in this encoding.

        :type train_toks: list(tuple(dict, str))
        :param train_toks: Training data, represented as a list of
            pairs, the first member of which is a feature dictionary,
            and the second of which is a classification label.

        :type count_cutoff: int
        :param count_cutoff: A cutoff value that is used to discard
            rare joint-features.  If a joint-feature's value is 1
            fewer than ``count_cutoff`` times in the training corpus,
            then that joint-feature is not included in the generated
            encoding.

        :type labels: list
        :param labels: A list of labels that should be used by the
            classifier.  If not specified, then the set of labels
            attested in ``train_toks`` will be used.

        :param options: Extra parameters for the constructor, such as
            ``unseen_features`` and ``alwayson_features``.
        úUnexpected label %srT   )rÛ   r   ra   r¢   Úaddrè   r   ©r£   r¤   r’   r"   Úoptionsrá   Úseen_labelsÚcountÚtokr4   rÓ   rÔ   s               r   r¡   z!BinaryMaxentFeatureEncoding.trainr  s  € ð8 ˆÝ‘e”eˆÝ�CÑ Ô ˆà&ð 	Cð 	C‰LˆS�%Øð @˜% vÐ-Ð-Ý Ð!6¸Ñ!>Ñ?Ô?Ð?Ø�OŠO˜EÑ"Ô"Ð"ð "%§¢¡¤ð Cð C‘�˜ð
 �e˜T�kÐ"Ð"Ô" aÑ'Ð"Ð"Ñ"Ø˜ ˜Ô%¨Ò5Ð5Ø˜t UÐ+°7Ð:Ð:Ý69¸'±l´l˜  t¨UÐ 2Ñ3øðCð ˆ>Ø ˆFØˆs�6˜7Ð.Ð. gÐ.Ð.Ð.r   ©FF©r   N©r¨   r©   rª   r«   r   r2   rd   r"   r   r­   r¡   rE   r   r   rÊ   rÊ   Ü  s�   € € € € € ð&ð &ðP/(ð /(ð /(ð /(ðbð ð ð6/ð /ð /ð2ð ð ðð ð ð ð1/ð 1/ð 1/ñ „[ð1/ð 1/ð 1/r   rÊ   c                   óD   — e Zd ZdZ	 d	d„Zed„ ¦   «         Zd„ Zd„ Zd„ Z	dS )
ÚGISEncodinga  
    A binary feature encoding which adds one new joint-feature to the
    joint-features defined by ``BinaryMaxentFeatureEncoding``: a
    correction feature, whose value is chosen to ensure that the
    sparse vector always sums to a constant non-negative number.  This
    new feature is used to ensure two preconditions for the GIS
    training algorithm:

      - At least one feature vector index must be nonzero for every
        token.
      - The feature vector must sum to a constant non-negative number
        for every token.
    FNc                 óŒ   — t                                | ||||¦  «         |€t          d„ |D ¦   «         ¦  «        dz   }|| _        dS )a	  
        :param C: The correction constant.  The value of the correction
            feature is based on this value.  In particular, its value is
            ``C - sum([v for (f,v) in encoding])``.
        :seealso: ``BinaryMaxentFeatureEncoding.__init__``
        Nc                 ó   — h | ]\  }}}|’Œ	S rE   rE   rÒ   s       r   rÕ   z'GISEncoding.__init__.<locals>.<setcomp>Ã  s   € Ð?Ð?Ð?Ñ3  t¨U�UÐ?Ð?Ð?r   rT   )rÊ   r   r   Ú_C)r   r"   rá   râ   rã   ÚCs         r   r   zGISEncoding.__init__¶  s[   € õ 	$×,Ò,Ø�&˜' ?Ð4Eñ	
ô 	
ð 	
ð ˆ9ÝÐ?Ð?°wÐ?Ñ?Ô?Ñ@Ô@À1ÑDˆAØˆŒˆˆr   c                 ó   — | j         S )zOThe non-negative constant that all encoded feature vectors
        will sum to.)r
  r#   s    r   r  zGISEncoding.CÆ  s   € ð Œwˆr   c                 ó  — t                                | ||¦  «        }t                                | ¦  «        }t          d„ |D ¦   «         ¦  «        }|| j        k    rt          d¦  «        ‚|                     || j        |z
  f¦  «         |S )Nc              3   ó    K  — | ]	\  }}|V — Œ
d S r!   rE   )rF   ÚfÚvs      r   rH   z%GISEncoding.encode.<locals>.<genexpr>Ò  s&   è è € Ð-Ð-™&˜1˜a�AÐ-Ð-Ð-Ð-Ð-Ð-r   z&Correction feature is not high enough!)rÊ   r2   r   Úsumr
  r¢   ré   )r   r,   r4   r   Úbase_lengthr6   s         r   r2   zGISEncoding.encodeÌ  sŠ   € å.×5Ò5°d¸JÈÑNÔNˆÝ1×8Ò8¸Ñ>Ô>ˆõ Ð-Ð- HÐ-Ñ-Ô-Ñ-Ô-ˆØ�D”GÒÐÝÐEÑFÔFÐFØ�Š˜ d¤g°¡oÐ6Ñ7Ô7Ð7ð ˆr   c                 ó<   — t                                | ¦  «        dz   S rç   )rÊ   r   r#   s    r   r   zGISEncoding.lengthÚ  s   € Ý*×1Ò1°$Ñ7Ô7¸!Ñ;Ð;r   c                 óˆ   — |t                                | ¦  «        k    r
d| j        z  S t                                | |¦  «        S )NzCorrection feature (%s))rÊ   r   r
  rd   )r   r7   s     r   rd   zGISEncoding.describeÝ  s?   € ØÕ.×5Ò5°dÑ;Ô;Ò;Ð;Ø,¨t¬wÑ6Ð6å.×7Ò7¸¸dÑCÔCÐCr   )FFN)
r¨   r©   rª   r«   r   Úpropertyr  r2   r   rd   rE   r   r   r  r  §  s†   € € € € € ðð ð RVðð ð ð ð  ðð ñ „Xðð
ð ð ð<ð <ð <ðDð Dð Dð Dð Dr   r  c                   óF   — e Zd Zd
d„Zd„ Zd„ Zd„ Zd„ Zedd	„¦   «         Z	dS )ÚTadmEventMaxentFeatureEncodingFc                 óš   — t          |¦  «        | _        t          ¦   «         | _        t                               | || j        ||¦  «         d S r!   )r   rÝ   Ú_label_mappingrÊ   r   )r   r"   rá   râ   rã   s        r   r   z'TadmEventMaxentFeatureEncoding.__init__å  sM   € Ý# GÑ,Ô,ˆŒÝ)™mœmˆÔÝ#×,Ò,Ø�&˜$œ-¨Ð:Kñ	
ô 	
ð 	
ð 	
ð 	
r   c                 óx  — g }|                      ¦   «         D ]¢\  }}||f| j        vrt          | j        ¦  «        | j        ||f<   || j        vr<t	          |t
          ¦  «        st          | j        ¦  «        | j        |<   n
|| j        |<   |                     | j        ||f         | j        |         f¦  «         Œ£|S r!   )rè   rÝ   r   r  rð   ra   ré   )r   r,   r4   r   ÚfeatureÚvalues         r   r2   z%TadmEventMaxentFeatureEncoding.encodeì  sÙ   € ØˆØ(×.Ò.Ñ0Ô0ð 
	ð 
	‰NˆG�UØ˜Ð t¤}Ð4Ð4Ý25°d´mÑ2DÔ2D�”˜w¨Ð.Ñ/Ø˜DÔ/Ð/Ð/Ý! %­Ñ-Ô-ð 7Ý14°TÔ5HÑ1IÔ1I�DÔ'¨Ñ.Ð.à16�DÔ'¨Ñ.Ø�OŠOØ” ¨Ð/Ô0°$Ô2EÀeÔ2LÐMñô ð ð ð ˆr   c                 ó   — | j         S r!   rÇ   r#   s    r   r"   z%TadmEventMaxentFeatureEncoding.labelsû  rÅ   r   c                 óR   — | j         D ]\  }}| j         ||f         |k    r||fc S Œd S r!   )rÝ   )r   rq   r  r4   s       r   rd   z'TadmEventMaxentFeatureEncoding.describeþ  sO   € Ø $¤ð 	(ð 	(ÑˆW�eØŒ}˜g uÐ-Ô.°#Ò5Ð5Ø Ð'Ð'Ð'Ð'ð 6ð	(ð 	(r   c                 ó*   — t          | j        ¦  «        S r!   )r   rÝ   r#   s    r   r   z%TadmEventMaxentFeatureEncoding.length  s   € Ý�4”=Ñ!Ô!Ð!r   r   Nc                 óò   — t          ¦   «         }|sg }t          |¦  «        }|D ]\  }}||vr|                     |¦  «         Œ|D ])\  }}|D ]!}|D ]}||f|vrt          |¦  «        |||f<   ŒŒ"Œ* | ||fi |¤ŽS r!   )r   rs   ré   r   )	r£   r¤   r’   r"   rÿ   rá   r,   r4   r  s	            r   r¡   z$TadmEventMaxentFeatureEncoding.train  sß   € å‘-”-ˆØð 	ØˆFõ ˜*Ñ%Ô%ˆ
à#-ð 	%ð 	%ÑˆZ˜Ø˜FÐ"Ð"Ø—’˜eÑ$Ô$Ð$øà#-ð 	Að 	AÑˆZ˜Øð Að A�Ø)ð Að A�GØ Ð'¨wÐ6Ð6Ý47¸±L´L˜ ¨%Ð 0Ñ1øðAðAð
 ˆs�6˜7Ð.Ð. gÐ.Ð.Ð.r   r  r  )
r¨   r©   rª   r   r2   r"   rd   r   r­   r¡   rE   r   r   r  r  ä  s„   € € € € € ð
ð 
ð 
ð 
ðð ð ðð ð ð(ð (ð (ð
"ð "ð "ð ð/ð /ð /ñ „[ð/ð /ð /r   r  c                   óJ   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Ze	dd
„¦   «         Z
d	S )ÚTypedMaxentFeatureEncodingaZ  
    A feature encoding that generates vectors containing integer,
    float and binary joint-features of the form:

    Binary (for string and boolean features):

    |  joint_feat(fs, l) = { 1 if (fs[fname] == fval) and (l == label)
    |                      {
    |                      { 0 otherwise

    Value (for integer and float features):

    |  joint_feat(fs, l) = { fval if     (fs[fname] == type(fval))
    |                      {         and (l == label)
    |                      {
    |                      { not encoded otherwise

    Where ``fname`` is the name of an input-feature, ``fval`` is a value
    for that input-feature, and ``label`` is a label.

    Typically, these features are constructed based on a training
    corpus, using the ``train()`` method.

    For string and boolean features [type(fval) not in (int, float)]
    this method will create one feature for each combination of
    ``fname``, ``fval``, and ``label`` that occurs at least once in the
    training corpus.

    For integer and float features [type(fval) in (int, float)] this
    method will create one feature for each combination of ``fname``
    and ``label`` that occurs at least once in the training corpus.

    For binary features the ``unseen_features`` parameter can be used
    to add "unseen-value features", which are used whenever an input
    feature has a value that was not encountered in the training
    corpus.  These features have the form:

    |  joint_feat(fs, l) = { 1 if is_unseen(fname, fs[fname])
    |                      {      and l == label
    |                      {
    |                      { 0 otherwise

    Where ``is_unseen(fname, fval)`` is true if the encoding does not
    contain any joint features that are true when ``fs[fname]==fval``.

    The ``alwayson_features`` parameter can be used to add "always-on
    features", which have the form:

    |  joint_feat(fs, l) = { 1 if (l == label)
    |                      {
    |                      { 0 otherwise

    These always-on features allow the maxent model to directly model
    the prior probabilities of each label.
    Fc                 ód  ‡ — t          |                     ¦   «         ¦  «        t          t          t          |¦  «        ¦  «        ¦  «        k    rt	          d¦  «        ‚t          |¦  «        ‰ _        	 |‰ _        	 t          |¦  «        ‰ _        	 d‰ _	        	 d‰ _
        	 |rBˆ fd„t          |¦  «        D ¦   «         ‰ _	        ‰ xj        t          ‰ j	        ¦  «        z  c_        |rKd„ |D ¦   «         }ˆ fd„t          |¦  «        D ¦   «         ‰ _
        ‰ xj        t          |¦  «        z  c_        dS dS )a½  
        :param labels: A list of the "known labels" for this encoding.

        :param mapping: A dictionary mapping from ``(fname,fval,label)``
            tuples to corresponding joint-feature indexes.  These
            indexes must be the set of integers from 0...len(mapping).
            If ``mapping[fname,fval,label]=id``, then
            ``self.encode({..., fname:fval, ...``, label)[id]} is 1;
            otherwise, it is 0.

        :param unseen_features: If true, then include unseen value
           features in the generated joint-feature vectors.

        :param alwayson_features: If true, then include always-on
           features in the generated joint-feature vectors.
        rÌ   Nc                 ó,   •— i | ]\  }}||‰j         z   “ŒS rE   rÄ   rÎ   s      €r   rÏ   z7TypedMaxentFeatureEncoding.__init__.<locals>.<dictcomp>|  rÐ   r   c                 ó   — h | ]\  }}}|’Œ	S rE   rE   rÒ   s       r   rÕ   z6TypedMaxentFeatureEncoding.__init__.<locals>.<setcomp>‚  rÖ   r   c                 ó,   •— i | ]\  }}||‰j         z   “ŒS rE   rÄ   rØ   s      €r   rÏ   z7TypedMaxentFeatureEncoding.__init__.<locals>.<dictcomp>ƒ  rÙ   r   rÚ   rà   s   `     r   r   z#TypedMaxentFeatureEncoding.__init__U  rå   r   c                 ój  — g }|                      ¦   «         D ]é\  }}t          |t          t          f¦  «        rL|t	          |¦  «        |f| j        v r2|                     | j        |t	          |¦  «        |f         |f¦  «         Œm|||f| j        v r&|                     | j        |||f         df¦  «         ŒŸ| j        rC| j        D ]}|||f| j        v r n,Œ|| j        v r"|                     | j        |         df¦  «         Œê| j	        r+|| j	        v r"|                     | j	        |         df¦  «         |S rç   )
rè   rð   ra   ÚfloatÚtyperÝ   ré   rß   rÀ   rÞ   rê   s          r   r2   z!TypedMaxentFeatureEncoding.encode†  sm  € àˆð &×+Ò+Ñ-Ô-ð 	Fð 	F‰KˆE�4Ý˜$¥¥e Ñ-Ô-ð Fà�4 ™:œ: uÐ-°´Ð>Ð>Ø—O’O T¤]°5½$¸t¹*¼*ÀeÐ3KÔ%LÈdÐ$SÑTÔTÐTøð ˜4 Ð'¨4¬=Ð8Ð8Ø—O’O T¤]°5¸$ÀÐ3EÔ%FÈÐ$JÑKÔKÐKÐKð ”\ð Fà"&¤,ð Fð F˜Ø! 4¨Ð0°D´MÐAÐAØ!˜Eð Bð ! D¤LÐ0Ð0Ø$ŸOšO¨T¬\¸%Ô-@À!Ð,DÑEÔEÐEøð Œ>ð 	8˜e t¤~Ð5Ð5Ø�OŠO˜Tœ^¨EÔ2°AÐ6Ñ7Ô7Ð7àˆr   c                 óÌ  — t          |t          ¦  «        st          d¦  «        ‚	 | j         nV# t          $ rI dgt          | j        ¦  «        z  | _        | j                             ¦   «         D ]\  }}|| j        |<   ŒY nw xY w|t          | j        ¦  «        k     r| j        |         \  }}}|› d|›d|›�S | j        rI|| j         	                    ¦   «         v r.| j                             ¦   «         D ]\  }}||k    rd|z  c S Œd S | j
        rI|| j
         	                    ¦   «         v r.| j
                             ¦   «         D ]\  }}||k    rd|z  c S Œd S t          d¦  «        ‚rí   rï   ró   s           r   rd   z#TypedMaxentFeatureEncoding.describe¦  rö   r÷   c                 ó   — | j         S r!   rÇ   r#   s    r   r"   z!TypedMaxentFeatureEncoding.labels¿  rù   r   c                 ó   — | j         S r!   rÄ   r#   s    r   r   z!TypedMaxentFeatureEncoding.lengthÃ  rù   r   r   Nc                 óÔ  — i }t          ¦   «         }t          t          ¦  «        }|D ]´\  }}	|r|	|vrt          d|	z  ¦  «        ‚|                     |	¦  «         |                     ¦   «         D ]m\  }
}t          |¦  «        t          t          fv rt          |¦  «        }||
|fxx         dz  cc<   ||
|f         |k    r|
||	f|vrt          |¦  «        ||
||	f<   ŒnŒµ|€|} | ||fi |¤ŽS )a)  
        Construct and return new feature encoding, based on a given
        training corpus ``train_toks``.  See the class description
        ``TypedMaxentFeatureEncoding`` for a description of the
        joint-features that will be included in this encoding.

        Note: recognized feature values types are (int, float), over
        types are interpreted as regular binary features.

        :type train_toks: list(tuple(dict, str))
        :param train_toks: Training data, represented as a list of
            pairs, the first member of which is a feature dictionary,
            and the second of which is a classification label.

        :type count_cutoff: int
        :param count_cutoff: A cutoff value that is used to discard
            rare joint-features.  If a joint-feature's value is 1
            fewer than ``count_cutoff`` times in the training corpus,
            then that joint-feature is not included in the generated
            encoding.

        :type labels: list
        :param labels: A list of labels that should be used by the
            classifier.  If not specified, then the set of labels
            attested in ``train_toks`` will be used.

        :param options: Extra parameters for the constructor, such as
            ``unseen_features`` and ``alwayson_features``.
        rü   rT   )	rÛ   r   ra   r¢   rý   rè   r)  r(  r   rþ   s               r   r¡   z TypedMaxentFeatureEncoding.trainÇ  s8  € ð> ˆÝ‘e”eˆÝ�CÑ Ô ˆà&ð 	Cð 	C‰LˆS�%Øð @˜% vÐ-Ð-Ý Ð!6¸Ñ!>Ñ?Ô?Ð?Ø�OŠO˜EÑ"Ô"Ð"ð "%§¢¡¤ð 	Cð 	C‘�˜Ý˜‘:”:¥#¥u Ð-Ð-Ý ™:œ:�Dð �e˜T�kÐ"Ð"Ô" aÑ'Ð"Ð"Ñ"Ø˜ ˜Ô%¨Ò5Ð5Ø˜t UÐ+°7Ð:Ð:Ý69¸'±l´l˜  t¨UÐ 2Ñ3øð	Cð ˆ>Ø ˆFØˆs�6˜7Ð.Ð. gÐ.Ð.Ð.r   r  r  r  rE   r   r   r"  r"    s‘   € € € € € ð6ð 6ðp/(ð /(ð /(ð /(ðbð ð ð@/ð /ð /ð2ð ð ðð ð ð ð5/ð 5/ð 5/ñ „[ð5/ð 5/ð 5/r   r"  rŠ   c                 ó  — |                      dd¦  «         t          |¦  «        }|€t                               | |¬¦  «        }t	          |d¦  «        st          d¦  «        ‚d|j        z  }t          | |¦  «        }t          t          j
        |dk    ¦  «        d         ¦  «        }t          j        t          |¦  «        d	¦  «        }	|D ]}
t          j        |	|
<   Œt          ||	¦  «        }t          j        |¦  «        }~|dk    rt!          d
|d         z  ¦  «         |dk    r,t!          ¦   «          t!          d¦  «         t!          d¦  «         	 	 |dk    rJ|j        pt%          || ¦  «        }|j        pt)          || ¦  «        }|j        }t!          d|||fz  ¦  «         t-          || |¦  «        }|D ]}
||
xx         dz  cc<   Œt          j        |¦  «        }~|                     ¦   «         }	|	||z
  |z  z  }	|                     |	¦  «         |                     || ¦  «        rnŒ×n # t4          $ r t!          d¦  «         Y n ‚ xY w|dk    r7t%          || ¦  «        }t)          || ¦  «        }t!          d|d›d|d›�¦  «         |S )a†  
    Train a new ``ConditionalExponentialClassifier``, using the given
    training samples, using the Generalized Iterative Scaling
    algorithm.  This ``ConditionalExponentialClassifier`` will encode
    the model that maximizes entropy from all the models that are
    empirically consistent with ``train_toks``.

    :see: ``train_maxent_classifier()`` for parameter descriptions.
    r�   éd   N©r"   r  zJThe GIS algorithm requires an encoding that defines C (e.g., GISEncoding).r/   r   Údú  ==> Training (%d iterations)r=   ú-      Iteration    Log Likelihood    Accuracyú-      ---------------------------------------Tú     %9d    %14.5f    %9.3frT   ú*      Training stopped: keyboard interruptú         Final    ú14.5fú    ú9.3f)Ú
setdefaultr   r  r¡   rr   r›   r  Úcalculate_empirical_fcountrÛ   ÚnumpyÚnonzeroÚzerosr   ÚNINFÚ ConditionalExponentialClassifierÚlog2r^   Úllr   Úaccr   ÚiterÚcalculate_estimated_fcountr   r&   ÚcheckÚKeyboardInterrupt)r¤   r™   r   r"   r¦   ÚcutoffcheckerÚCinvÚempirical_fcountÚ
unattestedr   rq   Ú
classifierÚlog_empirical_fcountrC  rD  ÚiternumÚestimated_fcountÚlog_estimated_fcounts                     r   rž   rž     s  € ð ×Ò�z 3Ñ'Ô'Ð'Ý! 'Ñ*Ô*€Mð ÐÝ×$Ò$ Z¸Ð$Ñ?Ô?ˆå�8˜SÑ!Ô!ð 
Ýð-ñ
ô 
ð 	
ð �”Ñ€Dõ 2°*¸hÑGÔGÐõ •U”]Ð#3°qÒ#8Ñ9Ô9¸!Ô<Ñ=Ô=€Jõ Œk�#Ð.Ñ/Ô/°Ñ5Ô5€GØð "ð "ˆÝ”zˆ�‰ˆÝ1°(¸GÑDÔD€Jõ !œ:Ð&6Ñ7Ô7ÐØàˆq‚y€yÝÐ.°¸Ô1DÑDÑEÔEÐEØˆq‚y€yÝ‰ŒˆÝÐ=Ñ>Ô>Ð>ÝÐ=Ñ>Ô>Ð>ð ð	Ø�qŠyˆyØ"Ô%ÐO­¸
ÀJÑ)OÔ)O�Ø#Ô'ÐK­8°JÀ
Ñ+KÔ+K�Ø'Ô,�ÝÐ3°wÀÀCÐ6HÑHÑIÔIÐIõ  :Ø˜J¨ñ ô  Ðð
 "ð +ð +�Ø  Ð%Ð%Ô%¨Ñ*Ð%Ð%Ñ%Ð%Ý#(¤:Ð.>Ñ#?Ô#?Ð Ø ð !×(Ò(Ñ*Ô*ˆGØÐ,Ð/CÑCÀtÑKÑKˆGØ×"Ò" 7Ñ+Ô+Ð+ð ×"Ò" :¨zÑ:Ô:ð Øð5	ð4 øåð <ð <ð <ÝÐ:Ñ;Ô;Ð;Ð;Ð;ðØøøøàˆq‚y€yÝ˜J¨
Ñ3Ô3ˆÝ�z :Ñ.Ô.ˆÝÐ; 2Ð;Ð;Ð;°Ð;Ð;Ð;Ñ<Ô<Ð<ð Ðs   ÅCH- È-I
ÉI
c                 ó¼   — t          j        |                     ¦   «         d¦  «        }| D ]1\  }}|                     ||¦  «        D ]\  }}||xx         |z  cc<   ŒŒ2|S ©Nr1  )r=  r?  r   r2   )r¤   r   Úfcountr  r4   ÚindexÚvals          r   r<  r<  g  su   € ÝŒ[˜ŸšÑ*Ô*¨CÑ0Ô0€Fà ð !ð !‰
ˆˆUØ$ŸOšO¨C°Ñ7Ô7ð 	!ð 	!‰LˆU�CØ�5ˆMˆMŒM˜SÑ ˆMˆM‰MˆMð	!ð €Mr   c                 óD  — t          j        |                     ¦   «         d¦  «        }|D ]u\  }}|                      |¦  «        }|                     ¦   «         D ]F}|                     |¦  «        }|                     ||¦  «        D ]\  }}	||xx         ||	z  z  cc<   ŒŒGŒv|S rS  )r=  r?  r   r*   r]   rY   r2   )
rM  r¤   r   rT  r  r4   rZ   rY   rq   rÔ   s
             r   rF  rF  q  s¹   € ÝŒ[˜ŸšÑ*Ô*¨CÑ0Ô0€Fà ð +ð +‰
ˆˆUØ×(Ò(¨Ñ-Ô-ˆØ—]’]‘_”_ð 	+ð 	+ˆEØ—:’:˜eÑ$Ô$ˆDØ'Ÿš¨s°EÑ:Ô:ð +ð +‘��dØ�s��”˜t d™{Ñ*��‘�ð+ð	+ð
 €Mr   c           
      ó   — |                      dd¦  «         t          |¦  «        }|€t                               | |¬¦  «        }t	          | |¦  «        t          | ¦  «        z  }t          | |¦  «        }t          j        t          ||j
        ¬¦  «        d¦  «        }t          j        |t          |¦  «        df¦  «        }	t          t          j        |dk    ¦  «        d         ¦  «        }
t          j        t          |¦  «        d¦  «        }|
D ]}t          j        ||<   Œt!          ||¦  «        }|dk    rt#          d	|d         z  ¦  «         |d
k    r,t#          ¦   «          t#          d¦  «         t#          d¦  «         	 	 |d
k    rJ|j        pt'          || ¦  «        }|j        pt+          || ¦  «        }|j        }t#          d|||fz  ¦  «         t/          | ||
||||	|¦  «        }|                     ¦   «         }||z  }|                     |¦  «         |                     || ¦  «        rnŒ¬n # t6          $ r t#          d¦  «         Y n ‚ xY w|d
k    r7t'          || ¦  «        }t+          || ¦  «        }t#          d|d›d|d›�¦  «         |S )a‚  
    Train a new ``ConditionalExponentialClassifier``, using the given
    training samples, using the Improved Iterative Scaling algorithm.
    This ``ConditionalExponentialClassifier`` will encode the model
    that maximizes entropy from all the models that are empirically
    consistent with ``train_toks``.

    :see: ``train_maxent_classifier()`` for parameter descriptions.
    r�   r/  Nr0  )r?   r1  rT   r   r2  r=   r3  r4  Tr5  r6  r7  r8  r9  r:  )r;  r   rÊ   r¡   r<  r   Úcalculate_nfmapr=  Úarrayr\   Ú__getitem__ÚreshaperÛ   r>  r?  r@  rA  r^   rC  r   rD  r   rE  Úcalculate_deltasr   r&   rG  rH  )r¤   r™   r   r"   r¦   rI  Úempirical_ffreqÚnfmapÚnfarrayÚnftransposerL  r   rq   rM  rC  rD  rO  Údeltass                     r   r�   r�   ƒ  sØ  € ð ×Ò�z 3Ñ'Ô'Ð'Ý! 'Ñ*Ô*€Mð ÐÝ.×4Ò4°ZÈÐ4ÑOÔOˆõ 1°¸XÑFÔFÍÈZÉÌÑX€Oõ ˜J¨Ñ1Ô1€EÝŒk�& ¨EÔ,=Ð>Ñ>Ô>ÀÑDÔD€GÝ”- ­#¨g©,¬,¸Ð):Ñ;Ô;€Kõ •U”] ?°aÒ#7Ñ8Ô8¸Ô;Ñ<Ô<€Jõ Œk�#˜oÑ.Ô.°Ñ4Ô4€GØð "ð "ˆÝ”zˆ�‰ˆÝ1°(¸GÑDÔD€Jàˆq‚y€yÝÐ.°¸Ô1DÑDÑEÔEÐEØˆq‚y€yÝ‰ŒˆÝÐ=Ñ>Ô>Ð>ÝÐ=Ñ>Ô>Ð>ð ð	Ø�qŠyˆyØ"Ô%ÐO­¸
ÀJÑ)OÔ)O�Ø#Ô'ÐK­8°JÀ
Ñ+KÔ+K�Ø'Ô,�ÝÐ3°wÀÀCÐ6HÑHÑIÔIÐIõ &ØØØØØØØØñ	ô 	ˆFð !×(Ò(Ñ*Ô*ˆGØ�vÑˆGØ×"Ò" 7Ñ+Ô+Ð+ð ×"Ò" :¨zÑ:Ô:ð Øð5	ð4 øåð <ð <ð <ÝÐ:Ñ;Ô;Ð;Ð;Ð;ðØøøøàˆq‚y€yÝ˜J¨
Ñ3Ô3ˆÝ�z :Ñ.Ô.ˆÝÐ; 2Ð;Ð;Ð;°Ð;Ð;Ð;Ñ<Ô<Ð<ð Ðs   ÆB-H1 È1IÉIc                 ó  — t          ¦   «         }| D ]\\  }}|                     ¦   «         D ]B}|                     t          d„ |                     ||¦  «        D ¦   «         ¦  «        ¦  «         ŒCŒ]d„ t          |¦  «        D ¦   «         S )aó  
    Construct a map that can be used to compress ``nf`` (which is
    typically sparse).

    *nf(feature_vector)* is the sum of the feature values for
    *feature_vector*.

    This represents the number of features that are active for a
    given labeled text.  This method finds all values of *nf(t)*
    that are attested for at least one token in the given list of
    training tokens; and constructs a dictionary mapping these
    attested values to a continuous range *0...N*.  For example,
    if the only values of *nf()* that were attested were 3, 5, and
    7, then ``_nfmap`` might return the dictionary ``{3:0, 5:1, 7:2}``.

    :return: A map that can be used to compress ``nf`` to a dense
        vector.
    :rtype: dict(int -> int)
    c              3   ó    K  — | ]	\  }}|V — Œ
d S r!   rE   ©rF   ÚidrV  s      r   rH   z"calculate_nfmap.<locals>.<genexpr>÷  s&   è è € ÐKÐK¡) 2 s˜#ÐKÐKÐKÐKÐKÐKr   c                 ó   — i | ]\  }}||“Œ	S rE   rE   )rF   ri   Únfs      r   rÏ   z#calculate_nfmap.<locals>.<dictcomp>ø  s   € Ð2Ð2Ð2‘g�q˜"ˆB�Ð2Ð2Ð2r   )rÛ   r"   rý   r  r2   rb   )r¤   r   Únfsetr  Ú_r4   s         r   rY  rY  ß  s™   € õ* ‰EŒE€EØð Mð M‰ˆˆQØ—_’_Ñ&Ô&ð 	Mð 	MˆEØ�IŠI•cÐKÐK¨x¯ª¸sÀEÑ/JÔ/JÐKÑKÔKÑKÔKÑLÔLÐLÐLð	Mà2Ð2¥¨5Ñ!1Ô!1Ð2Ñ2Ô2Ð2r   c           	      óÆ  — d}d}	t          j        |                     ¦   «         d¦  «        }
t          j        t	          |¦  «        |                     ¦   «         fd¦  «        }| D ]–\  }}|                     |¦  «        }|                     ¦   «         D ]g}|                     ||¦  «        }t          d„ |D ¦   «         ¦  «        }|D ]3\  }}|||         |fxx         | 	                    |¦  «        |z  z  cc<   Œ4ŒhŒ—|t	          | ¦  «        z  }t          |	¦  «        D ]Ä}t          j        ||
¦  «        }d|z  }||z  }t          j        ||z  d¬¦  «        }t          j        ||z  d¬¦  «        }|D ]}||xx         dz  cc<   Œ|
||z
  | z  z  }
t          j        t          ||z
  ¦  «        ¦  «        t          j        t          |
¦  «        ¦  «        z  }||k     r|
c S ŒÅ|
S )	a
  
    Calculate the update values for the classifier weights for
    this iteration of IIS.  These update weights are the value of
    ``delta`` that solves the equation::

      ffreq_empirical[i]
             =
      SUM[fs,l] (classifier.prob_classify(fs).prob(l) *
                 feature_vector(fs,l)[i] *
                 exp(delta[i] * nf(feature_vector(fs,l))))

    Where:
        - *(fs,l)* is a (featureset, label) tuple from ``train_toks``
        - *feature_vector(fs,l)* = ``encoding.encode(fs,l)``
        - *nf(vector)* = ``sum([val for (id,val) in vector])``

    This method uses Newton's method to solve this equation for
    *delta[i]*.  In particular, it starts with a guess of
    ``delta[i]`` = 1; and iteratively updates ``delta`` with:

    | delta[i] -= (ffreq_empirical[i] - sum1[i])/(-sum2[i])

    until convergence, where *sum1* and *sum2* are defined as:

    |    sum1[i](delta) = SUM[fs,l] f[i](fs,l,delta)
    |    sum2[i](delta) = SUM[fs,l] (f[i](fs,l,delta).nf(feature_vector(fs,l)))
    |    f[i](fs,l,delta) = (classifier.prob_classify(fs).prob(l) .
    |                        feature_vector(fs,l)[i] .
    |                        exp(delta[i] . nf(feature_vector(fs,l))))

    Note that *sum1* and *sum2* depend on ``delta``; so they need
    to be re-computed each iteration.

    The variables ``nfmap``, ``nfarray``, and ``nftranspose`` are
    used to generate a dense encoding for *nf(ltext)*.  This
    allows ``_deltas`` to calculate *sum1* and *sum2* using
    matrices, which yields a significant performance improvement.

    :param train_toks: The set of training tokens.
    :type train_toks: list(tuple(dict, str))
    :param classifier: The current classifier.
    :type classifier: ClassifierI
    :param ffreq_empirical: An array containing the empirical
        frequency for each feature.  The *i*\ th element of this
        array is the empirical frequency for feature *i*.
    :type ffreq_empirical: sequence of float
    :param unattested: An array that is 1 for features that are
        not attested in the training data; and 0 for features that
        are attested.  In other words, ``unattested[i]==0`` iff
        ``ffreq_empirical[i]==0``.
    :type unattested: sequence of int
    :param nfmap: A map that can be used to compress ``nf`` to a dense
        vector.
    :type nfmap: dict(int -> int)
    :param nfarray: An array that can be used to uncompress ``nf``
        from a dense vector.
    :type nfarray: array(float)
    :param nftranspose: The transpose of ``nfarray``
    :type nftranspose: array(float)
    gê-�™—q=i,  r1  c              3   ó    K  — | ]	\  }}|V — Œ
d S r!   rE   re  s      r   rH   z#calculate_deltas.<locals>.<genexpr>U  s&   è è € Ð9Ð9™Y˜b #�SÐ9Ð9Ð9Ð9Ð9Ð9r   r=   r   )ÚaxisrT   )r=  Úonesr   r?  r   r*   r"   r2   r  rY   rt   ÚouterrM   )r¤   rM  rL  Úffreq_empiricalr_  r`  ra  r   ÚNEWTON_CONVERGEÚ
MAX_NEWTONrb  ÚAr  r4   Údistr5   rh  rf  rV  ÚrangenumÚnf_deltaÚexp_nf_deltaÚnf_exp_nf_deltaÚsum1Úsum2rq   Ún_errors                              r   r]  r]  û  s)  € ðR €OØ€JåŒZ˜ŸšÑ)Ô)¨3Ñ/Ô/€Fõ
 	Œ•S˜‘Z”Z §¢Ñ!2Ô!2Ð3°SÑ9Ô9€Aà ð 
;ð 
;‰
ˆˆUØ×'Ò'¨Ñ,Ô,ˆà—_’_Ñ&Ô&ð 	;ð 	;ˆEà%Ÿ_š_¨S°%Ñ8Ô8ˆNåÐ9Ð9¨.Ð9Ñ9Ô9Ñ9Ô9ˆBà+ð ;ð ;‘	��SØ�%˜”)˜R�-Ð Ð Ô  D§I¢I¨eÑ$4Ô$4°sÑ$:Ñ:Ð Ð Ñ Ð ð;ð	;ð �ˆZ‰ŒÑ€Aõ ˜*Ñ%Ô%ð ð ˆÝ”;˜w¨Ñ/Ô/ˆØ˜(‘{ˆØ%¨Ñ4ˆÝŒy˜¨Ñ)°Ð2Ñ2Ô2ˆÝŒy˜¨1Ñ,°1Ð5Ñ5Ô5ˆð ð 	ð 	ˆCØ�ˆIˆIŒI˜‰NˆIˆI‰IˆIð 	�? TÑ)¨d¨UÑ2Ñ2ˆõ ”)�C °$Ñ 6Ñ7Ô7Ñ8Ô8½5¼9ÅSÈÁ[Ä[Ñ;QÔ;QÑQˆØ�_Ò$Ð$ØˆMˆMˆMð %ð €Mr   c                 ó^  — d}d}d|v r|d         }d|v r|d         }|€5|                      dd¦  «        }t                               | ||d¬¦  «        }n|�t          d¦  «        ‚	 t	          j        d	¬
¦  «        \  }	}
t          |
d¦  «        5 }t          | ||||¬¦  «         ddd¦  «         n# 1 swxY w Y   t          j	        |	¦  «         n,# t          t          f$ r}t          d|z  ¦  «        |‚d}~ww xY wg }|g d¢z  }|r|dgz  }|s|dgz  }|r	d|dz  z  }nd}|dd|z  dgz  }|dk     r|dgz  }d|v r|dd|d         z  gz  }d|v r|ddt          |d         ¦  «        z  gz  }t          |d¦  «        r|dgz  }|d|
gz  }t          |¦  «        }	 t          j        |
¦  «         n,# t          $ r}t          d |
› d!|› �¦  «         Y d}~nd}~ww xY wt!          ||                     ¦   «         |¦  «        }|t%          j        t$          j        ¦  «        z  }t+          ||¦  «        S )"a›  
    Train a new ``ConditionalExponentialClassifier``, using the given
    training samples, using the external ``megam`` library.  This
    ``ConditionalExponentialClassifier`` will encode the model that
    maximizes entropy from all the models that are empirically
    consistent with ``train_toks``.

    :see: ``train_maxent_classifier()`` for parameter descriptions.
    :see: ``nltk.classify.megam``
    Tr”   r•   Nr’   r   )r"   rã   z$Specify encoding or labels, not bothznltk-©ÚprefixÚw)r”   r•   z,Error while creating megam training file: %s)z-nobiasz-repeatÚ10z	-explicitz-fvalsr/   r=   z-lambdaz%.2fz-tunerŠ   z-quietr�   z-maxirC   Úll_deltaz-dppÚcostz-multilabelÚ
multiclasszWarning: unable to delete z: )ÚgetrÊ   r¡   r¢   ÚtempfileÚmkstempÚopenr   ÚosÚcloseÚOSErrorrM   rr   r   Úremover^   r   r   r=  rB  Úer   )r¤   r™   r   r"   rš   r§   r”   r•   r’   ÚfdÚtrainfile_nameÚ	trainfilerŒ  rÿ   Úinv_varianceÚstdoutr   s                    r   rŸ   rŸ   �  sL  € ð €HØ€IØ�VÐÐØ˜*Ô%ˆØ�fÐÐØ˜;Ô'ˆ	ð Ðð —z’z .°!Ñ4Ô4ˆÝ.×4Ò4Ø˜¨VÀtð 5ñ 
ô 
ˆˆð 
Ð	ÝÐ?Ñ@Ô@Ð@ðTÝ%Ô-°WÐ=Ñ=Ô=ÑˆˆNÝ�. #Ñ&Ô&ð 	¨)ÝØ˜H i¸(Èiðñ ô ð ð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	õ 	Œ�‰ŒˆˆøÝ•ZÐ ð Tð Tð TÝÐGÈ!ÑKÑLÔLÐRSÐSøøøøðTøøøð €GØÐ+Ð+Ð+Ñ+€GØð !Ø�K�=Ñ ˆØð Ø�H�:ÑˆØð ð Ð1°1Ñ4Ñ4ˆˆàˆØ�	˜6 LÑ0°'Ð:Ñ:€GØˆq‚y€yØ�H�:ÑˆØ�VÐÐØ�G˜T F¨:Ô$6Ñ6Ð7Ñ7ˆØ�VÐÐð 	�F˜D¥3 v¨jÔ'9Ñ#:Ô#:Ñ:Ð;Ñ;ˆÝˆx˜Ñ Ô ð #Ø�M�?Ñ"ˆØ�˜nÐ-Ñ-€GÝ˜Ñ Ô €FðBÝ
Œ	�.Ñ!Ô!Ð!Ð!øÝð Bð Bð BÝÐ@¨>Ð@Ð@¸QÐ@Ð@ÑAÔAÐAÐAÐAÐAÐAÐAøøøøðBøøøõ " &¨(¯/ª/Ñ*;Ô*;¸XÑFÔF€Gð �uŒz�%œ'Ñ"Ô"Ñ"€Gõ ˜H gÑ.Ô.Ð.sT   Á&(C ÂB/Â#C Â/B3Â3C Â6B3Â7C ÃC8Ã C3Ã3C8ÆF/ Æ/
GÆ9GÇGc                   ó$   — e Zd Zed„ ¦   «         ZdS )r    c                 ó„  — |                      dd¦  «        }|                      dd¦  «        }|                      dd ¦  «        }|                      dd ¦  «        }|                      dd¦  «        }|                      d	d¦  «        }|                      d
¦  «        }	|                      d¦  «        }
|st                               |||¬¦  «        }t          j        dd¬¦  «        \  }}t          j        d¬¦  «        \  }}t          |d¦  «        }t          |||¦  «         |                     ¦   «          g }|                     dg¦  «         |                     d|g¦  «         |r|                     dd|dz  z  g¦  «         |	r|                     dd|	z  g¦  «         |
r'|                     ddt          |
¦  «        z  g¦  «         |                     d|g¦  «         |                     d|g¦  «         |dk     r|                     dg¦  «         n|                     dg¦  «         t          |¦  «         t          |¦  «        5 }t          |¦  «        }d d d ¦  «         n# 1 swxY w Y   t          j        |¦  «         t          j        |¦  «         |t          j        t          j        ¦  «        z  } | ||¦  «        S )Nr¥   Útao_lmvmr™   rŠ   r   r"   rš   r   r’   r�   r�   r0  znltk-tadm-events-z.gz)r~  Úsuffixznltk-tadm-weights-r}  r  z-monitorz-methodz-l2z%.6fr=   z-max_itz%dz-fatolz
-events_inz-params_outz2>&1z-summary)r„  r  r¡   r…  r†  r   r
   r‰  ÚextendrM   r   r‡  r	   rˆ  r‹  r=  rB  rŒ  )r£   r¤   r§   r¥   r™   r   r"   Úsigmar’   r�   r�  Útrainfile_fdrŽ  Úweightfile_fdÚweightfile_namer�  rÿ   Ú
weightfiler   s                      r   r¡   zTadmMaxentClassifier.trainÞ  s  € à—J’J˜{¨JÑ7Ô7ˆ	Ø—
’
˜7 AÑ&Ô&ˆØ—:’:˜j¨$Ñ/Ô/ˆØ—’˜H dÑ+Ô+ˆØ—
’
Ð1°1Ñ5Ô5ˆØ—z’z .°!Ñ4Ô4ˆØ—:’:˜jÑ)Ô)ˆØ—:’:˜mÑ,Ô,ˆð ð 	Ý5×;Ò;Ø˜L°ð <ñ ô ˆHõ (0Ô'7Ø&¨uð(
ñ (
ô (
Ñ$ˆ�nõ *2Ô)9ÐAUÐ)VÑ)VÔ)VÑ&ˆ�å% n°cÑ:Ô:ˆ	Ý˜
 H¨iÑ8Ô8Ð8Ø�ŠÑÔÐàˆØ�Š˜
�|Ñ$Ô$Ð$Ø�Š˜	 9Ð-Ñ.Ô.Ð.Øð 	7Ø�NŠN˜E 6¨E°1©HÑ#4Ð5Ñ6Ô6Ð6Øð 	9Ø�NŠN˜I t¨h¡Ð7Ñ8Ô8Ð8Øð 	?Ø�NŠN˜H f­s°8©}¬}Ñ&<Ð=Ñ>Ô>Ð>Ø�Š˜ nÐ5Ñ6Ô6Ð6Ø�Š˜ Ð7Ñ8Ô8Ð8Ø�1Š9ˆ9Ø�NŠN˜F˜8Ñ$Ô$Ð$Ð$à�NŠN˜J˜<Ñ(Ô(Ð(å�'ÑÔÐå�/Ñ"Ô"ð 	5 jÝ(¨Ñ4Ô4ˆGð	5ð 	5ð 	5ñ 	5ô 	5ð 	5ð 	5ð 	5ð 	5ð 	5ð 	5øøøð 	5ð 	5ð 	5ð 	5õ 	Œ	�.Ñ!Ô!Ð!Ý
Œ	�/Ñ"Ô"Ð"ð 	•5”:�eœgÑ&Ô&Ñ&ˆð ˆs�8˜WÑ%Ô%Ð%s   ÉI"É"I&É)I&N)r¨   r©   rª   r­   r¡   rE   r   r   r    r    Ý  s-   € € € € € Øð5&ð 5&ñ „[ð5&ð 5&ð 5&r   r    c                  ó<   — ddl m}   | t          j        ¦  «        }d S )Nr   )Ú
names_demo)Únltk.classify.utilr�  r   r¡   )r�  rM  s     r   ÚdemorŸ    s+   € Ø-Ð-Ð-Ð-Ð-Ð-à�Õ,Ô2Ñ3Ô3€J€J€Jr   Ú__main__)rŠ   NN)rŠ   NNr   ).r«   r=  ÚImportErrorrˆ  r…  Úcollectionsr   Únltk.classify.apir   Únltk.classify.megamr   r   r   Únltk.classify.tadmr   r	   r
   rž  r   r   r   Ú	nltk.datar   Únltk.probabilityr   Ú	nltk.utilr   Ú__docformat__r   rA  r¯   r¼   rÊ   r  r  r"  rž   r<  rF  r�   rY  r]  rŸ   r    rŸ  r¨   rE   r   r   ú<module>rª     sp  ðð,ð ,ðZ	Ø€L€L€L€LøØð 	ð 	ð 	Ø€Dð	øøøð 
€	€	€	Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #à )Ð )Ð )Ð )Ð )Ð )Ø QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ QØ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FØ 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø /Ð /Ð /Ð /Ð /Ð /Ø !Ð !Ð !Ð !Ð !Ð !à€ðJAð JAð JAð JAð JA�{ñ JAô JAð JAð\ $4Ð  ðF$ð F$ð F$ð F$ð F$ñ F$ô F$ð F$ðR,*ð ,*ð ,*ð ,*ð ,*Ð*@ñ ,*ô ,*ð ,*ð^H/ð H/ð H/ð H/ð H/Ð"8ñ H/ô H/ð H/ðV:Dð :Dð :Dð :Dð :DÐ-ñ :Dô :Dð :Dðz5/ð 5/ð 5/ð 5/ð 5/Ð%@ñ 5/ô 5/ð 5/ðpa/ð a/ð a/ð a/ð a/Ð!7ñ a/ô a/ð a/ðT 04ð_ð _ð _ð _ðDð ð ð
ð 
ð 
ð& 04ðYð Yð Yð Yðx3ð 3ð 3ð8{ð {ð {ðN KLðT/ð T/ð T/ð T/ðx7&ð 7&ð 7&ð 7&ð 7&Ð+ñ 7&ô 7&ð 7&ðz4ð 4ð 4ð ˆzÒÐØ€D�F„F€F€F€Fð Ðs   „	 ‰�