ó
    ´OÂfš  ã                   óÜ   • S r SSKJrJr  SSKJrJrJr   " S S\5      r " S S\5      r	 " S S	\	5      r
 " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)zLanguage Modelsé    )ÚLanguageModelÚ	Smoothing)ÚAbsoluteDiscountingÚ	KneserNeyÚ
WittenBellc                   ó"   • \ rS rSrSrSS jrSrg)ÚMLEé   zZClass for providing MLE ngram model scores.

Inherits initialization from BaseNgramModel.
Nc                 óB   • U R                  U5      R                  U5      $ )z£Returns the MLE score for a word given a context.

Args:
- word is expected to be a string
- context is expected to be something reasonably convertible to a tuple
)Úcontext_countsÚfreq)ÚselfÚwordÚcontexts      Ú0/usr/lib/python3/dist-packages/nltk/lm/models.pyÚunmasked_scoreÚMLE.unmasked_score   s    € ð ×"Ñ" 7Ó+×0Ñ0°Ó6Ð6ó    © ©N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__static_attributes__r   r   r   r	   r	      s   † ñ÷
7r   r	   c                   ó6   ^ • \ rS rSrSrU 4S jrSS jrSrU =r$ )ÚLidstoneé   zŸProvides Lidstone-smoothed scores.

In addition to initialization arguments from BaseNgramModel also requires
a number by which to increase the counts, gamma.
c                 ó2   >• [         TU ]  " U0 UD6  Xl        g r   )ÚsuperÚ__init__Úgamma)r   r#   ÚargsÚkwargsÚ	__class__s       €r   r"   ÚLidstone.__init__%   ó   ø€ Ü‰Ò˜$Ð) &Ò)Ø�
r   c                 ó´   • U R                  U5      nX1   nUR                  5       nX@R                  -   U[        U R                  5      U R                  -  -   -  $ )zdAdd-one smoothing: Lidstone or Laplace.

To see what kind, look at `gamma` attribute on the class.

)r   ÚNr#   ÚlenÚvocab©r   r   r   ÚcountsÚ
word_countÚ
norm_counts         r   r   ÚLidstone.unmasked_score)   sN   € ð ×$Ñ$ WÓ-ˆØ‘\ˆ
Ø—X‘X“Zˆ
ØŸZ™ZÑ'¨J¼¸T¿Z¹Z»È4Ï:É:Ñ9UÑ,UÑVÐVr   )r#   r   ©	r   r   r   r   r   r"   r   r   Ú__classcell__©r&   s   @r   r   r      s   ø† ñõ÷	Wò 	Wr   r   c                   ó,   ^ • \ rS rSrSrU 4S jrSrU =r$ )ÚLaplaceé5   zoImplements Laplace (add one) smoothing.

Initialization identical to BaseNgramModel because gamma is always 1.
c                 ó.   >• [         TU ]  " S/UQ70 UD6  g )Né   )r!   r"   )r   r$   r%   r&   s      €r   r"   ÚLaplace.__init__;   s   ø€ Ü‰Ò˜Ð,˜TÒ, VÓ,r   r   ©r   r   r   r   r   r"   r   r3   r4   s   @r   r6   r6   5   s   ø† ñ÷
-ó -r   r6   c                   ó:   ^ • \ rS rSrSrSU 4S jjrSS jrSrU =r$ )ÚStupidBackoffé?   a$  Provides StupidBackoff scores.

In addition to initialization arguments from BaseNgramModel also requires
a parameter alpha with which we scale the lower order probabilities.
Note that this is not a true probability distribution as scores for ngrams
of the same order do not sum up to unity.
c                 ó2   >• [         TU ]  " U0 UD6  Xl        g r   )r!   r"   Úalpha)r   r@   r$   r%   r&   s       €r   r"   ÚStupidBackoff.__init__H   r(   r   c                 óú   • U(       d%  U R                   R                  R                  U5      $ U R                  U5      nX1   nUR	                  5       nUS:”  a  XE-  $ U R
                  U R                  XSS  5      -  $ )Nr   r9   )r.   Úunigramsr   r   r*   r@   r   r-   s         r   r   ÚStupidBackoff.unmasked_scoreL   sr   € Þà—;‘;×'Ñ'×,Ñ,¨TÓ2Ð2Ø×$Ñ$ WÓ-ˆØ‘\ˆ
