Ë
    T^(h—_  ã                   ój  — d 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
ZddlmZ ddlmZ ddlmZ d	d
lmZmZmZmZ  e«       rddlmZ  e«       rddlZ ej4                  e«      Zedz  ZddiZdedefd„Zd„ Z ddefd„Z!ddede"defd„Z#d„ Z$d„ Z%defd„Z& ee«       G d„ de«      «       Z'dgZ(y)z"
Fast tokenizer class for Nougat.
é    N)Úpartial)ÚPool)ÚListÚOptionalÚUnion)ÚINIT_TOKENIZER_DOCSTRING)ÚPreTrainedTokenizerFast)Úadd_end_docstringsé   )Úis_levenshtein_availableÚis_nltk_availableÚloggingÚrequires_backends)Úratiou¡  
        tokenizer_object ([`tokenizers.Tokenizer`]):
            A [`tokenizers.Tokenizer`] object from ðŸ¤— tokenizers to instantiate from. See [Using tokenizers from ðŸ¤—
            tokenizers](../fast_tokenizers) for more information.
        tokenizer_file ([`str`]):
            A path to a local JSON file representing a previously serialized [`tokenizers.Tokenizer`] object from ðŸ¤—
            tokenizers.
Útokenizer_fileztokenizer.jsonÚtextÚreturnc                 ó  — t        j                  dd| t         j                  ¬«      } t        j                  dd| t         j                  ¬«      } t        j                  dd| t         j                  ¬«      } | j                  dd	«      } | j                  d
d«      j                  dd«      } t        j                  dd| «      } t        j                  dd| «      } t        j                  dd| t         j                  ¬«      } | S )a1  
    Make text compatible with Markdown formatting.

    This function makes various text formatting adjustments to make it compatible with Markdown.

    Args:
        text (`str`):
            The input text to be made Markdown-compatible.

    Returns:
        `str`: The Markdown-compatible text.
    z%^\(([\d.]+[a-zA-Z]?)\) \\\[(.+?)\\\]$z\[\2 \\tag{\1}\]©Úflagsz%^\\\[(.+?)\\\] \(([\d.]+[a-zA-Z]?)\)$z\[\1 \\tag{\2}\]z3^\\\[(.+?)\\\] \(([\d.]+[a-zA-Z]?)\) (\\\[.+?\\\])$z\[\1 \\tag{\2}\] \3z\. z. z\bm{z\mathbf{z{\\bm z\\mbox{ ?\\boldmath\$(.*?)\$}z\\mathbf{\1}z^((?:http|ftp|https):\/\/(?:[\w_-]+(?:(?:\.[\w_-]+)+))(?:[\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-]))z[\1](\1)z```\s*(.+?)\s*```z```\n\1\n```)ÚreÚsubÚMÚreplaceÚS)r   s    úq/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/nougat/tokenization_nougat_fast.pyÚmarkdown_compatibler   8   s×   € ô �6‰6Ð:Ð<OÐQUÔ]_×]aÑ]aÔb€Dä�6‰6Ð:Ð<OÐQUÔ]_×]aÑ]aÔb€Dä�6‰6Ø>ØØÜ�d‰dô	€Dð �<‰<˜ Ó%€Dà�<‰<˜ Ó-×5Ñ5°iÀÓM€DÜ�6‰6Ð2°OÀTÓJ€Dä�6‰6ØiØØó€Dô �6‰6Ð&¨¸ÄRÇTÁTÔJ€Dà€Kó    c                 óò  — | j                  d«      }g }t        |«      D �]E  \  }}t        j                  d|«      }|r|d   dvr|j	                  |«       Œ8|j                  d«      dz   }|j                  |«      dd }d}|d   dz   }	t        |«      D ]§  \  }
}d}|j                  «       j                  d«      \  }}}|sŒ.t        j                  d	|t        j                  t        j                  z  ¬
«      r|j                  d«      }||
dkD  rdndd|z  z   |
dkD  s|dk(  r|n|	z   |j                  «       z   z  }Œ© |t        |«      dz
  k(  r|dz  }|j	                  |«       �ŒH dj                  |«      S )a  
    Normalize lines in the given text that resemble list items. The function looks for lines that start optionally with
    '-' or '*', possibly followed by Roman numerals or digits indicating nesting levels. The function reformats such
    lines to make them more structured.

    Args:
        generation (str): The input text containing lines that need to be normalized.

    Returns:
        str: The input text with the list-like lines normalized.

    Note:
        The function uses regular expressions to identify and reformat the list-like lines. The patterns capture
        optional bullet points, nesting levels indicated by numerals, and the actual list item content. The
        normalization adjusts the bullet point style and nesting levels based on the captured patterns.
    ú
