
    qi                         d Z ddlmZmZmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ  ej                  e      Zddd	Z G d
 de      ZdgZy)z%Tokenization class for model PEGASUS.    )Regex	Tokenizerdecodersnormalizerspre_tokenizers
processors)Unigram   )TokenizersBackend)loggingzspiece.modelztokenizer.json)
vocab_filetokenizer_filec                   h     e Zd ZdZeZddgZeZ	 	 	 	 	 	 	 	 	 dde	e
ee	ef      z  dz  f fdZ xZS )PegasusTokenizera  
    Construct a PEGASUS tokenizer (backed by HuggingFace's *tokenizers* library). Based on
    [Unigram](https://huggingface.co/docs/tokenizers/python/latest/components.html?highlight=unigram#models).

    This tokenizer inherits from [`TokenizersBackend`] which contains most of the main methods. Users should
    refer to this superclass for more information regarding those methods.

    Args:
        vocab_file (`str`, *optional*):
            [SentencePiece](https://github.com/google/sentencepiece) file (generally has a *.spm* extension) that
            contains the vocabulary necessary to instantiate a tokenizer.
        pad_token (`str`, *optional*, defaults to `"<pad>"`):
            The token used for padding, for example when batching sequences of different lengths.
        eos_token (`str`, *optional*, defaults to `"</s>"`):
            The end of sequence token.

            <Tip>

            When building a sequence using special tokens, this is not the token that is used for the end of sequence.
            The token used is the `sep_token`.

            </Tip>

        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.
        mask_token (`str`, *optional*, defaults to `"<mask_2>"`):
            The token used for masking single token values. This is the token used when training this model with masked
            language modeling (MLM). This is the token that the PEGASUS encoder will try to predict during pretraining.
            It corresponds to *[MASK2]* in [PEGASUS: Pre-training with Extracted Gap-sentences for Abstractive
            Summarization](https://huggingface.co/papers/1912.08777).
        mask_token_sent (`str`, *optional*, defaults to `"<mask_1>"`):
            The token used for masking whole target sentences. This is the token used when training this model with gap
            sentences generation (GSG). This is the sentence that the PEGASUS decoder will try to predict during
            pretraining. It corresponds to *[MASK1]* in [PEGASUS: Pre-training with Extracted Gap-sentences for
            Abstractive Summarization](https://huggingface.co/papers/1912.08777).
        additional_special_tokens (`List[str]`, *optional*):
            Additional special tokens used by the tokenizer. If no additional_special_tokens are provided <mask_2> and
            <unk_2, ..., unk_102> are used as additional special tokens corresponding to the [original PEGASUS
            tokenizer](https://github.com/google-research/pegasus/blob/939830367bcf411193d2b5eca2f2f90f3f9260ca/pegasus/ops/pretrain_parsing_ops.cc#L66)
            that uses the tokens 2 - 104 only for pretraining
        offset (`int`, *optional*, defaults to 103):
            Offset for additional special tokens.
        vocab (`str` or `list[tuple[str, float]]`, *optional*):
            Custom vocabulary with `(token, score)` tuples. If not provided, a blank vocabulary is initialized.
    	input_idsattention_maskNvocabc
                 Z   |	| _         |2||gng }|t        d| j                         D cg c]  }d| d
 c}z  }|2t        |      dft        |      dft        |      dft        |      dfg}|| _        t	        t        || j                  j                  t        |      dfd                  | _        |Wt        j                  t        j                  |      t        j                  t        d      d      g      | j                  _        n`t        j                  t        j                  t        d	      d      t        j                  t        d      d      g      | j                  _        t        j                  d
dd      | j                  _        t#        j                  d
dd      | j                  _        t'        | P  d||||||	|d|
 t+        j,                  d| d| t        |      | j/                  t        |            fg      | j                  _        y c c}w )N   z<unk_>g           )r   unk_idz {2,} z\nu   ▁alwaysT)replacementprepend_schemesplit)	pad_token	eos_token	unk_token
mask_tokenmask_token_sentoffsetadditional_special_tokensz$A z$A $B )singlepairspecial_tokens )r#   rangestr_vocabr   r	   index
_tokenizerr   SequencePrecompiledReplacer   
normalizerr   	Metaspacepre_tokenizerr   decodersuper__init__r   TemplateProcessingconvert_tokens_to_idspost_processor)selfr   r   r   r    r!   r"   _spm_precompiled_charsmapr$   r#   kwargsi	__class__s               b/opt/pipecat/venv/lib/python3.12/site-packages/transformers/models/pegasus/tokenization_pegasus.pyr6   zPegasusTokenizer.__init__P   s
    $,=L=X(9^`%%a@U)V1E!A,)VV%=)nc*S^S,AC	NTWCX[^_i[jloZpqE#G%@Q@QSVW`SacfRgij@k$lm$0)4)=)=(()BC[EXEXY^_gYhjmEno*DOO& *5)=)=$$U5\379L9LUS[_^a9bc*DOO& )7(@(@Ucksw(x%"*"4"4W_gk"l 		
!+&?		
 		
 *4)F)F$)% ^T-G-GI-WXY*
&; *Ws   H()	Nz<pad>z</s>z<unk>z<mask_2>z<mask_1>NNg   )__name__
__module____qualname____doc__VOCAB_FILES_NAMESvocab_files_namesmodel_input_namesr	   modelr*   listtuplefloatr6   __classcell__)r>   s   @r?   r   r      si    -^ *$&67E 7;""&"&2
T%U
+,,t32
 2
    r   N)rD   
tokenizersr   r   r   r   r   r   tokenizers.modelsr	   tokenization_utils_tokenizersr   utilsr   
get_loggerrA   loggerrE   r   __all__r(   rM   r?   <module>rU      sS    , Z Z % >  
		H	%#1EUV f
( f
R 
rM   