§
    \zni;h  ã                   ó6  — d dl Z d dlZd dlmZmZmZmZ d dlZddl	m
Z
 ddlmZmZmZmZ ddlmZmZmZmZ  e¦   «         r
d dlZddlmZ  e¦   «         rdd	lmZ  G d
„ de¦  «        Z G d„ de¦  «        Z eed¦  «         G d„ de¦  «        ¦   «         ZeZdS )é    N)ÚListÚOptionalÚTupleÚUnioné   )ÚBasicTokenizer)ÚExplicitEnumÚadd_end_docstringsÚis_tf_availableÚis_torch_availableé   )ÚPIPELINE_INIT_ARGSÚArgumentHandlerÚChunkPipelineÚDataset)Ú/TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES)Ú,MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMESc                   ó:   — e Zd ZdZdeeee         f         fd„ZdS )Ú"TokenClassificationArgumentHandlerz5
    Handles arguments for token classification.
    Úinputsc                 óJ  — |�Nt          |t          t          f¦  «        r2t          |¦  «        dk    rt          |¦  «        }t          |¦  «        }ndt          |t          ¦  «        r|g}d}nIt
          �t          |t
          ¦  «        st          |t          j        ¦  «        r|d fS t          d¦  «        ‚| 	                    d¦  «        }|rUt          |t          ¦  «        rt          |d         t          ¦  «        r|g}t          |¦  «        |k    rt          d¦  «        ‚||fS )Nr   r   zAt least one input is required.Úoffset_mappingz;offset_mapping should have the same batch size as the input)