z	. ([-*]) r   )ú-Ú*é   ú NÚ z^[\dixv]+((?:\.[\dixv])?)+$r   ú.ú	)ÚsplitÚ	enumerater   ÚsearchÚappendÚgroupÚstripÚ	partitionÚmatchÚIr   ÚcountÚlenÚjoin)Ú
generationÚlinesÚoutput_linesÚline_noÚliner/   ÚdelimÚsplitsÚreplacementÚdelim1ÚiÚitemÚlevelÚpotential_numeralÚ_Úrests                   r   Únormalize_list_like_linesrC   b   sŒ  € ð$ ×Ñ˜TÓ"€EØ€LÜ" 5Ó)ó )‰ˆ�Ü—	‘	˜,¨Ó-ˆÙ˜˜Q™ zÑ1Ø×Ñ Ô%ØØ—‘˜A“ Ñ$ˆØ—‘˜EÓ" 1 2Ð&ˆØˆØ�a‘˜3‘ˆä  Ó(ò 	‰GˆAˆtØˆEØ)-¯©«×)?Ñ)?ÀÓ)DÑ&Ð˜q $ÙØä�x‰xÐ6Ð8IÔQS×QUÑQUÔXZ×X\ÑX\ÑQ\Õ]Ø)×/Ñ/°Ó4�àØ˜Qš‘ B¨4°%©<Ñ8ÀQÈÂUÈgÐYZÊl¹EÐ`fÑgÐjn×jtÑjtÓjvÑvñ‰Kð	ð ”c˜%“j 1‘nÒ$Ø˜4ÑˆKà×Ñ˜KÖ(ð5)ð8 �9‰9�\Ó"Ð"r   c                 óN   — t        |t        | «      «      D ]  }| |   dv sŒ|c S  y)z¼
    Find the index of the next punctuation mark.

    Args:
        text (`str`):
            String to examine
        start_idx (`int`, *optional*)
            Index where to start
    )r&   ú?ú!r    N)Úranger2   )r   Ú	start_idxr=   s      r   Úfind_next_punctuationrI   •   s5   € ô �9œc $›iÓ(ò ˆØ�‰7Ð+Ò+ØŠHðð r   Úmin_lenc                 óB  — | j                  «       }t        |«      }|d|z  k  r| S d}t        |t        |dz  «      «      D ]8  }d}t        d|«      D ]   }|||z
  |z
  dz
     |||z
  dz
     k7  sŒd} n |sŒ7|}Œ: |€| S || d }| }	|}
|
j	                  |«      r|	d|  }	|
d|  }
|
j	                  |«      rŒ|t        |
«      d }|
}	 t        |t        |«      «      }t        |ddd…   t        |«      «      }|r|r||| }|d|dz    }||v rnnŒH| dt        |«       }|S )a  
    Attempt to truncate repeating segments in the input string.

    This function looks for the longest repeating substring at the end of the input string and truncates it to appear
    only once. To be considered for removal, repetitions need to be continuous.

    Args:
        text (`str`):
            The input raw prediction to be truncated.
        min_len (int):
            The minimum length of the repeating segment.

    Returns:
        `str`: The input string with repeated segments truncated.
    é   NTr   r#   Féÿÿÿÿ)Úlowerr2   rG   ÚintÚendswithrI   )r   rJ   Ú
