Ë
    çÍ:jº  ã                   óÜ   — d Z ddlmZmZ ddlmZmZm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 G d„ de«      Z G d„ de«      Z G d„ de«      Zy)zLanguage Modelsé    )ÚLanguageModelÚ	Smoothing)ÚAbsoluteDiscountingÚ	KneserNeyÚ
WittenBellc                   ó   — e Zd ZdZdd„Zy)ÚMLEzbClass for providing MLE ngram model scores.

    Inherits initialization from BaseNgramModel.
    Nc                 óB   — | j                  |«      j                  |«      S )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      úc/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/nltk/lm/models.pyÚunmasked_scorezMLE.unmasked_score   s    € ð ×"Ñ" 7Ó+×0Ñ0°Ó6Ð6ó    ©N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   © r   r   r	   r	      s   „ ñô
7r   r	   c                   ó*   ‡ — e Zd ZdZˆ fd„Zdd„Zˆ xZS )ÚLidstonez«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        ‰| �  |i |¤Ž || _        y r   )ÚsuperÚ__init__Úgamma)r   r   ÚargsÚkwargsÚ	__class__s       €r   r   zLidstone.__init__%   ó   ø€ Ü‰Ñ˜$Ð) &Ò)Øˆ�
r   c                 ó¸   — | j                  |«      }||   }|j                  «       }|| j                  z   |t        | j                  «      | j                  z  z   z  S )ztAdd-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   zLidstone.unmasked_score)   sR   € ð ×$Ñ$ WÓ-ˆØ˜D‘\ˆ
Ø—X‘X“Zˆ
Ø˜TŸZ™ZÑ'¨J¼¸T¿Z¹Z»È4Ï:É:Ñ9UÑ,UÑVÐVr   r   ©r   r   r   r   r   r   Ú__classcell__©r!   s   @r   r   r      s   ø„ ñô÷	Wr   r   c                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )ÚLaplacezwImplements Laplace (add one) smoothing.

    Initialization identical to BaseNgramModel because gamma is always 1.
    c                 ó,   •— t        ‰| �  dg|¢­i |¤Ž y )Né   )r   r   )r   r   r    r!   s      €r   r   zLaplace.__init__;   s   ø€ Ü‰Ñ˜Ð,˜TÒ, VÓ,r   ©r   r   r   r   r   r+   r,   s   @r   r.   r.   5   s   ø„ ñ÷
-ð -r   r.   c                   ó,   ‡ — e Zd ZdZdˆ fd„	Zdd„Zˆ xZS )ÚStupidBackoffa8  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        ‰| �  |i |¤Ž || _        y r   )r   r   Úalpha)r   r5   r   r    r!   s       €r   r   zStupidBackoff.__init__H   r"   r   c                 ó>  — |r#| j                   dz
  }t        |«      |kD  r|| d  }|s%| j                  j                  j	                  |«      S | j                  |«      }||   }|j                  «       }|dkD  r||z  S | j                  | j                  ||dd  «      z  S )Nr0   r   )	Úorderr%   r'   Úunigramsr   r   r$   r5   r   )r   r   r   Úmax_ctxr'   r(   r)   s          r   r   zStupidBackoff.unmasked_scoreL   s¢   € ÙØ—j‘j 1‘nˆGÜ�7‹|˜gÒ%Ø! 7 ( )Ð,�áà—;‘;×'Ñ'×,Ñ,¨TÓ2Ð2à×$Ñ$ WÓ-ˆØ˜D‘\ˆ