Ú
isinstanceÚlistÚtupleÚlenÚstrr   ÚtypesÚGeneratorTypeÚ
ValueErrorÚget)Úselfr   ÚkwargsÚ
batch_sizer   s        ú‹/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/transformers/pipelines/token_classification.pyÚ__call__z+TokenClassificationArgumentHandler.__call__   s  € ØÐ¥*¨Vµd½E°]Ñ"CÔ"CÐÍÈFÉÌÐVWÊÈÝ˜&‘\”\ˆFÝ˜V™œˆJˆJÝ˜¥Ñ$Ô$ð 	@Ø�XˆFØˆJˆJÝÐ ¥Z°½Ñ%@Ô%@Ð ÅJÈvÕW\ÔWjÑDkÔDkÐ Ø˜4�<ÐåÐ>Ñ?Ô?Ð?àŸšÐ$4Ñ5Ô5ˆØð 	`Ý˜.­$Ñ/Ô/ð 2µJ¸~ÈaÔ?PÕRWÑ4XÔ4Xð 2Ø"0Ð!1�Ý�>Ñ"Ô" jÒ0Ð0Ý Ð!^Ñ_Ô_Ð_Ø�~Ð%Ð%ó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r&   © r'   r%   r   r      sF   € € € € € ðð ð&˜u S¨$¨s¬) ^Ô4ð &ð &ð &ð &ð &ð &r'   r   c                   ó&   — e Zd ZdZdZdZdZdZdZdS )ÚAggregationStrategyzDAll the valid aggregation strategies for TokenClassificationPipelineÚnoneÚsimpleÚfirstÚaverageÚmaxN)	r(   r)   r*   r+   ÚNONEÚSIMPLEÚFIRSTÚAVERAGEÚMAXr,   r'   r%   r.   r.   3   s-   € € € € € ØNÐNà€DØ€FØ€EØ€GØ
€C€C€Cr'   r.   aÒ
  
        ignore_labels (`List[str]`, defaults to `["O"]`):
            A list of labels to ignore.
        grouped_entities (`bool`, *optional*, defaults to `False`):
            DEPRECATED, use `aggregation_strategy` instead. Whether or not to group the tokens corresponding to the
            same entity together in the predictions or not.
        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                   ód  ‡ — e Zd ZdZdZ e¦   «         fˆ fd„	Z	 	 	 	 	 	 d dee         dee         dee	         dee
eeef                           d	ee         f
d
„Zdeee
e         f         fˆ fd„Zd!d„Zd„ Ze	j        dfd„Zd„ Zdedej        dej        dee
eeef                           dej        de	de
e         fd„Zde
e         de	de
e         fd„Zde
e         de	defd„Zde
e         de	de
e         fd„Zde
e         defd„Zdedeeef         fd„Zde
e         de
e         fd„Zˆ xZ S )"ÚTokenClassificationPipelineuv	  
    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).
    Ú	sequencesc                 óÊ   •—  t          ¦   «         j        |i |¤Ž |                      | j        dk    rt          nt
          ¦  «         t          d¬¦  «        | _        || _        d S )NÚtfF)Údo_lower_case)	ÚsuperÚ__init__Úcheck_model_typeÚ	frameworkr   r   r   Ú_basic_tokenizerÚ_args_parser)r"   Úargs_parserÚargsr#   Ú	__class__s       €r%   r@   z$TokenClassificationPipeline.__init__‡   sr   ø€ Ø�‰ŒÔ˜$Ð) &Ð)Ð)Ð)Ø×ÒàŒ~ Ò%Ð%õ <Ð;å=ñ	
ô 	
ð 	
õ !/¸UÐ CÑ CÔ CˆÔØ'ˆÔÐÐr'   NÚgrouped_entitiesÚignore_subwordsÚaggregation_strategyr   Ústridec                 óÈ  — i }|�||d<   i }|€|�b|r|rt           j        }n|r|st           j        }nt           j        }|�t	          j        d|› d�¦  «         |�t	          j        d|› d�¦  «         |�yt          |t          ¦  «        rt           |                     ¦   «                  }|t           j        t           j	        t           j
        hv r| j        j        st          d¦  «        ‚||d<   |�||d<   |�i|| j        j        k    rt          d¦  «        ‚|t           j        k    rt          d	|› d
�¦  «        ‚| j        j        rdd|dœ}	|	|d<   nt          d¦  «        ‚|i |fS )Nr   zl`grouped_entities` is deprecated and will be removed in version v5.0.0, defaulted to `aggregation_strategy="z"` instead.zk`ignore_subwords` is deprecated and will be removed in version v5.0.0, defaulted to `aggregation_strategy="z{Slow tokenizers cannot handle subwords. Please set the `aggregation_strategy` option to `"simple"` or use a fast tokenizer.rJ   Ú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ÚpaddingrK   Útokenizer_paramszm`stride` was provided to process all the text but you're using a slow tokenizer. Please use a fast tokenizer.)r.   r6   r5   r4   ÚwarningsÚwarnr   r   Úupperr8   r7   Ú	tokenizerÚis_fastr    Úmodel_max_length)
r"   rM   rH   rI   rJ   r   rK   Úpreprocess_paramsÚpostprocess_paramsrP   s
             r%   Ú_sanitize_parametersz0TokenClassificationPipeline._sanitize_parameters’   sE  € ð ÐØÐ%Ø2@ÐÐ.Ñ/àÐØÐ'¨?Ð+FØð @ Oð @Ý':Ô'@Ð$Ð$Ø!ð @¨/ð @Ý':Ô'AÐ$Ð$å':Ô'?Ð$àÐ+Ý”ðQØ/CðQð Qð Qñô ð ð Ð*Ý”ðQØ/CðQð Qð Qñô ð ð
  Ð+ÝÐ.µÑ4Ô4ð YÝ':Ð;O×;UÒ;UÑ;WÔ;WÔ'XÐ$à$Ý'Ô-Õ/BÔ/FÕH[ÔHcÐdðeð eàœÔ.ðeõ !ð>ñô ð ð :NÐÐ5Ñ6ØÐ$Ø2?Ð˜Ñ/ØÐØ˜œÔ8Ò8Ð8Ý ð Cñô ð ð $Õ':Ô'?Ò?Ð?Ý ðUØ,ðUð Uð Uñô ð ð
 ”>Ô)ð à59Ø#'Ø"(ð(ð (Ð$ð
 =MÐ%Ð&8Ñ9Ð9å$ð8ñô ð ð ! "Ð&8Ð8Ð8r'   r   c                 óh   •—  | j         |fi |¤Ž\  }}|r||d<    t          ¦   «         j        |fi |¤ŽS )aÍ  
        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.

        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   )rD   r?   r&   )r"   r   r#   Ú_inputsr   rG   s        €r%   r&   z$TokenClassificationPipeline.__call__Û   sV   ø€ ð4 #4 $Ô"3°FÐ"EÐ"E¸fÐ"EÐ"EÑˆ�Øð 	6Ø'5ˆFÐ#Ñ$à�u‰wŒwÔ Ð1Ð1¨&Ð1Ð1Ð1r'   c              +   ó  ‡	K  — |                      di ¦  «        }| j        j        r| j        j        dk    rdnd} | j        |f| j        |d| j        j        dœ|¤Ž}|                      dd ¦  «         t          |d         ¦  «        }t          |¦  «        D ]rŠ	| j        dk    r!ˆ	fd	„|                     ¦   «         D ¦   «         }n ˆ	fd