text_lowerÚtext_lengthÚmax_repetition_lengthÚrepetition_lengthÚsamer=   ÚlcsÚsubstituted_textÚsubstituted_text_lowerÚrepeating_tailÚsubstituted_text_lower_outÚsentence_endÚsentence_startÚsentenceÚtext_outs                    r   Útruncate_repetitionsr_   §   s»  € ð  —‘“€JÜ�j“/€Kà�Q˜‘[Ò Øˆð !ÐÜ" 7¬C°¸a±Ó,@ÓAò 	6ÐàˆÜ�qÐ+Ó,ò 	ˆAØ˜+Ð(9Ñ9¸AÑ=ÀÑAÑBÀjÐQ\Ð_`ÑQ`ÐcdÑQdÑFeÓeØ�Ùð	ò
 Ø$5Ñ!ð	6ð Ð$Øˆà
Ð+Ð+Ð,Ð
-€Cð ÐØ'ÐØ
 ×
)Ñ
)¨#Ô
.Ø+Ð,CÐ.CÐ-CÐDÐØ!7Ð8OÐ:OÐ9OÐ!PÐð !×
)Ñ
)¨#Õ
.ð
  ¤Ð$:Ó ;Ð =Ð>€Nð "8ÐØ
Ü,¨Z¼Ð=WÓ9XÓYˆÜ.¨z¹$¸B¸$Ñ/?ÄÐE_ÓA`ÓaˆÙ™NØ! .°Ð>ˆHØ)3Ð4F°lÀQÑ6FÐ)GÐ&Ø˜>Ñ)Øàð ð Ð5”cÐ4Ó5Ð6€Hà€Or   c                 ó|   — d„ }t        | t        «      r || «      S g }| D ]  }|j                   ||«      «       Œ |S )Nc                 óL   — t        j                  dd| «      j                  «       S )Nz(?:[\d_]|\*\*)r%   )r   r   r-   )Úss    r   Ú_cleanzremove_numbers.<locals>._cleanì   s   € Ü�v‰vÐ'¨¨QÓ/×5Ñ5Ó7Ð7r   )Ú
isinstanceÚstrr+   )r5   rc   ÚoutÚls       r   Úremove_numbersrh   ë   sF   € ò8ô �%œÔÙ�e‹}ÐØ
€CØò ˆØ�
‰
‘6˜!“9Õðà€Jr   c                 ó\  — t        j                  t        | «      «      }t        t        | «      dz
  «      D ]¼  }|dz   }||   s-|t        | «      dz
  k  r|dz  }||   s|t        | «      dz
  k  rŒt        ||   «      dk  sŒLt        ||   «      dkD  sŒ^t        ||   «      dk  sŒpt        ||   «      dkD  sŒ‚||   j	                  d«      rŒ—||   ||   k(  st        ||   ||   «      dkD  sŒ¸d||| Œ¾ t        j                  |«      d   }g }t        |«      dk(  r|S d}t        t        j                  |«      dkD  «      D ])  \  }}|sŒ	|j                  ||   ||   dz   f«       |dz   }Œ+ |j                  ||   |d   dz   f«       |D �	cg c]  }	|	d   |	d   z
  d	kD  sŒ|	‘Œ c}	S c c}	w )
a5  
    Get slices of text based on specific criteria within the lines.

    This function identifies and returns slices of text from the input lines based on certain conditions.

    These conditions were chosen by the Nougat authors:
    - The slice is less than 200 characters long.
    - The slice is more than 3 characters long.
    - The slice does not start with "[MISSING_PAGE".
    - The slice is either the same as the next slice or the ratio of the two in terms of Levensthein distance is
      greater than 0.9.

    Args:
        lines (`List[str]`):
            The list of lines containing the text.
        clean_lines (`List[str]`):
            A cleaned version of the text (without numbers).

    Returns:
        `List[tuple]`: A list of tuples representing the start and end indices of text slices.
    r#   éÈ   r   z[MISSING_PAGEçÍÌÌÌÌÌì?r   rL   rM   é   )
ÚnpÚzerosr2   rG   Ú
startswithr   Úwherer)   Údiffr+   )
r5   Úclean_linesÚindicesr=   ÚjÚidsÚslicesÚj0ÚxÚslis
             r   Ú
get_slicesrz   ÷   sÀ  € ô, �h‰h”s˜5“zÓ"€GÜ”3�u“: ‘>Ó"ò ˆØ�‰EˆØ˜a’. Q¬¨U«°a©Ò%7Ø�‰FˆAð ˜a’. Q¬¨U«°a©Ó%7ô �˜A‘Ó #Ó%Ü�K ‘NÓ# aÓ'Ü�K ‘NÓ# cÓ)Ü�K ‘NÓ# aÓ'Ø ‘N×-Ñ-¨oÕ>Ø˜Q‘ ;¨q¡>Ò1´U¸;Àq¹>È;ÐWXÉ>Ó5ZÐ]`Ó5`àˆG�A�a‰Lðô �(‰(�7Ó
˜AÑ
€CØ€FÜ
ˆ3ƒx�1‚}ØˆØ	
€BÜœ"Ÿ'™' #›,¨Ñ*Ó+ò ‰ˆˆ1ÚØ�M‰M˜3˜r™7 C¨¡F¨Q¡JÐ/Ô0Ø�Q‘‰Bðð ‡M�M�3�r‘7˜C ™G a™KÐ(Ô)Ø!Ö:�C S¨¡V¨c°!©f¡_°rÓ%9ŠCÒ:Ð:ùÒ:s   ÆF)Æ"F)c           	      óL  — ||d      }t        |«      }d}t        t        d|d   dz
  «      t        d|d   dz
  «      d«      D ]™  }| |   sŒ	| |   dk(  r||d<    n„t        |t	        | |   «      «      dk  sŒ4|dz   |d<   t	        | t        d|dz
  «         j                  d«      d   «      }t        |«      d	t        |«      z  k\  rt        ||«      dk  r||d<   d
} n t        t        t        | «      |d   «      t        t        | «      |d   dz   «      «      D ]$  }t        |t	        | |   «      «      dk  sŒ||d<    n t        | «      |d   k  rt        | «      dz
  |d<   dj                  | |d   |d   dz    «      }t        | |d   dz
     «      t        | |d      «      }
}		 	 t        |	«      \  }}|j                  «       rt        |	«      \  }}|j                  «       rŒt        |
«      \  }}|j                  «       rt        |
«      \  }}|j                  «       rŒ||k7  rn	 Œƒ|rd|v rd|j                  d«      d   z   }	 t        | |d      «      z
  dz
  }|dkD  r|d|  }|j                  «       S # t        $ r Y Œ[w xY w# t        $ r Y |j                  «       S w xY w)a  
    Remove a slice of text from the lines based on specific criteria.

    This function identifies a slice of text within the lines and removes it based on certain conditions.

    Args:
        lines (list of str): The list of lines containing the text.
        clean_text (list of str): A cleaned version of the text (without numbers).
        slice (tuple): A tuple representing the start and end indices of the slice to be removed.

    Returns:
        str: The removed slice of text as a single string.
    r   Fr#   é   rM   z## Referencesrk   z* [g      è?Tr    N)ÚlistrG   Úmaxr   rh   r.   r2   Úminr3   r)   ÚnextÚ	isnumericÚStopIterationÚUnboundLocalErrorr-   )r5   Ú
clean_textÚsliceÚbaseÚsectionÚcheck_start_flagÚline_idxÚpotential_refÚ	to_deleteÚiteraÚiterbÚiaÚaÚibÚbÚdeltas                   r   Úremove_slice_from_linesr“   (  så  € ð �e˜A‘hÑ€DÜ�5‹k€GØÐäœ#˜a  q¡¨A¡Ó.´°A°u¸Q±xÀ!±|Ó0DÀbÓIò ˆØ�XŠØØ�‰?˜oÒ-Ø!ˆG�A‰JÙÜ�4œ¨¨h©Ó8Ó9¸CÓ?Ø! A™ˆG�A‰JÜ*¨5´°Q¸À1¹Ó1EÑ+F×+PÑ+PÐQVÓ+WÐXZÑ+[Ó\ˆMÜ�=Ó! T¬C°«IÑ%5Ò5¼%ÀÀmÓ:TÐWZÒ:ZØ%�˜‘
Ø#ÐÙðô œ#œc %›j¨%°©(Ó3´S¼¸U»ÀUÈ1ÁXÐPQÁ\Ó5RÓSò ˆÜ�”~ e¨H¡oÓ6Ó7¸#Ó=Ø!ˆG�A‰JÙðô ˆ5ƒz�W˜Q‘ZÒÜ˜“Z !‘^ˆ�‰
Ø—	‘	˜% ¨¡
¨W°Q©Z¸!©^Ð<Ó=€Iä˜U 7¨1¡:°¡>Ñ2Ó3´Y¸uÀWÈQÁZÑ?PÓ5Qˆ5€EØ
ð
	Ü˜5“k‰GˆR�Ø—+‘+”-Ü˜u›+‘��Qð —+‘+•-ä˜5“k‰GˆR�Ø—+‘+”-Ü˜u›+‘��Qð —+‘+•-à�AŠvØð ð ñ ˜E YÑ.Ø˜I×/Ñ/°Ó6°rÑ:Ñ:ˆ	ðÜ�E˜' !™*Ñ%Ó&¨Ñ+¨aÑ/ˆØ�1Š9Ø! ' E 6Ð*ˆIð �?‰?ÓÐøô ò 	Ùð	ûô ò Øà�?‰?ÓÐðús0   Æ'<I9 Ç$<I9 È!I9 É"J É9	JÊJÊ	J#Ê"J#c                   ó¼   ‡ — e Zd ZdZeZddgZdZ	 	 	 	 	 	 	 dˆ fd„	Zde	de	fd„Z
d	e	de	fd
„Zdd	e	dede	fd„Z	 	 dd	ee	ee	   f   dedee   dee	ee	   f   fd„Zˆ xZS )ÚNougatTokenizerFasta’  
    Fast tokenizer for Nougat (backed by HuggingFace tokenizers library).

    This tokenizer inherits from [`PreTrainedTokenizerFast`] which contains most of the main methods. Users should
    refer to this superclass for more information regarding those methods. This class mainly adds Nougat-specific
    methods for postprocessing the generated text.

    Args:
        vocab_file (`str`, *optional*):
            [SentencePiece](https://github.com/google/sentencepiece) file (generally has a .model extension) that
            contains the vocabulary necessary to instantiate a tokenizer.
        tokenizer_file (`str`, *optional*):
            [tokenizers](https://github.com/huggingface/tokenizers) file (generally has a .json extension) that
            contains everything needed to load the tokenizer.

        clean_up_tokenization_spaces (`str`, *optional*, defaults to `False`):
            Wether to cleanup spaces after decoding, cleanup consists in removing potential artifacts like extra
            spaces.

        unk_token (`str`, *optional*, defaults to `"<unk>"`):
            The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
            token instead.

        bos_token (`str`, *optional*, defaults to `"<s>"`):
            The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token.

        eos_token (`str`, *optional*, defaults to `"</s>"`):
            The end of sequence token.

        pad_token (`str`, *optional*, defaults to `"<pad>"`):
            The token used for padding, for example when batching sequences of different lengths.
    Ú	input_idsÚattention_maskNc                 óB   •— t        ‰	| �  d|||||||dœ|¤Ž || _        y )N)Ú
vocab_filer   Úclean_up_tokenization_spacesÚ	unk_tokenÚ	bos_tokenÚ	eos_tokenÚ	pad_token© )ÚsuperÚ__init__r™   )
Úselfr™   r   rš   r›   rœ   r�   rž   ÚkwargsÚ	__class__s
            €r   r¡   zNougatTokenizerFast.__init__�  s?   ø€ ô 	‰Ñð 		
Ø!Ø)Ø)EØØØØñ		
ð ò		
ð %ˆ�r   r   r   c                 ó0  — |j                  d«      }t        |«      dk(  ryt        |«      }t        ||«      }g }|D ]  }|j	                  t        |||«      «       Œ  t        |«      D ]  }|j                  |d«      }Œ t        j                  dd|«      }|S )av  
        Remove hallucinated or missing references from the text.

        This function identifies and removes references that are marked as missing or hallucinated from the input text.

        Args:
            text (`str`):
                The input text containing references.

        Returns:
            `str`: The text with hallucinated references removed.
        r    r   r%   z

[MISSING_PAGE_POST]

z,## References\n+\[MISSING_PAGE_POST(:\d+)?\]z

[MISSING_PAGE_POST\1])
r(   r2   rh   rz   r+   r“   Úreversedr   r   r   )r¢   r   r5   rr   rv   r‹   r…   s          r   Úremove_hallucinated_referencesz2NougatTokenizerFast.remove_hallucinated_references§  s©   € ð —
‘
˜4Ó ˆÜˆu‹:˜Š?ØÜ$ UÓ+ˆÜ˜E ;Ó/ˆØˆ	Øò 	QˆEØ×ÑÔ4°U¸KÈÓOÕPð	Qä! )Ó,ò 	JˆIØ—<‘< 	Ð+HÓI‰Dð	Jä�v‰vØ;Ø(Øó
ˆð
 ˆr   r4   c                 óÒ  — |j                  d«      D ]Q  }|j                  d«      dkD  s)|j                  d«      dkD  s|j                  d«      dkD  sŒ@|j                  |d«      }ŒS |j                  d	d
«      }|j                  dd«      }|j                  dd«      }t        j                  dd|t        j
                  ¬«      }|j                  dd«      }|j                  dd«      }|S )aÚ  
        Takes a generated string and fixes tables/tabulars to make them match the markdown format needed.

        Args:
            generation (str): The generated text to be postprocessed.

        Returns:
            str: The postprocessed text.

        Example:

        ```python
        correct_tables("\begin{table} \begin{tabular}{l l} & \ \end{tabular} \end{table}")
        "\begin{table}