Ø—X‘X“Zˆ
Ø˜‹>ØÑ*Ð*à—:‘: × 3Ñ 3°DÀ!À"¸+Ó FÑFÐFr   )r@   )gš™™™™™Ù?r   r2   r4   s   @r   r=   r=   ?   s   ø† ñ÷÷
Gò 
Gr   r=   c                   ó6   ^ • \ rS rSrSrU 4S jrSS jrSrU =r$ )ÚInterpolatedLanguageModeléY   z•Logic common to all interpolated language models.

The idea to abstract this comes from Chen & Goodman 1995.
Do not instantiate this class directly!
c                 ó’   >• UR                  S0 5      n[        TU ]  " U40 UD6  U" U R                  U R                  40 UD6U l        g )NÚparams)Úpopr!   r"   r,   r.   Ú	estimator)r   Úsmoothing_clsÚorderr%   rI   r&   s        €r   r"   Ú"InterpolatedLanguageModel.__init__`   s@   ø€ Ø—‘˜H bÓ)ˆÜ‰Ò˜Ñ) &Ò)Ù& t§z¡z°4·;±;ÑIÀ&ÑIˆ�r   c                 óä   • U(       d  U R                   R                  U5      $ U R                  U   (       d  Su  p4OU R                   R                  X5      u  p4X4U R	                  XSS  5      -  -   $ )N)r   r9   r9   )rK   Úunigram_scorer.   Úalpha_gammar   )r   r   r   r@   r#   s        r   r   Ú(InterpolatedLanguageModel.unmasked_scoree   sf   € Þà—>‘>×/Ñ/°Ó5Ð5Ø�{‰{˜7×#ð  ‰LˆE�5àŸ>™>×5Ñ5°dÓD‰LˆEØ˜t×2Ñ2°4ÀÀ¸ÓEÑEÑEÐEr   )rK   r   r2   r4   s   @r   rF   rF   Y   s   ø† ñõJ÷
Fò Fr   rF   c                   ó,   ^ • \ rS rSrSrU 4S jrSrU =r$ )ÚWittenBellInterpolatedés   z.Interpolated version of Witten-Bell smoothing.c                 ó2   >• [         TU ]  " [        U40 UD6  g r   )r!   r"   r   )r   rM   r%   r&   s      €r   r"   ÚWittenBellInterpolated.__init__v   s   ø€ Ü‰Òœ UÑ5¨fÓ5r   r   r;   r4   s   @r   rT   rT   s   s   ø† Ù8÷6ó 6r   rT   c                   ó0   ^ • \ rS rSrSrSU 4S jjrSrU =r$ )ÚAbsoluteDiscountingInterpolatedéz   z9Interpolated version of smoothing with absolute discount.c                 ó:   >• [         TU ]  " [        U4SSU00UD6  g )NrI   Údiscount)r!   r"   r   ©r   rM   r\   r%   r&   s       €r   r"   Ú(AbsoluteDiscountingInterpolated.__init__}   s*   ø€ Ü‰ÒÜ ñ	
Ø0:¸HÐ/Eð	
ØIOó	
r   r   )g      è?r;   r4   s   @r   rY   rY   z   s   ø† ÙC÷
õ 
r   rY   c                   ó0   ^ • \ rS rSrSrSU 4S jjrSrU =r$ )ÚKneserNeyInterpolatedéƒ   z-Interpolated version of Kneser-Ney smoothing.c                 ón   >• SUs=::  a  S::  d  O  [        S5      e[        TU ]  " [        U4SX!S.0UD6  g )Nr   r9   zCDiscount must be between 0 and 1 for probabilities to sum to unity.rI   )r\   rM   )Ú
ValueErrorr!   r"   r   r]   s       €r   r"   ÚKneserNeyInterpolated.__init__†   sG   ø€ Ø�XÕ" Õ"ÜØUóð ô 	‰ÒÜ�uñ	
Ø2:Ñ%Kð	
ØOUó	
r   r   )gš™™™™™¹?r;   r4   s   @r   r`   r`   ƒ   s   ø† Ù7÷
õ 
r   r`   N)r   Únltk.lm.apir   r   Únltk.lm.smoothingr   r   r   r	   r   r6   r=   rF   rT   rY   r`   r   r   r   Ú<module>rg      s|   ðñ ç 0ß HÑ Hô7ˆ-ô 7ô Wˆ}ô Wô.-ˆhô -ôG�Mô Gô4F ô Fô46Ð6ô 6ô
Ð&?ô 
ô

Ð5õ 

r   