„|                     ¦   «         D ¦   «         }|�||d<   ‰	dk    r|nd |d<   ‰	|dz
  k    |d<   |V — Œsd S )NrP   r   TF)Úreturn_tensorsÚ
truncationÚreturn_special_tokens_maskÚreturn_offsets_mappingÚoverflow_to_sample_mappingÚ	input_idsr=   c                 óN   •— i | ]!\  }}|t          j        |‰         d ¦  «        “Œ"S ©r   )r=   Úexpand_dims©Ú.0ÚkÚvÚis      €r%   ú
<dictcomp>z:TokenClassificationPipeline.preprocess.<locals>.<dictcomp>  s/   ø€ ÐVÐVÐV¹t¸qÀ! ¥2¤>°!°A´$¸Ñ#:Ô#:ÐVÐVÐVr'   c                 óN   •— i | ]!\  }}||‰                               d ¦  «        “Œ"S rd   )Ú	unsqueezerf   s      €r%   rk   z:TokenClassificationPipeline.preprocess.<locals>.<dictcomp>  s/   ø€ ÐPÐPÐP¹¸¸A  1 Q¤4§>¢>°!Ñ#4Ô#4ÐPÐPÐPr'   r   Úsentencer   Úis_last)ÚpoprT   rV   rB   rU   r   ÚrangeÚitems)
r"   rn   r   rW   rP   r^   r   Ú
num_chunksÚmodel_inputsrj   s
            @r%   Ú