\begin{tabular}{l l} & \ \end{tabular}
\end{table}"
        ```
        r    z\begin{tabular}rl   z\multicolumné<   ú&i�  r%   z\begin{table} \begin{tabular}z\begin{table}
\begin{tabular}z\end{tabular} \end{table}z\end{tabular}
\end{table}z\end{table} Tabz\end{table}
Tabz(^.+)\\begin{tabz\1\n\\begin{tabr   z(\begin{tabular}{l l}  & \\ \end{tabular}z \begin{tabular}{}

\end{tabular})r(   r1   r   r   r   r   )r¢   r4   rg   s      r   Úcorrect_tablesz"NougatTokenizerFast.correct_tablesÅ  sò   € ð$ ×!Ñ! $Ó'ò 	7ˆAØ�w‰wÐ)Ó*¨RÒ/°1·7±7¸?Ó3KÈbÒ3PÐTU×T[ÑT[Ð\_ÓT`ÐcfÓTfØ'×/Ñ/°°2Ó6‘
ð	7ð
  ×'Ñ'Ð(IÐKmÓnˆ
Ø×'Ñ'Ð(EÐGeÓfˆ
Ø×'Ñ'Ð(:Ð<OÓPˆ
ä—V‘VÐ/Ð1CÀZÔWY×W[ÑW[Ô\ˆ
ð  ×'Ñ'Ð(SÐUWÓXˆ
à×'Ñ'Ð(NÐPRÓSˆ
ØÐr   Úfix_markdownc                 óº  — t        j                  dd|«      }|j                  «       }|j                  dd«      }t        j                  dd|t         j                  ¬«      }|j                  d«      }|d   j                  d	«      r`|d   j                  d	«      j                  d
«      r=t        |«      dkD  r/t        j                  d|d   z   «       dj                  |dd «      }t        |«      }| j                  |«      }t        j                  dd|t         j                  ¬«      }t        j                  dd|t         j                  ¬«      }t        j                  dd|«      }t        j                  dd|«      }t        j                  dd|«      }t        j                  dd|«      }t        j                  dd|«      }t        |«      }|j                  d«      r|dz  }t        j                   d|«      r|d
z  }n„|j                  d«      rd|z   }nm|j                  d«      d   j                  d«      r|dz   }nD	 |j                  d
«      d   }|t"        j$                  j&                  j'                  «       v r|d
z  }| j+                  |«      }|j                  dd«      }t        j                  d d|«      }t        j                  d!d|«      }t        j                  d"d|t         j                  ¬«      }t        j                  d#d|t         j                  ¬«      }t        j                  d$d|«      }|rt-        |«      S |S # t(        $ r |d
z  }Y ŒÕw xY w)%aÛ  
        Postprocess a single generated text. Regular expressions used here are taken directly from the Nougat article
        authors. These expressions are commented for clarity and tested end-to-end in most cases.

        Args:
            generation (str): The generated text to be postprocessed.
            fix_markdown (bool, optional): Whether to perform Markdown formatting fixes. Default is True.

        Returns:
            str: The postprocessed text.
        z(?:\n|^)#+ \d*\W? ?(.{100,})z\n\1z
* [leftmargin=*]
r    z(^#+ (?:[\d+\.]+|[ixv\.]+)?\s*(?:$|\n\s*)r%   r   rM   ú#r$   r#   z2Likely hallucinated title at the end of the page: Nz#^\* \[\d+\](\s?[A-W]\.+\s?){10,}.*$z^(\* \[\d+\])\[\](.*)$z\1\2z(^\w\n\n|\n\n\w$)z8([\s.,()])_([a-zA-Z0-9])__([a-zA-Z0-9]){1,3}_([\s.,:()])z\1\(\2_{\3}\)\4z$([\s.,\d])_([a-zA-Z0-9])_([\s.,\d;])z
\1\(\2\)\3z;(\nFootnote .*?:) (?:footnotetext|thanks):\W*(.*(?:\n\n|$))z\1 \2z$\[FOOTNOTE:.+?\](.*?)\[ENDFOOTNOTE\])r&   ú}z

z[A-Z0-9,;:]$)r®   z**z\begin)r®   ÚFigureÚTablez\begin{array}[]{z\begin{array}{z?\\begin{tabular}{([clr ]){2,}}\s*[& ]*\s*(\\\\)? \\end{tabular}z(\*\*S\. A\. B\.\*\*\n+){2,}z^#+( [\[\d\w])?$z^\.\s*$z\n{3,})r   r   r-   r   r   r(   ro   Úlstripr2   ÚloggerÚinfor3   r_   r§   rC   rP   r/   ÚnltkÚcorpusÚwordsÚLookupErrorr«   r   )r¢   r4   r¬   r5   Ú	last_words        r   Úpost_process_singlez'NougatTokenizerFast.post_process_singleè  s  € ô —V‘VØ+¨W°jó
ˆ
ð  ×%Ñ%Ó'ˆ
à×'Ñ'Ð(>ÀÓEˆ
ô —V‘VÐGÈÈZÔ_a×_cÑ_cÔdˆ
à× Ñ  Ó&ˆØ�‰9×Ñ Ô$¨¨r©×)9Ñ)9¸#Ó)>×)IÑ)IÈ#Ô)NÔSVÐW\ÓS]Ð`aÒSaÜ�K‰KÐLÈuÐUWÉyÑXÔYØŸ™ 5¨¨" :Ó.ˆJä)¨*Ó5ˆ
à×8Ñ8¸ÓDˆ
ä—V‘VÐBÀBÈ
ÔZ\×Z^ÑZ^Ô_ˆ
ä—V‘VÐ5°wÀ
ÔRT×RVÑRVÔWˆ
ä—V‘VÐ0°"°jÓAˆ
ä—V‘VØGØØó
ˆ
ô
 —V‘VÐCÀ]ÐT^Ó_ˆ
ä—V‘VØJØØó
ˆ
ô —V‘VÐCÀRÈÓTˆ
ä.¨zÓ:ˆ
à×Ñ˜zÔ*Ø˜&Ñ ˆJÜ�8‰8�O ZÔ0à˜#Ñ‰JØ×"Ñ"Ð#9Ô:Ø *Ñ,‰JØ×Ñ˜dÓ# BÑ'×2Ñ2Ð3KÔLØ# fÑ,‰Jð"Ø&×,Ñ,¨SÓ1°"Ñ5�	Ø¤§¡× 1Ñ 1× 7Ñ 7Ó 9Ñ9Ø #Ñ%�Jð ×(Ñ(¨Ó4ˆ
à×'Ñ'Ð(;Ð=NÓOˆ
ä—V‘VØNØØó
ˆ
ô —V‘VÐ;¸RÀÓLˆ
ä—V‘VÐ/°°ZÄrÇtÁtÔLˆ
ä—V‘V˜J¨¨J¼b¿d¹dÔCˆ
ä—V‘V˜I v¨zÓ:ˆ
ÙÜ& zÓ2Ð2àÐøô3 ò "à˜cÑ!’
ð"ús   ÉAM	 Í	MÍMÚnum_workersc                 ód  — t        | ddg«       t        |t        «      ro|�Lt        |t        «      r<t	        |«      5 }|j                  t        | j                  |¬«      |«      cddd«       S |D �cg c]  }| j                  ||¬«      ‘Œ c}S | j                  ||¬«      S # 1 sw Y   yxY wc c}w )aP  
        Postprocess a generated text or a list of generated texts.

        This function can be used to perform postprocessing on generated text, such as fixing Markdown formatting.

        Postprocessing is quite slow so it is recommended to use multiprocessing to speed up the process.

        Args:
            generation (Union[str, List[str]]):
                The generated text or a list of generated texts.
            fix_markdown (`bool`, *optional*, defaults to `True`):
                Whether to perform Markdown formatting fixes.
            num_workers (`int`, *optional*):
                Optional number of workers to pass to leverage multiprocessing (postprocessing several texts in
                parallel).

        Returns:
            Union[str, List[str]]: The postprocessed text or list of postprocessed texts.
        rµ   ÚlevenshteinN)r¬   )r   rd   r}   rO   r   Úmapr   rº   )r¢   r4   r¬   r»   Úprb   s         r   Úpost_process_generationz+NougatTokenizerFast.post_process_generationG  s³   € ô2 	˜$ ¨Ð 7Ô8ä�j¤$Ô'ØÐ&¬:°kÄ3Ô+GÜ˜+Ó&ð k¨!ØŸ5™5¤¨×)AÑ)AÐP\Ô!]Ð_iÓj÷kñ kð YcÖcÐST˜×0Ñ0°ÀÐ0ÕNÒcÐcà×+Ñ+¨JÀ\Ð+ÓRÐR÷kð küò ds   ¼'B!Á1B-Â!B*)NNFz<unk>z<s>z</s>z<pad>)T)TN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚVOCAB_FILES_NAMESÚvocab_files_namesÚmodel_input_namesÚslow_tokenizer_classr¡   re   r§   r«   Úboolrº   r   r   r   rO   rÀ   Ú__classcell__)r¤   s   @r   r•   r•   i  sÜ   ø„ ñðB *ÐØ$Ð&6Ð7ÐØÐð ØØ%*ØØØØõ%ð.°3ð ¸3ó ð<!¨ð !°ó !ñF]¨cð ]Àð ]ÐQTó ]ðD "Ø%)ñ	"Sà˜#˜t C™y˜.Ñ)ð"Sð ð"Sð ˜c‘]ð	"Sð
 
ˆs�D˜‘Iˆ~Ñ	÷"Sr   r•   )r   )é   ))rÄ   r   Ú	functoolsr   Úmultiprocessingr   Útypingr   r   r   Únumpyrm   Ú$transformers.tokenization_utils_baser   Ú$transformers.tokenization_utils_fastr	   Útransformers.utilsr
   Úutilsr   r   r   r   ÚLevenshteinr   rµ   Ú
get_loggerrÁ   r³   rÅ   re   r   rC   rI   rO   r_   rh   rz   r“   r•   Ú__all__rŸ   r   r   ú<module>r×      s  ðñó 
Ý Ý  ß (Ñ (ã å IÝ HÝ 1ç \Ó \ñ ÔÝ!áÔÛð 
ˆ×	Ñ	˜HÓ	%€ð ð ñ Ð ð &Ð'7Ð8Ð ð'˜cð ' có 'òT0#ñf ó ñ$A˜sð A¨Sð A¸#ó AòH	ò.;ðb>¸ó >ñB Ð,Ó-ôSÐ1ó Só .ðSðD !Ð
!�r   