ó
    ‰Ž¡jÞo  ã                   óö   • S SK r S SKrS SKJrJr  S SKrSSKJr  SSK	J
r
JrJr  SSKJrJrJrJr  \" 5       (       a
  S SKrSSKJr   " S	 S
\5      r " S S\
5      r\" \" SS9S5       " S S\5      5       r\rg)é    N)ÚAnyÚoverloadé   )ÚBasicTokenizer)ÚExplicitEnumÚadd_end_docstringsÚis_torch_availableé   )ÚArgumentHandlerÚChunkPipelineÚDatasetÚbuild_pipeline_init_args)Ú,MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMESc                   ó2   • \ rS rSrSrS\\\   -  4S jrSrg)Ú"TokenClassificationArgumentHandleré   z-
Handles arguments for token classification.
Úinputsc                 óh  • UR                  SS5      nUR                  S5      nUbA  [        U[        [        45      (       a&  [	        U5      S:”  a  [        U5      n[	        U5      nOf[        U[
        5      (       a  U/nSnOK[        b  [        U[        5      (       d  [        U[        R                  5      (       a  XS U4$ [        S5      eUR                  S5      nU(       aJ  [        U[        5      (       a  [        US   [        5      (       a  U/n[	        U5      U:w  a  [        S5      eXXd4$ )	NÚis_split_into_wordsFÚ	delimiterr   r
   zAt least one input is required.Úoffset_mappingz;offset_mapping should have the same batch size as the input)
ÚgetÚ
isinstanceÚlistÚtupleÚlenÚstrr   ÚtypesÚGeneratorTypeÚ
ValueError)Úselfr   Úkwargsr   r   Ú
batch_sizer   s          Ú¹C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\transformers/pipelines/token_classification.pyÚ__call__Ú+TokenClassificationArgumentHandler.__call__   s	  € Ø$Ÿj™jÐ)>ÀÓFÐØ—J‘J˜{Ó+ˆ	àÑ¤*¨V´d¼E°]×"CÑ"CÌÈFËÐVWËÜ˜&“\ˆFÜ˜V›‰JÜ˜¤×$Ñ$Ø�XˆFØ‰JÜÑ ¤Z°¼×%@Ñ%@ÄJÈvÔW\×WjÑWj×DkÑDkØ°°iÐ?Ð?äÐ>Ó?Ð?àŸ™Ð$4Ó5ˆÞÜ˜.¬$×/Ñ/´J¸~ÈaÑ?PÔRW×4XÑ4XØ"0Ð!1�Ü�>Ó" jÓ0Ü Ð!^Ó_Ð_Ø¨NÐEÐEó    © N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r%   Ú__static_attributes__r(   r'   r$   r   r      s   † ñðF˜s T¨#¡Y™÷ Fr'   r   c                   ó,   • \ rS rSrSrSrSrSrSrSr	Sr
g	)
ÚAggregationStrategyé3   zDAll the valid aggregation strategies for TokenClassificationPipelineÚnoneÚsimpleÚfirstÚaverageÚmaxr(   N)r)   r*   r+   r,   r-   ÚNONEÚSIMPLEÚFIRSTÚAVERAGEÚMAXr.   r(   r'   r$   r0   r0   3   s   † ÙNà€DØ€FØ€EØ€GØ
ƒCr'   r0   T)Úhas_tokenizeraÙ	  
        ignore_labels (`list[str]`, defaults to `["O"]`):
            A list of labels to ignore.
        stride (`int`, *optional*):
            If stride is provided, the pipeline is applied on all the text. The text is split into chunks of size
            model_max_length. Works only with fast tokenizers and `aggregation_strategy` different from `NONE`. The
            value of this argument defines the number of overlapping tokens between chunks. In other words, the model
            will shift forward by `tokenizer.model_max_length - stride` tokens each step.
        aggregation_strategy (`str`, *optional*, defaults to `"none"`):
            The strategy to fuse (or not) tokens based on the model prediction.

                - "none" : Will simply not do any aggregation and simply return raw results from the model
                - "simple" : Will attempt to group entities following the default schema. (A, B-TAG), (B, I-TAG), (C,
                  I-TAG), (D, B-TAG2) (E, B-TAG2) will end up being [{"word": ABC, "entity": "TAG"}, {"word": "D",
                  "entity": "TAG2"}, {"word": "E", "entity": "TAG2"}] Notice that two consecutive B tags will end up as
                  different entities. On word based languages, we might end up splitting words undesirably : Imagine
                  Microsoft being tagged as [{"word": "Micro", "entity": "ENTERPRISE"}, {"word": "soft", "entity":
                  "NAME"}]. Look for FIRST, MAX, AVERAGE for ways to mitigate that and disambiguate words (on languages
                  that support that meaning, which is basically tokens separated by a space). These mitigations will
                  only work on real words, "New york" might still be tagged with two different entities.
                - "first" : (works only on word based models) Will use the `SIMPLE` strategy except that words, cannot
                  end up with different tags. Words will simply use the tag of the first token of the word when there
                  is ambiguity.
                - "average" : (works only on word based models) Will use the `SIMPLE` strategy except that words,
                  cannot end up with different tags. scores will be averaged first across tokens, and then the maximum
                  label is applied.
                - "max" : (works only on word based models) Will use the `SIMPLE` strategy except that words, cannot
                  end up with different tags. Word entity will simply be the token with the maximum score.c                   ó  ^ • \ rS rSrSrSrSrSrSrSr	\
" 5       4U 4S jjr      S)S\S-  S	\\\\4      S-  S
\S\S-  S\S-  4
S jjr\S\S\S\\\\4      4S j5       r\S\\   S\S\\\\\4         4S j5       rS\\\   -  S\S\\\\4      \\\\\4         -  4U 4S jjrS*S jrS r\R2                  S4S jrS r  S+S\S\R:                  S\R:                  S	\\\\4      S-  S\R:                  S\S\\S-     S-  S\\\\4      S-  S\\   4S jjrS\\   S\S\\   4S  jrS!\\   S\S\4S" jr S!\\   S\S\\   4S# jr!S!\\   S\4S$ jr"S%\S\\\4   4S& jr#S!\\   S\\   4S' jr$S(r%U =r&$ ),ÚTokenClassificationPipelineé=   u	  
Named Entity Recognition pipeline using any `ModelForTokenClassification`. See the [named entity recognition
examples](../task_summary#named-entity-recognition) for more information.

Example:

```python
>>> from transformers import pipeline

>>> token_classifier = pipeline(model="Jean-Baptiste/camembert-ner", aggregation_strategy="simple")
>>> sentence = "Je m'appelle jean-baptiste et je vis Ã  montrÃ©al"
>>> tokens = token_classifier(sentence)
>>> tokens
[{'entity_group': 'PER', 'score': 0.9931, 'word': 'jean-baptiste', 'start': 12, 'end': 26}, {'entity_group': 'LOC', 'score': 0.998, 'word': 'montrÃ©al', 'start': 38, 'end': 47}]

>>> token = tokens[0]
>>> # Start and end provide an easy way to highlight words in the original text.
>>> sentence[token["start"] : token["end"]]
' jean-baptiste'

>>> # Some models use the same idea to do part of speech.
>>> syntaxer = pipeline(model="vblagoje/bert-english-uncased-finetuned-pos", aggregation_strategy="simple")
>>> syntaxer("My name is Sarah and I live in London")
[{'entity_group': 'PRON', 'score': 0.999, 'word': 'my', 'start': 0, 'end': 2}, {'entity_group': 'NOUN', 'score': 0.997, 'word': 'name', 'start': 3, 'end': 7}, {'entity_group': 'AUX', 'score': 0.994, 'word': 'is', 'start': 8, 'end': 10}, {'entity_group': 'PROPN', 'score': 0.999, 'word': 'sarah', 'start': 11, 'end': 16}, {'entity_group': 'CCONJ', 'score': 0.999, 'word': 'and', 'start': 17, 'end': 20}, {'entity_group': 'PRON', 'score': 0.999, 'word': 'i', 'start': 21, 'end': 22}, {'entity_group': 'VERB', 'score': 0.998, 'word': 'live', 'start': 23, 'end': 27}, {'entity_group': 'ADP', 'score': 0.999, 'word': 'in', 'start': 28, 'end': 30}, {'entity_group': 'PROPN', 'score': 0.999, 'word': 'london', 'start': 31, 'end': 37}]
```

Learn more about the basics of using a pipeline in the [pipeline tutorial](../pipeline_tutorial)

This token recognition pipeline can currently be loaded from [`pipeline`] using the following task identifier:
`"ner"` (for predicting the classes of tokens in a sequence: person, organisation, location or miscellaneous).

The models that this pipeline can use are models that have been fine-tuned on a token classification task. See the
up-to-date list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=token-classification).
Ú	sequencesFTc                 óx   >• [         TU ]  " S0 UD6  U R                  [        5        [	        SS9U l        Xl        g )NF)Údo_lower_caser(   )ÚsuperÚ__init__Úcheck_model_typer   r   Ú_basic_tokenizerÚ_args_parser)r!   Úargs_parserr"   Ú	__class__s      €r$   rD   Ú$TokenClassificationPipeline.__init__ˆ   s5   ø€ Ü‰ÒÑ"˜6Ò"à×ÑÔJÔKä .¸UÑ CˆÔØ'Õr'   NÚaggregation_strategyr   r   Ústrider   c                 óh  • 0 nXGS'   U(       a
  Uc  SOUUS'   Ub  X7S'   0 nUb‰  [        U[        5      (       a  [        UR                  5          nU[        R                  [        R
                  [        R                  1;   a&  U R                  R                  (       d  [        S5      eX(S'   Ub  XS'   Ubx  XPR                  R                  :¼  a  [        S5      eU[        R                  :X  a  [        S	U S
35      eU R                  R                  (       a  SSUS.n	X—S'   O[        S5      eU0 U4$ )Nr   Ú r   r   z{Slow tokenizers cannot handle subwords. Please set the `aggregation_strategy` option to `"simple"` or use a fast tokenizer.rK   Úignore_labelszl`stride` must be less than `tokenizer.model_max_length` (or even lower if the tokenizer adds special tokens)zI`stride` was provided to process all the text but `aggregation_strategy="z&"`, please select another one instead.T)Úreturn_overflowing_tokensÚpaddingrL   Útokenizer_paramszm`stride` was provided to process all the text but you're using a slow tokenizer. Please use a fast tokenizer.)r   r   r0   Úupperr9   r;   r:   Ú	tokenizerÚis_fastr    Úmodel_max_lengthr7   )
r!   rO   rK   r   r   rL   r   Úpreprocess_paramsÚpostprocess_paramsrR   s
             r$   Ú_sanitize_parametersÚ0TokenClassificationPipeline._sanitize_parameters�   so  € ð ÐØ3FÐ/Ñ0æØ4=Ñ4E©SÈ9Ð˜kÑ*àÑ%Ø2@Ð.Ñ/àÐØÑ+ÜÐ.´×4Ñ4Ü':Ð;O×;UÑ;UÓ;WÑ'XÐ$à$Ü'×-Ñ-Ô/B×/FÑ/FÔH[×HcÑHcÐdóeàŸ™×.×.ä ð>óð ð :NÐ5Ñ6ØÑ$Ø2?˜Ñ/ØÑØŸ™×8Ñ8Ó8Ü ð Cóð ð $Ô':×'?Ñ'?Ó?Ü ðØ,Ð-Ð-SðUóð ð
 —>‘>×)×)à59Ø#'Ø"(ñ(Ð$ð
 =MÐ&8Ò9ä$ð8óð ð ! "Ð&8Ð8Ð8r'   r   r"   Úreturnc                 ó   • g ©Nr(   ©r!   r   r"   s      r$   r%   Ú$TokenClassificationPipeline.__call__Ë   s   € ØLOr'   c                 ó   • g r]   r(   r^   s      r$   r%   r_   Î   s   € ØX[r'   c                 óØ   >• U R                   " U40 UD6u  p4pVXBS'   XbS'   U(       a)  [        S U 5       5      (       d  [        TU ]  " U/40 UD6$ U(       a  XRS'   [        TU ]  " U40 UD6$ )ak  
Classify each token of the text(s) given as inputs.

Args:
    inputs (`str` or `List[str]`):
        One or several texts (or one list of texts) for token classification. Can be pre-tokenized when
        `is_split_into_words=True`.

Return:
    A list or a list of list of `dict`: Each result comes as a list of dictionaries (one for each token in the
    corresponding input, or each entity if this pipeline was instantiated with an aggregation_strategy) with
    the following keys:

    - **word** (`str`) -- The token/word classified. This is obtained by decoding the selected tokens. If you
      want to have the exact string in the original sentence, use `start` and `end`.
    - **score** (`float`) -- The corresponding probability for `entity`.
    - **entity** (`str`) -- The entity predicted for that token/word (it is named *entity_group* when
      *aggregation_strategy* is not `"none"`.
    - **index** (`int`, only present when `aggregation_strategy="none"`) -- The index of the corresponding
      token in the sentence.
    - **start** (`int`, *optional*) -- The index of the start of the corresponding entity in the sentence. Only
      exists if the offsets are available within the tokenizer
    - **end** (`int`, *optional*) -- The index of the end of the corresponding entity in the sentence. Only
      exists if the offsets are available within the tokenizer
r   r   c              3   óB   #   • U  H  n[        U[        5      v •  M     g 7fr]   )r   r   )Ú.0Úinputs     r$   Ú	<genexpr>Ú7TokenClassificationPipeline.__call__.<locals>.<genexpr>ï   s   é € Ð*WÒPVÀu¬:°e¼T×+BÐ+BÒPVùs   ‚r   )rG   ÚallrC   r%   )r!   r   r"   Ú_inputsr   r   r   rI   s          €r$   r%   r_   Ñ   s€   ø€ ð6 CG×BSÒBSÐTZÑBeÐ^dÑBeÑ?ˆ nØ(;Ð$Ñ%Ø'ˆ{ÑÞ¤sÑ*WÑPVÓ*W×'WÑ'WÜ‘7Ò# V HÑ7°Ñ7Ð7ÞØ'5Ð#Ñ$ä‰wÒ Ñ1¨&Ñ1Ð1r'   c           	   +   ó  #   • UR                  S0 5      nU R                  R                  =(       a    U R                  R                  S:„  nS nUS   nU(       a‡  US   n[        U[        5      (       d  [        S5      eUn	UR                  U	5      n/ n[        U5      n
SnU	 H2  nUR                  X»[        U5      -   45        U[        U5      U
-   -  nM4     U	nSUS'   O"[        U[        5      (       d  [        S5      eUnU R                  " U4SUSU R                  R                  S	.UD6nU(       a&  U R                  R                  (       d  [        S
5      eUR                  SS 5        [        US   5      n[        U5       H{  nUR                  5        VVs0 s H  u  nnUUU   R                  S5      _M     nnnUb  UUS'   US:X  a  UOS US'   UUS-
  :H  US'   Ub  UR                  U5      US'   UUS'   Uv •  M}     g s  snnf 7f)NrR   r   r   r   zEWhen `is_split_into_words=True`, `sentence` must be a list of tokens.TzKWhen `is_split_into_words=False`, `sentence` must be an untokenized string.Úpt)Úreturn_tensorsÚ
truncationÚreturn_special_tokens_maskÚreturn_offsets_mappingz@is_split_into_words=True is only supported with fast tokenizers.Úoverflow_to_sample_mappingÚ	input_idsr   Úsentencer
   Úis_lastÚword_idsÚword_to_chars_map)ÚpoprT   rV   r   r   r    Újoinr   Úappendr   rU   ÚrangeÚitemsÚ	unsqueezers   )r!   rq   r   rW   rR   rl   rt   r   r   ÚwordsÚdelimiter_lenÚchar_offsetÚwordÚtext_to_tokenizer   Ú
num_chunksÚiÚkÚvÚmodel_inputss                       r$   Ú
preprocessÚ&TokenClassificationPipeline.preprocessö   s  é € Ø,×0Ñ0Ð1CÀRÓHÐØ—^‘^×4Ñ4×\¸¿¹×9XÑ9XÐ[\Ñ9\ˆ
à ÐØ/Ð0EÑFÐÞØ)¨+Ñ6ˆIÜ˜h¬×-Ñ-Ü Ð!hÓiÐiØˆEØ —~‘~ eÓ,ˆHà "ÐÜ 	›NˆMØˆKÛ�Ø!×(Ñ(¨+ÄSÈÃYÑ7NÐ)OÔPØœs 4›y¨=Ñ8Ñ8’ñ ð
  %ÐØ6:ÐÐ2Ò3ä˜h¬×,Ñ,Ü Ð!nÓoÐoØ'Ðà—’Øð
àØ!Ø'+Ø#'§>¡>×#9Ñ#9ñ
ð ñ
ˆö  t§~¡~×'=×'=ÜÐ_Ó`Ð`à�
‰
Ð/°Ô6Ü˜ Ñ,Ó-ˆ
ä�zÖ"ˆAØ=C¿\¹\¼^ÔLº^±T°Q¸˜A˜q ™tŸ~™~¨aÓ0Ò0¹^ˆLÑLØÑ)Ø1?�Ð-Ñ.à34¸³6¡x¸tˆL˜Ñ$Ø&'¨:¸©>Ñ&9ˆL˜Ñ#Ø Ñ,Ø+1¯?©?¸1Ó+=�˜ZÑ(Ø4E�Ð0Ñ1àÔò #ùÛLùs   ‚FHÆ"HÆ>AHc                 óN  • UR                  S5      nUR                  SS 5      nUR                  S5      nUR                  S5      nUR                  SS 5      nUR                  SS 5      nU R                  " S
0 UD6n[        U[        5      (       a  US   OUS   n	U	UUUUUUS	.UE$ )NÚspecial_tokens_maskr   rq   rr   rs   rt   Úlogitsr   )r‰   rˆ   r   rq   rr   rs   rt   r(   )ru   Úmodelr   Údict)
r!   r„   rˆ   r   rq   rr   rs   rt   Úoutputr‰   s
             r$   Ú_forwardÚ$TokenClassificationPipeline._forward.  sÅ   € à*×.Ñ.Ð/DÓEÐØ%×)Ñ)Ð*:¸DÓAˆØ×#Ñ# JÓ/ˆØ×"Ñ" 9Ó-ˆØ×#Ñ# J°Ó5ˆØ(×,Ñ,Ð-@À$ÓGÐà—’Ñ+˜lÑ+ˆÜ%/°¼×%=Ñ%=�˜Ò!À6È!Á9ˆð Ø#6Ø,Ø ØØ Ø!2ñ	
ð ð	
ð 		
r'   c                 ó¢  • Uc  S/n/ nUS   R                  S5      nU GH„  nUS   S   R                  [        R                  [        R                  4;   a4  US   S   R                  [        R                  5      R                  5       nOUS   S   R                  5       nUS   S   nUS   S   n	US   b  US   S   OS n
US   S   R                  5       nUR                  S	5      n[        R                  " US
SS9n[        R                  " X}-
  5      nXîR                  S
SS9-  nU R                  UU	UU
UUUUS9nU R                  UU5      nU Vs/ s H5  nUR                  SS 5      U;  d  M  UR                  SS 5      U;  d  M3  UPM7     nnUR                  U5        GM‡     [        U5      nUS:”  a  U R!                  U5      nU$ s  snf )NÚOr   rt   r‰   rq   rp   r   rˆ   rs   éÿÿÿÿT)ÚaxisÚkeepdims)rs   rt   ÚentityÚentity_groupr
   )r   ÚdtypeÚtorchÚbfloat16Úfloat16ÚtoÚfloat32ÚnumpyÚnpr6   ÚexpÚsumÚgather_pre_entitiesÚ	aggregateÚextendr   Úaggregate_overlapping_entities)r!   Úall_outputsrK   rO   Úall_entitiesrt   Úmodel_outputsr‰   rq   rp   r   rˆ   rs   ÚmaxesÚshifted_expÚscoresÚpre_entitiesÚgrouped_entitiesr”   Úentitiesr€   s                        r$   ÚpostprocessÚ'TokenClassificationPipeline.postprocessE  s  € ØÑ Ø ˜EˆMØˆð (¨™N×.Ñ.Ð/BÓCÐä(ˆMØ˜XÑ& qÑ)×/Ñ/´E·N±NÄEÇMÁMÐ3RÓRØ& xÑ0°Ñ3×6Ñ6´u·}±}ÓE×KÑKÓM‘à& xÑ0°Ñ3×9Ñ9Ó;�à" 1‘~ jÑ1ˆHØ% kÑ2°1Ñ5ˆIà6CÐDTÑ6UÑ6a�Ð.Ñ/°Ò2Ðgkð ð #0Ð0EÑ"FÀqÑ"I×"OÑ"OÓ"QÐØ$×(Ñ(¨Ó4ˆHä—F’F˜6¨°TÑ:ˆEÜŸ&š& ¡Ó0ˆKØ §?¡?¸ÀT ?Ð#JÑJˆFà×3Ñ3ØØØØØ#Ø$Ø!Ø"3ð 4ð 	ˆLð  $Ÿ~™~¨lÐ<PÓQÐñ /óâ.�FØ—:‘:˜h¨Ó-°]ÑBó ð —J‘J˜~¨tÓ4¸MÑI÷ Ù.ð ð ð ×Ñ ×)ñI )ôJ ˜Ó%ˆ
Ø˜‹>Ø×>Ñ>¸|ÓLˆLØÐùòs   ÅGÅ2GÆ
Gc                 ó@  • [        U5      S:X  a  U$ [        US S9n/ nUS   nU Hc  nUS   US   s=::  a	  US   :  a7  O  O4US   US   -
  nUS   US   -
  nXV:”  d  XV:X  a  US   US   :”  a  UnML  MN  MP  UR                  U5        UnMe     UR                  U5        U$ )Nr   c                 ó   • U S   $ )NÚstartr(   )Úxs    r$   Ú<lambda>ÚLTokenClassificationPipeline.aggregate_overlapping_entities.<locals>.<lambda>z  s   € °!°G²*r'   ©Úkeyr±   ÚendÚscore)r   Úsortedrw   )r!   r¬   Úaggregated_entitiesÚprevious_entityr”   Úcurrent_lengthÚprevious_lengths          r$   r£   Ú:TokenClassificationPipeline.aggregate_overlapping_entitiesw  sÒ   € Üˆx‹=˜AÓØˆOÜ˜(Ñ(<Ñ=ˆØ ÐØ" 1™+ˆÛˆFØ˜wÑ'¨6°'©?ÕS¸_ÈUÑ=SÖSØ!'¨¡°¸±Ñ!@�Ø"1°%Ñ"8¸?È7Ñ;SÑ"S�à"Ó4Ø%Ó8Ø˜w™¨/¸'Ñ*BÓBà&,’Oñ Cñ 9ð
 $×*Ñ*¨?Ô;Ø"(’ñ ð 	×"Ñ" ?Ô3Ø"Ð"r'   rq   rp   r©   rˆ   rs   rt   c	                 ó„  • / n	[        U5       GH­  u  p«XZ   (       a  M  U R                  R                  [        X*   5      5      nUGbR  XJ   u  pÞUb  Ub  Xz   nUb  X�   u  nnUU-  nUU-  n[	        U[        5      (       d   UR                  5       nUR                  5       nXU n[        U R                  SS5      (       aH  [        U R                  R                  R                  SS5      (       a  [        U5      [        U5      :g  nOgU[        R                  [        R                  [        R                  1;   a  [        R                  " S[         5        US:„  =(       a    SXS-
  US-    ;  n[        X*   5      U R                  R"                  :X  a  UnSnOSnSnSnUUUUU
US	.nU	R%                  U5        GM°     U	$ )
zTFuse various numpy arrays into dicts with all the information needed for aggregationNÚ
_tokenizerÚcontinuing_subword_prefixz?Tokenizer does not support real words, using fallback heuristicr   rN   r
   F)r~   r©   r±   r·   ÚindexÚ
is_subword)Ú	enumeraterT   Úconvert_ids_to_tokensÚintr   ÚitemÚgetattrrÀ   rŠ   r   r0   r9   r:   r;   ÚwarningsÚwarnÚUserWarningÚunk_token_idrw   )r!   rq   rp   r©   r   rˆ   rK   rs   rt   rª   ÚidxÚtoken_scoresr~   Ú	start_indÚend_indÚ
word_indexÚ
start_charÚ_Úword_refrÃ   Ú
pre_entitys                        r$   r    Ú/TokenClassificationPipeline.gather_pre_entities�  sÓ  € ð ˆÜ!*¨6×!2ÑˆCà"×'Ùà—>‘>×7Ñ7¼¸I¹NÓ8KÓLˆDØÒ)Ø%3Ñ%8Ñ"�	ð Ñ'Ð,=Ñ,IØ!)¡�JØ!Ñ-Ø(9Ñ(E™˜
 AØ! ZÑ/˜	Ø :Ñ-˜ä! )¬S×1Ñ1Ø )§¡Ó 0�IØ%Ÿl™l›n�GØ#¨gÐ6�Ü˜4Ÿ>™>¨<¸×>Ñ>Ä7Ø—N‘N×-Ñ-×3Ñ3Ð5PÐRV÷Dñ Dô
 "% T£¬c°(«mÑ!;‘Jð ,Ü+×1Ñ1Ü+×3Ñ3Ü+×/Ñ/ð0ó ô
 !ŸšØ]Ü'ôð "+¨Q¡×!e°3¸hÐSTÁ}ÐW`ÐcdÑWdÐ>eÑ3e�Jä�y‘~Ó&¨$¯.©.×*EÑ*EÓEØ#�DØ!&�Jøà �	Ø�Ø"�
ð Ø&Ø"ØØØ(ñˆJð ×Ñ 
×+ñq "3ðr Ðr'   rª   c                 ó–  • U[         R                  [         R                  1;   an  / nU He  nUS   R                  5       nUS   U   nU R                  R
                  R                  U   UUS   US   US   US   S.nUR                  U5        Mg     OU R                  X5      nU[         R                  :X  a  U$ U R                  U5      $ )Nr©   rÂ   r~   r±   r·   )r”   r¸   rÂ   r~   r±   r·   )
r0   r7   r8   ÚargmaxrŠ   ÚconfigÚid2labelrw   Úaggregate_wordsÚgroup_entities)r!   rª   rK   r¬   rÕ   Ú
entity_idxr¸   r”   s           r$   r¡   Ú%TokenClassificationPipeline.aggregateÕ  sÕ   € ØÔ$7×$<Ñ$<Ô>Q×>XÑ>XÐ#YÓYØˆHÛ*�
Ø'¨Ñ1×8Ñ8Ó:�
Ø" 8Ñ,¨ZÑ8�à"Ÿj™j×/Ñ/×8Ñ8¸ÑDØ"Ø'¨Ñ0Ø& vÑ.Ø'¨Ñ0Ø% eÑ,ñ�ð —‘ Ö'ò +ð ×+Ñ+¨LÓOˆHàÔ#6×#;Ñ#;Ó;ØˆOØ×"Ñ" 8Ó,Ð,r'   r¬   c                 ó(  • U R                   R                  U Vs/ s H  o3S   PM	     sn5      nU[        R                  :X  a@  US   S   nUR	                  5       nXV   nU R
                  R                  R                  U   nOñU[        R                  :X  aH  [        US S9nUS   nUR	                  5       nXV   nU R
                  R                  R                  U   nO•U[        R                  :X  av  [        R                  " U Vs/ s H  o3S   PM	     sn5      n[        R                  " USS9n	U	R	                  5       n
U R
                  R                  R                  U
   nXš   nO[        S5      eUUUUS   S   US	   S
   S.nU$ s  snf s  snf )Nr~   r   r©   c                 ó(   • U S   R                  5       $ )Nr©   )r6   )r”   s    r$   r³   Ú<TokenClassificationPipeline.aggregate_word.<locals>.<lambda>ó  s   € ¸&ÀÑ:J×:NÑ:NÔ:Pr'   rµ   )r’   zInvalid aggregation_strategyr±   r‘   r·   )r”   r¸   r~   r±   r·   )rT   Úconvert_tokens_to_stringr0   r9   rØ   rŠ   rÙ   rÚ   r;   r6   r:   r�   ÚstackÚnanmeanr    )r!   r¬   rK   r”   r~   r©   rÍ   r¸   Ú
max_entityÚaverage_scoresrÝ   Ú
new_entitys               r$   Úaggregate_wordÚ*TokenClassificationPipeline.aggregate_wordë  s|  € Ø�~‰~×6Ñ6ÑU]Ó7^ÒU]È6¸v¼ÑU]Ñ7^Ó_ˆØÔ#6×#<Ñ#<Ó<Ø˜a‘[ Ñ*ˆFØ—-‘-“/ˆCØ‘KˆEØ—Z‘Z×&Ñ&×/Ñ/°Ñ4‰FØ!Ô%8×%<Ñ%<Ó<Ü˜XÑ+PÑQˆJØ Ñ)ˆFØ—-‘-“/ˆCØ‘KˆEØ—Z‘Z×&Ñ&×/Ñ/°Ñ4‰FØ!Ô%8×%@Ñ%@Ó@Ü—X’X¹hÓGºh°F hÔ/¹hÑGÓHˆFÜŸZšZ¨°QÑ7ˆNØ'×.Ñ.Ó0ˆJØ—Z‘Z×&Ñ&×/Ñ/°
Ñ;ˆFØ"Ñ.‰EäÐ;Ó<Ð<àØØØ˜a‘[ Ñ)Ø˜B‘< Ñ&ñ
ˆ
ð Ðùò7 8_ùò Hs   šF
ÄFc                 óT  • U[         R                  [         R                  1;   a  [        S5      e/ nSnU HK  nUc  U/nM  US   (       a  UR	                  U5        M(  UR	                  U R                  XB5      5        U/nMM     Ub   UR	                  U R                  XB5      5        U$ )zÚ
Override tokens from a given word that disagree to force agreement on word boundaries.

Example: micro|soft| com|pany| B-ENT I-NAME I-ENT I-ENT will be rewritten with first strategy as microsoft|
company| B-ENT I-ENT
z;NONE and SIMPLE strategies are invalid for word aggregationNrÃ   )r0   r7   r8   r    rw   rè   )r!   r¬   rK   Úword_entitiesÚ
word_groupr”   s         r$   rÛ   Ú+TokenClassificationPipeline.aggregate_words	  s¯   € ð  Ü×$Ñ$Ü×&Ñ&ð$
ó 
ô ÐZÓ[Ð[àˆØˆ
ÛˆFØÑ!Ø$˜X’
Ø˜×%Ø×!Ñ! &Ö)à×$Ñ$ T×%8Ñ%8¸Ó%ZÔ[Ø$˜X’
ñ ð Ñ!Ø× Ñ  ×!4Ñ!4°ZÓ!VÔWØÐr'   c                 óL  • US   S   R                  SS5      S   n[        R                  " U Vs/ s H  o"S   PM	     sn5      nU Vs/ s H  o"S   PM	     nnW[        R                  " U5      U R                  R                  U5      US   S   US   S	   S
.nU$ s  snf s  snf )zŠ
Group together the adjacent tokens with the same entity predicted.

Args:
    entities (`dict`): The entities predicted by the pipeline.
r   r”   Ú-r
   r‘   r¸   r~   r±   r·   )r•   r¸   r~   r±   r·   )Úsplitr�   rä   ÚmeanrT   râ   )r!   r¬   r”   r©   Útokensr•   s         r$   Úgroup_sub_entitiesÚ.TokenClassificationPipeline.group_sub_entities%  s«   € ð ˜!‘˜XÑ&×,Ñ,¨S°!Ó4°RÑ8ˆÜ—’¹8ÓDº8° Gœ_¹8ÑDÓEˆÙ/7Ó8ªx V˜”.©xˆÐ8ð #Ü—W’W˜V“_Ø—N‘N×;Ñ;¸FÓCØ˜a‘[ Ñ)Ø˜B‘< Ñ&ñ
ˆð Ðùò EùÚ8s   °BÁ	B!Úentity_namec                 ó�   • UR                  S5      (       a
  SnUSS  nX#4$ UR                  S5      (       a
  SnUSS  nX#4$ SnUnX#4$ )NzB-ÚBr   zI-ÚI)Ú
startswith)r!   rõ   ÚbiÚtags       r$   Úget_tagÚ#TokenClassificationPipeline.get_tag:  sk   € Ø×!Ñ! $×'Ñ'ØˆBØ˜a˜b�/ˆCð ˆwˆð ×#Ñ# D×)Ñ)ØˆBØ˜a˜b�/ˆCð ˆwˆð ˆBØˆCØˆwˆr'   c                 ó‚  • / n/ nU H�  nU(       d  UR                  U5        M  U R                  US   5      u  pVU R                  US   S   5      u  pxXh:X  a  US:w  a  UR                  U5        Mj  UR                  U R                  U5      5        U/nM�     U(       a   UR                  U R                  U5      5        U$ )z“
Find and group together the adjacent tokens with the same entity predicted.

Args:
    entities (`dict`): The entities predicted by the pipeline.
r”   r‘   r÷   )rw   rü   ró   )	r!   r¬   Úentity_groupsÚentity_group_disaggr”   rú   rû   Úlast_biÚlast_tags	            r$   rÜ   Ú*TokenClassificationPipeline.group_entitiesH  sÂ   € ð ˆØ ÐãˆFÞ&Ø#×*Ñ*¨6Ô2Ùð —l‘l 6¨(Ñ#3Ó4‰GˆBØ $§¡Ð-@ÀÑ-DÀXÑ-NÓ OÑˆGà‹ 2¨£9à#×*Ñ*¨6Ö2ð ×$Ñ$ T×%<Ñ%<Ð=PÓ%QÔRØ'- hÒ#ñ' ö( à× Ñ  ×!8Ñ!8Ð9LÓ!MÔNàÐr'   )rG   rF   )NNNFNNr]   )NN)'r)   r*   r+   r,   r-   Údefault_input_namesÚ_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr   rD   r0   r   r   rÆ   Úboolr   rY   r   r   r‹   r%   r…   r�   r7   r­   r£   r�   Úndarrayr    r¡   rè   rÛ   ró   rü   rÜ   r.   Ú__classcell__)rI   s   @r$   r>   r>   =   sâ  ø† ñ@"ðH &Ðà€OØ!ÐØ#ÐØ€Oá#EÓ#G÷ (ð Ø;?Ø7;Ø$)Ø!Ø $ñ99ð 2°DÑ8ð99ð ˜U 3¨ 8™_Ñ-°Ñ4ð	99ð
 "ð99ð �d‘
ð99ð ˜‘:õ99ðv ØO˜sÐO¨cÐO°d¸4ÀÀSÀ¹>Ñ6JÓOó ØOàØ[˜t C™yÐ[°CÐ[¸DÀÀdÈ3ÐPSÈ8ÁnÑAUÑ<VÓ[ó Ø[ð#2˜s T¨#¡Y™ð #2¸#ð #2À$ÀtÈCÐQTÈHÁ~ÑBVÐY]Ð^bÐcgÐhkÐmpÐhpÑcqÑ^rÑYsÑBs÷ #2ôJ6òp
ð. =P×<TÑ<TÐdhô 0òd#ð< -1Ø:>ñFàðFð —:‘:ðFð —
‘
ð	Fð
 ˜U 3¨ 8™_Ñ-°Ñ4ðFð  ŸZ™ZðFð 2ðFð �s˜T‘zÑ" TÑ)ðFð    c¨3 h¡Ñ0°4Ñ7ðFð 
ˆd‰õFðP- d¨4¡jð -ÐH[ð -Ð`dÐeiÑ`jô -ð, t¨D¡zð ÐI\ð Ðaeô ð<¨¨T©
ð ÐJ]ð ÐbfÐgkÑblô ð8¨4°©:ð ¸$ô ð* 3ð ¨5°°c°©?ô ð# t¨D¡zð #°d¸4±j÷ #ò #r'   r>   )r   rÉ   Útypingr   r   rœ   r�   Ú$models.bert.tokenization_bert_legacyr   Úutilsr   r   r	   Úbaser   r   r   r   r—   Úmodels.auto.modeling_autor   r   r0   r>   ÚNerPipeliner(   r'   r$   Ú<module>r     s‹   ðÛ Û ß  ã å A÷ñ ÷
 TÓ Sñ ×ÑÛåXôF¨ô Fô:˜,ô ñ Ù¨4Ñ0ðnóô>O -ó Oó?ð>Oðd *�r'   