preprocessz&TokenClassificationPipeline.preprocessû   sc  øè è € Ø,×0Ò0Ð1CÀRÑHÔHÐØ!œ^Ô<ÐoÀÄÔA`ÐcdÒAdÐAd�T�TÐjoˆ
Ø�”Øð
àœ>Ø!Ø'+Ø#'¤>Ô#9ð
ð 
ð ð
ð 
ˆð 	�
Š
Ð/°Ñ6Ô6Ð6Ý˜ Ô,Ñ-Ô-ˆ
å�zÑ"Ô"ð 
	ð 
	ˆAØŒ~ Ò%Ð%ØVÐVÐVÐVÀvÇ|Â|Á~Ä~ÐVÑVÔV��àPÐPÐPÐPÀÇÂÁÄÐPÑPÔP�ØÐ)Ø1?�Ð-Ñ.Ø34¸²6°6 x x¸tˆL˜Ñ$Ø&'¨:¸©>Ò&9ˆL˜Ñ#àÐÐÐÐð
	ð 
	r'   c                 ób  — |                      d¦  «        }|                      dd ¦  «        }|                      d¦  «        }|                      d¦  «        }| j        dk    r | j        d	i |¤Žd         }n2 | j        d	i |¤Ž}t          |t          ¦  «        r|d         n|d         }|||||dœ|¥S )
NÚspecial_tokens_maskr   rn   ro   r=   r   Úlogits)rx   rw   r   rn   ro   r,   )rp   rB   Úmodelr   Údict)r"   rt   rw   r   rn   ro   rx   Úoutputs           r%   Ú_forwardz$TokenClassificationPipeline._forward  sá   € à*×.Ò.Ð/DÑEÔEÐØ%×)Ò)Ð*:¸DÑAÔAˆØ×#Ò# JÑ/Ô/ˆØ×"Ò" 9Ñ-Ô-ˆØŒ>˜TÒ!Ð!Ø�T”ZÐ/Ð/ ,Ð/Ð/°Ô2ˆFˆFà�T”ZÐ/Ð/ ,Ð/Ð/ˆFÝ)3°F½DÑ)AÔ)AÐP�V˜HÔ%Ð%ÀvÈaÄyˆFð Ø#6Ø,Ø Øð
ð 
ð ð
ð 	
r'   c           	      ó  ‡— ‰€dgŠg }|D �]I}|d         d                               ¦   «         }|d         d         }|d         d         }|d         �|d         d         nd }	|d         d                               ¦   «         }
t          j        |dd	¬
¦  «        }t          j        ||z
  ¦  «        }||                     dd	¬
¦  «        z  }| j        dk    r,|                      ¦   «         }|	�|	                      ¦   «         nd }	|                      ||||	|
|¦  «        }|                      ||¦  «        }ˆfd„|D ¦   «         }|                     |¦  «         �ŒKt          |¦  «        }|dk    r|  
                    |¦  «        }|S )NÚOrx   r   rn   rb   r   rw   éÿÿÿÿT)ÚaxisÚkeepdimsr=   c                 ót   •— g | ]4}|                      d d¦  «        ‰vr|                      dd¦  «        ‰v¯2|‘Œ5S )ÚentityNÚentity_group)r!   )rg   rƒ   rM   s     €r%   ú
<listcomp>z;TokenClassificationPipeline.postprocess.<locals>.<listcomp>D  sX   ø€ ð ð ð àØ—:’:˜h¨Ñ-Ô-°]ÐBÐBØ—J’J˜~¨tÑ4Ô4¸MÐIÐIð ð JÐIÐIr'   r   )ÚnumpyÚnpr3   ÚexpÚsumrB   Úgather_pre_entitiesÚ	aggregateÚextendr   Úaggregate_overlapping_entities)r"   Úall_outputsrJ   rM   Úall_entitiesÚmodel_outputsrx   rn   rb   r   rw   ÚmaxesÚshifted_expÚscoresÚpre_entitiesrH   Úentitiesrs   s      `              r%   Úpostprocessz'TokenClassificationPipeline.postprocess*  sÅ  ø€ ØÐ Ø ˜EˆMØˆØ(ð 	*ñ 	*ˆMØ" 8Ô,¨QÔ/×5Ò5Ñ7Ô7ˆFØ" 1”~ jÔ1ˆHØ% kÔ2°1Ô5ˆIà6CÐDTÔ6UÐ6a�Ð.Ô/°Ô2Ð2Ðgkð ð #0Ð0EÔ"FÀqÔ"I×"OÒ"OÑ"QÔ"QÐå”F˜6¨°TÐ:Ñ:Ô:ˆEÝœ& ¨%¡Ñ0Ô0ˆKØ  ;§?¢?¸ÀT ?Ñ#JÔ#JÑJˆFàŒ~ Ò%Ð%Ø%ŸOšOÑ-Ô-�	Ø;IÐ;U ×!5Ò!5Ñ!7Ô!7Ð!7Ð[_�à×3Ò3Ø˜) V¨^Ð=PÐRfñô ˆLð  $Ÿ~š~¨lÐ<PÑQÔQÐðð ð ð à.ðñ ô ˆHð ×Ò Ñ)Ô)Ð)Ñ)Ý˜Ñ%Ô%ˆ
Ø˜Š>ˆ>Ø×>Ò>¸|ÑLÔLˆLØÐr'   c                 óš  — t          |¦  «        dk    r|S t          |d„ ¬¦  «        }g }|d         }|D ]�}|d         |d         cxk    r|d         k     rIn nF|d         |d         z
  }|d         |d         z
  }||k    r|}ŒO||k    r|d         |d         k    r|}Œj|                     |¦  «         |}Œ‚|                     |¦  «         |S )Nr   c                 ó   — | d         S )NÚstartr,   )Úxs    r%   ú<lambda>zLTokenClassificationPipeline.aggregate_overlapping_entities.<locals>.<lambda>S  s
   € °!°G´*€ r'   ©Úkeyr™   ÚendÚscore)r   ÚsortedÚappend)r"   r•   Úaggregated_entitiesÚprevious_entityrƒ   Úcurrent_lengthÚprevious_lengths          r%   r�   z:TokenClassificationPipeline.aggregate_overlapping_entitiesP  s  € Ýˆx‰=Œ=˜AÒÐØˆOÝ˜(Ð(<Ð(<Ð=Ñ=Ô=ˆØ ÐØ" 1œ+ˆØð 
	)ð 
	)ˆFØ˜wÔ'¨6°'¬?ÐSÐSÒSÐS¸_ÈUÔ=SÒSÐSÐSÐSÐSØ!'¨¤°¸´Ñ!@�Ø"1°%Ô"8¸?È7Ô;SÑ"S�Ø! OÒ3Ð3Ø&,�O�OØ# Ò6Ð6¸6À'¼?È_Ð]dÔMeÒ;eÐ;eØ&,�Oøà#×*Ò*¨?Ñ;Ô;Ð;Ø"(��Ø×"Ò" ?Ñ3Ô3Ð3Ø"Ð"r'   rn   rb   r“   rw   Úreturnc                 óX  — g }t          |¦  «        D �]–\  }}	||         rŒ| j                             t          ||         ¦  «        ¦  «        }