Ø—X‘X“Zˆ
à˜Š>Ø 
Ñ*Ð*à—:‘: × 3Ñ 3°D¸'À!À"¸+Ó FÑFÐFr   )gš™™™™™Ù?r   r*   r,   s   @r   r3   r3   ?   s   ø„ ñõ÷Gr   r3   c                   ó*   ‡ — e Zd ZdZˆ fd„Zdd„Zˆ xZS )ÚInterpolatedLanguageModelz¡Logic common to all interpolated language models.

    The idea to abstract this comes from Chen & Goodman 1995.
    Do not instantiate this class directly!
    c                 ó�   •— |j                  di «      }t        ‰| �  |fi |¤Ž  || j                  | j                  fi |¤Ž| _        y )NÚparams)Úpopr   r   r&   r'   Ú	estimator)r   Úsmoothing_clsr7   r    r=   r!   s        €r   r   z"InterpolatedLanguageModel.__init__g   s@   ø€ Ø—‘˜H bÓ)ˆÜ‰Ñ˜Ñ) &Ò)Ù& t§z¡z°4·;±;ÑIÀ&ÑIˆ�r   c                 ó$  — |r#| j                   dz
  }t        |«      |kD  r|| d  }|s| j                  j                  |«      S | j                  |   sd\  }}n| j                  j                  ||«      \  }}||| j                  ||dd  «      z  z   S )Nr0   )r   r0   )r7   r%   r?   Úunigram_scorer'   Úalpha_gammar   )r   r   r   r9   r5   r   s         r   r   z(InterpolatedLanguageModel.unmasked_scorel   s˜   € ÙØ—j‘j 1‘nˆGÜ�7‹|˜gÒ%Ø! 7 ( )Ð,�áà—>‘>×/Ñ/°Ó5Ð5à�{‰{˜7Ò#ð  ‰LˆE‘5àŸ>™>×5Ñ5°d¸GÓD‰LˆE�5à�u˜t×2Ñ2°4¸ÀÀ¸ÓEÑEÑEÐEr   r   r*   r,   s   @r   r;   r;   `   s   ø„ ñôJ÷
Fr   r;   c                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )ÚWittenBellInterpolatedz.Interpolated version of Witten-Bell smoothing.c                 ó0   •— t        ‰| �  t        |fi |¤Ž y r   )r   r   r   )r   r7   r    r!   s      €r   r   zWittenBellInterpolated.__init__„   s   ø€ Ü‰Ñœ UÑ5¨fÓ5r   r1   r,   s   @r   rE   rE   �   s   ø„ Ù8÷6ð 6r   rE   c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )ÚAbsoluteDiscountingInterpolatedz9Interpolated version of smoothing with absolute discount.c                 ó8   •— t        ‰| �  t        |fdd|ii|¤Ž y )Nr=   Údiscount)r   r   r   ©r   r7   rJ   r    r!   s       €r   r   z(AbsoluteDiscountingInterpolated.__init__‹   s*   ø€ Ü‰ÑÜ ñ	
Ø0:¸HÐ/Eð	
ØIOó	
r   )g      è?r1   r,   s   @r   rH   rH   ˆ   s   ø„ ÙC÷
ñ 
r   rH   c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )ÚKneserNeyInterpolatedz-Interpolated version of Kneser-Ney smoothing.c                 ó~   •— d|cxk  rdk  st        d«      ‚ t        d«      ‚t        ‰| �  t        |fd||dœi|¤Ž y )Nr   r0   zCDiscount must be between 0 and 1 for probabilities to sum to unity.r=   )rJ   r7   )Ú
ValueErrorr   r   r   rK   s       €r   r   zKneserNeyInterpolated.__init__”   s^   ø€ Ø�XÔ" Ò"ÜØUóð ð #ÜØUóð ô 	‰ÑÜ�uñ	
Ø2:ÀUÑ%Kð	
ØOUó	
r   )gš™™™™™¹?r1   r,   s   @r   rM   rM   ‘   s   ø„ Ù7÷
ñ 
r   rM   N)r   Únltk.lm.apir   r   Únltk.lm.smoothingr   r   r   r	   r   r.   r3   r;   rE   rH   rM   r   r   r   ú<module>rR      s~   ðñ ç 0ß HÑ Hô7ˆ-ô 7ô Wˆ}ô Wô.-ˆhô -ôG�Mô GôBF ô FôB6Ð6ô 6ô
Ð&?ô 
ô

Ð5õ 

r   