|��3||         \  }}t	          |t          ¦  «        s3| j        dk    r(|                     ¦   «         }|                     ¦   «         }|||…         }t          | j        dd¦  «        rAt          | j        j        j	        dd¦  «        r!t          |
¦  «        t          |¦  «        k    }nW|t          j        t          j        t          j        hv rt          j        dt"          ¦  «         |dk    od||dz
  |dz   …         v}t          ||         ¦  «        | j        j        k    r|}
d	}nd}d}d	}|
|	||||d
œ}|                     |¦  «         �Œ˜|S )zTFuse various numpy arrays into dicts with all the information needed for aggregationNÚptÚ
_tokenizerÚcontinuing_subword_prefixz?Tokenizer does not support real words, using fallback heuristicr   ú r   F)Úwordr“   r™   rž   ÚindexÚ
is_subword)Ú	enumeraterT   Úconvert_ids_to_tokensÚintr   rB   ÚitemÚgetattrr©   ry   r   r.   r6   r7   r8   rQ   rR   ÚUserWarningÚunk_token_idr¡   )r"   rn   rb   r“   r   rw   rJ   r”   ÚidxÚtoken_scoresr¬   Ú	start_indÚend_indÚword_refr®   Ú
pre_entitys                   r%   rŠ   z/TokenClassificationPipeline.gather_pre_entitiesd  sí  € ð ˆÝ!*¨6Ñ!2Ô!2ð 0	,ñ 0	,ÑˆC�à" 3Ô'ð Øà”>×7Ò7½¸IÀc¼NÑ8KÔ8KÑLÔLˆDØÑ)Ø%3°CÔ%8Ñ"�	˜7Ý! )­SÑ1Ô1ð 1Ø”~¨Ò-Ð-Ø$-§N¢NÑ$4Ô$4˜	Ø")§,¢,¡.¤.˜Ø# I¨gÐ$5Ô6�Ý˜4œ>¨<¸Ñ>Ô>ð fÅ7Ø”NÔ-Ô3Ð5PÐRVñDô Dð fõ
 "% T¡¤­c°(©m¬mÒ!;�J�Jð ,Ý+Ô1Ý+Ô3Ý+Ô/ð0ð ð õ
 !œØ]Ý'ñô ð ð "+¨Q¢Ð!e°3¸hÀyÐSTÁ}ÐW`ÐcdÑWdÐGdÔ>eÐ3e�Jå�y ”~Ñ&Ô&¨$¬.Ô*EÒEÐEØ#�DØ!&�Jøà �	Ø�Ø"�
ð Ø&Ø"ØØØ(ðð ˆJð ×Ò 
Ñ+Ô+Ð+Ñ+ØÐr'   r”   c                 ó¦  — |t           j        t           j        hv r{g }|D ]u}|d                              ¦   «         }|d         |         }| j        j        j        |         ||d         |d         |d         |d         dœ}|                     |¦  «         Œvn|                      ||¦  «        }|t           j        k    r|S |  	                    |¦  «        S )Nr“   r­   r¬   r™   rž   )rƒ   rŸ   r­   r¬   r™   rž   )
r.   r4   r5   Úargmaxry   ÚconfigÚid2labelr¡   Úaggregate_wordsÚgroup_entities)r"   r”   rJ   r•   r»   Ú
entity_idxrŸ   rƒ   s           r%   r‹   z%TokenClassificationPipeline.aggregate¢  sî   € ØÕ$7Ô$<Õ>QÔ>XÐ#YÐYÐYØˆHØ*ð (ð (�
Ø'¨Ô1×8Ò8Ñ:Ô:�
Ø" 8Ô,¨ZÔ8�à"œjÔ/Ô8¸ÔDØ"Ø'¨Ô0Ø& vÔ.Ø'¨Ô0Ø% eÔ,ðð �ð —’ Ñ'Ô'Ð'Ð'ð(ð ×+Ò+¨LÐ:NÑOÔOˆHàÕ#6Ô#;Ò;Ð;ØˆOØ×"Ò" 8Ñ,Ô,Ð,r'   r•   c                 óü  — | j                              d„ |D ¦   «         ¦  «        }|t          j        k    rB|d         d         }|                     ¦   «         }||         }| j        j        j        |         }nå|t          j        k    rNt          |d„ ¬¦  «        }|d         }|                     ¦   «         }||         }| j        j        j        |         }n‡|t          j
        k    rht          j        d„ |D ¦   «         ¦  «        }t          j        |d¬¦  «        }	|	                     ¦   «         }
| j        j        j        |
         }|	|
         }nt          d¦  «        ‚||||d         d	         |d
         d         dœ}|S )Nc                 ó   — g | ]
}|d          ‘ŒS ©r¬   r,   ©rg   rƒ   s     r%   r…   z>TokenClassificationPipeline.aggregate_word.<locals>.<listcomp>¹  s   € Ð7^Ð7^Ð7^È6¸¸v¼Ð7^Ð7^Ð7^r'   r   r“   c                 ó6   — | d                               ¦   «         S )Nr“   )r3   )rƒ   s    r%   r›   z<TokenClassificationPipeline.aggregate_word.<locals>.<lambda>À  s   € ¸&ÀÔ:J×:NÒ:NÑ:PÔ:P€ r'   rœ   c                 ó   — g | ]
}|d          ‘ŒS )r“   r,   rÆ   s     r%   r…   z>TokenClassificationPipeline.aggregate_word.<locals>.<listcomp>Æ  s   € ÐGÐGÐG°F˜v hÔ/ÐGÐGÐGr'   )r€   zInvalid aggregation_strategyr™   r   rž   )rƒ   rŸ   r¬   r™   rž   )rT   Úconvert_tokens_to_stringr.   r6   r½   ry   r¾   r¿   r8   r3   r7   r‡   ÚstackÚnanmeanr    )r"   r•   rJ   r¬   r“   r¶   rŸ   rƒ   Ú
max_entityÚaverage_scoresrÂ   Ú
new_entitys               r%   Úaggregate_wordz*TokenClassificationPipeline.aggregate_word¸  s{  € ØŒ~×6Ò6Ð7^Ð7^ÐU]Ð7^Ñ7^Ô7^Ñ_Ô_ˆØÕ#6Ô#<Ò<Ð<Ø˜a”[ Ô*ˆFØ—-’-‘/”/ˆCØ˜3”KˆEØ”ZÔ&Ô/°Ô4ˆFˆFØ!Õ%8Ô%<Ò<Ð<Ý˜XÐ+PÐ+PÐQÑQÔQˆJØ Ô)ˆFØ—-’-‘/”/ˆCØ˜3”KˆEØ”ZÔ&Ô/°Ô4ˆFˆFØ!Õ%8Ô%@Ò@Ð@Ý”XÐGÐG¸hÐGÑGÔGÑHÔHˆFÝœZ¨°QÐ7Ñ7Ô7ˆNØ'×.Ò.Ñ0Ô0ˆJØ”ZÔ&Ô/°
Ô;ˆFØ" :Ô.ˆEˆEåÐ;Ñ<Ô<Ð<àØØØ˜a”[ Ô)Ø˜B”< Ô&ð
ð 
ˆ
ð Ðr'   c                 ó`  — |t           j        t           j        hv rt          d¦  «        ‚g }d}|D ]R}|€|g}Œ|d         r|                     |¦  «         Œ&|                     |                      ||¦  «        ¦  «         |g}ŒS|�)|                     |                      ||¦  «        ¦  «         |S )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®   )r.   r4   r5   r    r¡   rÏ   )r"   r•   rJ   Úword_entitiesÚ
word_grouprƒ   s         r%   rÀ   z+TokenClassificationPipeline.aggregate_wordsÖ  sÞ   € ð  ÝÔ$ÝÔ&ð$
ð 
ð 
õ ÐZÑ[Ô[Ð[àˆØˆ
Øð 	&ð 	&ˆFØÐ!Ø$˜X�
�
Ø˜Ô%ð &Ø×!Ò! &Ñ)Ô)Ð)Ð)à×$Ò$ T×%8Ò%8¸ÐEYÑ%ZÔ%ZÑ[Ô[Ð[Ø$˜X�
�
àÐ!Ø× Ò  ×!4Ò!4°ZÐAUÑ!VÔ!VÑWÔWÐWØÐr'   c                 ó<  — |d         d                               d¦  «        d         }t          j        d„ |D ¦   «         ¦  «        }d„ |D ¦   «         }|t          j        |¦  «        | j                             |¦  «        |d         d         |d         d         d	œ}|S )
zª
        Group together the adjacent tokens with the same entity predicted.

        Args:
            entities (`dict`): The entities predicted by the pipeline.
        r   rƒ   ú-r   c                 ó   — g | ]
}|d          ‘ŒS )rŸ   r,   rÆ   s     r%   r…   zBTokenClassificationPipeline.group_sub_entities.<locals>.<listcomp>û  s   € ÐDÐDÐD°˜V Gœ_ÐDÐDÐDr'   c                 ó   — g | ]
}|d          ‘ŒS rÅ   r,   rÆ   s     r%   r…   zBTokenClassificationPipeline.group_sub_entities.<locals>.<listcomp>ü  s   € Ð8Ð8Ð8 V�&˜”.Ð8Ð8Ð8r'   r™   rž   )r„   rŸ   r¬   r™   rž   )Úsplitr‡   rË   ÚmeanrT   rÉ   )r"   r•   rƒ   r“   Útokensr„   s         r%   Úgroup_sub_entitiesz.TokenClassificationPipeline.group_sub_entitiesò  s¥   € ð ˜!”˜XÔ&×,Ò,¨SÑ1Ô1°"Ô5ˆÝ”ÐDÐD¸8ÐDÑDÔDÑEÔEˆØ8Ð8¨xÐ8Ñ8Ô8ˆð #Ý”W˜V‘_”_Ø”N×;Ò;¸FÑCÔCØ˜a”[ Ô)Ø˜B”< Ô&ð
ð 
ˆð Ðr'   Úentity_namec                 óš   — |                      d¦  «        rd}|dd …         }n&|                      d¦  «        rd}|dd …         }nd}|}||fS )NzB-ÚBr   zI-ÚI)Ú
startswith)r"   rÛ   ÚbiÚtags       r%   Úget_tagz#TokenClassificationPipeline.get_tag  sk   € Ø×!Ò! $Ñ'Ô'ð 
	ØˆBØ˜a˜b˜b”/ˆCˆCØ×#Ò# DÑ)Ô)ð 	ØˆBØ˜a˜b˜b”/ˆCˆCð ˆBØˆCØ�3ˆwˆr'   c                 óº  — g }g }|D ]©}|s|                      |¦  «         Œ|                      |d         ¦  «        \  }}|                      |d         d         ¦  «        \  }}||k    r|dk    r|                      |¦  «         Œ~|                      |                      |¦  «        ¦  «         |g}Œª|r(|                      |                      |¦  «        ¦  «         |S )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Ý   )r¡   râ   rÚ   )	r"   r•   Úentity_groupsÚentity_group_disaggrƒ   rà   rá   Úlast_biÚlast_tags	            r%   rÁ   z*TokenClassificationPipeline.group_entities  s  € ð ˆØ Ðàð 	/ð 	/ˆFØ&ð Ø#×*Ò*¨6Ñ2Ô2Ð2Øð —l’l 6¨(Ô#3Ñ4Ô4‰GˆB�Ø $§¢Ð-@ÀÔ-DÀXÔ-NÑ OÔ OÑˆG�Xà�hŠˆ 2¨¢9 9à#×*Ò*¨6Ñ2Ô2Ð2Ð2ð ×$Ò$ T×%<Ò%<Ð=PÑ%QÔ%QÑRÔRÐRØ'- hÐ#Ð#Øð 	Oà× Ò  ×!8Ò!8Ð9LÑ!MÔ!MÑNÔNÐNàÐr'   )NNNNNN)N)!r(   r)   r*   r+   Údefault_input_namesr   r@   r   Úboolr.   r   r   r±   rY   r   r   r&   ru   r|   r4   r–   r�   r‡   Úndarrayrz   rŠ   r‹   rÏ   rÀ   rÚ   râ   rÁ   Ú__classcell__)rG   s   @r%   r:   r:   =   sù  ø€ € € € € ðH"ð "ðH &Ðà#EÐ#EÑ#GÔ#Gð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð Ø+/Ø*.Ø>BØ:>Ø $ðG9ð G9ð # 4œ.ðG9ð " $œð	G9ð
 'Ð':Ô;ðG9ð !  e¨C°¨H¤oÔ!6Ô7ðG9ð ˜”ðG9ð G9ð G9ð G9ðR2˜u S¨$¨s¬) ^Ô4ð 2ð 2ð 2ð 2ð 2ð 2ð@ð ð ð ð4
ð 
ð 
ð* =PÔ<TÐdhð $ð $ð $ð $ðL#ð #ð #ð(<àð<ð ”:ð<ð ”
ð	<ð
 !  e¨C°¨H¤oÔ!6Ô7ð<ð  œZð<ð 2ð<ð 
ˆdŒð<ð <ð <ð <ð|- 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   rQ   Útypingr   r   r   r   r†   r‡   Úmodels.bert.tokenization_bertr   Úutilsr	   r
   r   r   Úbaser   r   r   r   Ú
tensorflowr=   Úmodels.auto.modeling_tf_autor   Úmodels.auto.modeling_autor   r   r.   r:   ÚNerPipeliner,   r'   r%   ú<module>rô      sÊ  ðØ €€€Ø €€€Ø /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ð /à Ð Ð Ð à :Ð :Ð :Ð :Ð :Ð :ðð ð ð ð ð ð ð ð ð ð ð ð NÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ Mð €?ÑÔð _ØÐÐÐà^Ð^Ð^Ð^Ð^Ð^ØÐÑÔð YØXÐXÐXÐXÐXÐXð&ð &ð &ð &ð &¨ñ &ô &ð &ð4ð ð ð ð ˜,ñ ô ð ð ÐØðñ"ô "ðFXð Xð Xð Xð X -ñ Xô XñG"ô "ðFXðv *€€€r'   