Ë
    a›¾j€a  ã            	       ó„  — d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
mZmZmZmZ d dlZd dlmZmZmZmZmZmZ d dlmZmZmZmZ ddlmZm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( ddl)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ dZ0dZ1dZ2 e«       jg                  e0«      d   Z4 e«       jg                  e1«      d   Z5e G d„ de«      «       Z6ddœde	e&   de
e7   dee   defd„Z8ddœde	e&   de9dee   defd„Z:de
e7   de6fd„Z;d e7d!e7de6fd"„Z<de9de6fd#„Z=d$e	e*   dee9ef   fd%„Z>d&„ Z?e G d'„ d(«      «       Z@ G d)„ d*e/«      ZAd+„ ZBy),é    N)Ú	dataclass)Úpartial)	ÚAnyÚCallableÚDictÚIterableÚListÚOptionalÚTupleÚUnionÚcast)ÚConfigÚModelÚOpsÚ	OptimizerÚget_current_opsÚset_dropout_rate)ÚFloats2dÚInts1dÚInts2dÚRaggedé   )ÚProtocolÚruntime_checkable)ÚErrors)ÚLanguage)ÚScorer)ÚDocÚSpanÚ	SpanGroup)ÚExampleÚvalidate_examples)ÚVocabé   )ÚTrainablePipea4  
[model]
@architectures = "spacy.SpanCategorizer.v1"
scorer = {"@layers": "spacy.LinearLogistic.v1"}

[model.reducer]
@layers = spacy.mean_max_reducer.v1
hidden_size = 128

[model.tok2vec]
@architectures = "spacy.Tok2Vec.v2"

[model.tok2vec.embed]
@architectures = "spacy.MultiHashEmbed.v2"
width = 96
rows = [5000, 1000, 2500, 1000]
attrs = ["NORM", "PREFIX", "SUFFIX", "SHAPE"]
include_static_vectors = false

[model.tok2vec.encode]
@architectures = "spacy.MaxoutWindowEncoder.v2"
width = ${model.tok2vec.embed.width}
window_size = 1
maxout_pieces = 3
depth = 4
a&  
[model]
@architectures = "spacy.SpanCategorizer.v1"
scorer = {"@layers": "Softmax.v2"}

[model.reducer]
@layers = spacy.mean_max_reducer.v1
hidden_size = 128

[model.tok2vec]
@architectures = "spacy.Tok2Vec.v2"
[model.tok2vec.embed]
@architectures = "spacy.MultiHashEmbed.v1"
width = 96
rows = [5000, 1000, 2500, 1000]
attrs = ["NORM", "PREFIX", "SUFFIX", "SHAPE"]
include_static_vectors = false

[model.tok2vec.encode]
@architectures = "spacy.MaxoutWindowEncoder.v2"
width = ${model.tok2vec.embed.width}
window_size = 1
maxout_pieces = 3
depth = 4
ÚscÚmodelc                   ó2   — e Zd Zddœdee   dee   defd„Zy)Ú	SuggesterN©ÚopsÚdocsr+   Úreturnc                 ó   — y ©N© )Úselfr,   r+   s      ú`/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/spacy/pipeline/spancat.pyÚ__call__zSuggester.__call__Q   s   � ó    )	Ú__name__Ú
__module__Ú__qualname__r   r   r
   r   r   r3   r0   r4   r2   r)   r)   O   s   „ àDHÒX˜X c™]ÐX°H¸S±MÐXÈVÔXr4   r)   r*   r,   Úsizesr+   r-   c          	      ó  — |€
t        «       }g }g }| D ]â  }|j                  j                  t        |«      d¬«      }|j	                  d«      }d}|D ]‘  }|t        |«      k  rX|d t        |«      |dz
  z
   }	|j                  |j                  j                  |	|	|z   f«      «       ||d   j                  d   z  }|sŒl|d   j                  dk(  rŒJ |d   j                  «       ‚ |j                  |«       Œä |j                  |«      }
t        |«      dkD  r&t        |j                  j                  |«      |
«      }n't        |j                  j                  dd¬«      |
«      }|j                  j                  dk(  sJ ‚|S )	NÚi©Údtype)éÿÿÿÿr$   r   r$   r=   r   ©r   r   )r   ÚxpÚarangeÚlenÚreshapeÚappendÚhstackÚshapeÚndimÚ	asarray1ir   ÚvstackÚzerosÚdataXd)r,   r8   r+   ÚspansÚlengthsÚdocÚstartsÚlengthÚsizeÚstarts_sizeÚlengths_arrayÚoutputs               r2   Úngram_suggesterrT   T   sh  € ð €{ÜÓˆØ€EØ€GØò ˆØ—‘—‘œs 3›x¨s�Ó3ˆØ—‘ Ó(ˆØˆØò 	<ˆDØ”s˜3“xÒØ$Ð%<¤s¨3£x°4¸!±8Ñ'<Ð=�Ø—‘˜SŸV™VŸ]™]¨K¸ÀtÑ9KÐ+LÓMÔNØ˜% ™)Ÿ/™/¨!Ñ,Ñ,�ÚØ˜R‘y—~‘~¨Ó*Ð;¨E°"©I¯O©OÓ;Ð*ð	<ð 	�‰�vÕðð —M‘M 'Ó*€MÜ
ˆ5ƒz�A‚~Ü˜Ÿ™Ÿ™ eÓ,¨mÓ<‰ä˜Ÿ™Ÿ™ V°3˜Ó7¸ÓGˆà�=‰=×Ñ Ò"Ð"Ð"Ø€Mr4   Ú	spans_keyc                óâ  — |€
t        «       }g }g }| D ]d  }d}|j                  |   r@|j                  |   D ].  }|j                  |j                  |j                  g«       |dz  }Œ0 |j                  |«       Œf t        t        |j                  |d¬«      «      }t        |«      dkD  rt        |j                  |d¬«      |«      }	|	S t        |j                  j                  dd¬«      |«      }	|	S )Nr   r$   r:   r;   r>   )r   rK   rC   ÚstartÚendr   r   ÚasarrayrA   r   r?   rI   )
r,   rU   r+   rK   rL   rM   rO   ÚspanrR   rS   s
             r2   Úpreset_spans_suggesterr[   q   sí   € ð €{ÜÓˆØ€EØ€GØò ˆØˆØ�9‰9�YÒØŸ	™	 )Ñ,ò �Ø—‘˜dŸj™j¨$¯(©(Ð3Ô4Ø˜!‘‘ðð 	�‰�vÕðô œ §¡¨W¸C Ó!@ÓA€MÜ
ˆ5ƒz�A‚~Ü˜Ÿ™ E°˜Ó5°}ÓEˆð €Mô ˜Ÿ™Ÿ™ V°3˜Ó7¸ÓGˆØ€Mr4   c                 ó$   — t        t        | ¬«      S )z£Suggest all spans of the given lengths. Spans are returned as a ragged
    array of integers. The array has two columns, indicating the start and end
    position.©r8   )r   rT   r]   s    r2   Úbuild_ngram_suggesterr^   ˆ   s   € ô
 ”?¨%Ô0Ð0r4   Úmin_sizeÚmax_sizec                 óH   — t        t        | |dz   «      «      }t        |«      S )zÖSuggest all spans of the given lengths between a given min and max value - both inclusive.
    Spans are returned as a ragged array of integers. The array has two columns,
    indicating the start and end position.r$   )ÚlistÚranger^   )r_   r`   r8   s      r2   Úbuild_ngram_range_suggesterrd   �   s$   € ô ”�x ¨A¡Ó.Ó/€EÜ  Ó'Ð'r4   c                 ó$   — t        t        | ¬«      S )z»Suggest all spans that are already stored in doc.spans[spans_key].
    This is useful when an upstream component is used to set the spans
    on the Doc such as a SpanRuler or SpanFinder.©rU   )r   r[   rf   s    r2   Úbuild_preset_spans_suggesterrg   ˜   s   € ô Ô)°YÔ?Ð?r4   Úexamplesc                 óú   ‡‡— t        |«      }dŠ|d   Š|j                  d‰› ‰› �«       |j                  dd«       |j                  dˆfd„«       |j                  dˆfd	„«       t        j                  | fi |¤ŽS )
NÚspans_rU   ÚattrÚallow_overlapTÚgetterc                 óT   •— | j                   j                  |t        ‰«      d  g «      S r/   )rK   ÚgetrA   )rM   ÚkeyÚattr_prefixs     €r2   ú<lambda>zspancat_score.<locals>.<lambda>¦   s#   ø€  3§9¡9§=¡=°´S¸Ó5EÐ5GÐ1HÈ"Ó#M€ r4   Úhas_annotationc                 ó    •— ‰| j                   v S r/   )rK   )rM   rp   s    €r2   rr   zspancat_score.<locals>.<lambda>¨   s   ø€ °C¸3¿9¹9Ð4D€ r4   )ÚdictÚ
setdefaultr   Úscore_spans)rh   Úkwargsrq   rp   s     @@r2   Úspancat_scorery   Ÿ   s‚   ù€ Ü�&‹\€FØ€KØ
�Ñ
€CØ
×Ñ�f  ¨c¨UÐ3Ô4Ø
×Ñ�o tÔ,Ø
×ÑØÓMôð ×ÑÐ&Ó(DÔEÜ×Ñ˜hÑ1¨&Ñ1Ð1r4   c                  ó   — t         S r/   )ry   r0   r4   r2   Úmake_spancat_scorerr{   ¬   s   € ÜÐr4   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)Ú
_Intervalsz:
    Helper class to avoid storing overlapping spans.
    c                 ó"   — t        «       | _        y r/   )ÚsetÚranges©r1   s    r2   Ú__init__z_Intervals.__init__¶   s   € Ü“eˆ�r4   c                 ó\   — t        ||«      D ]  }| j                  j                  |«       Œ y r/   )rc   r€   Úadd)r1   r:   ÚjÚes       r2   r„   z_Intervals.add¹   s'   € Ü�q˜!“ò 	ˆAØ�K‰K�O‰O˜AÕñ	r4   c                 óP   — |\  }}t        ||«      D ]  }|| j                  v sŒ y y)NTF)rc   r€   )r1   Úrangr:   r…   r†   s        r2   Ú__contains__z_Intervals.__contains__½   s4   € Ø‰ˆˆ1Ü�q˜!“ò 	ˆAØ�D—K‘KÒÙð	ð r4   N)r5   r6   r7   Ú__doc__r‚   r„   r‰   r0   r4   r2   r}   r}   °   s   „ ñòòór4   r}   c                   ó¬  — e Zd ZdZ	 d<ddddddedœd	ed
eeee	   e
f   ef   dededededee   dee   dee   dee   dee   ddfd„Zedefd„«       Zd=d„Zdedefd„Zedee   fd„«       Zedee   fd„«       Zedeeef   fd„«       Zedefd„«       Zedeedf   fd„«       Zdee	   fd „Z d!d"œdee	   d#eddfd$„Z!dee	   ddfd%„Z"d&ddd'œd(ee#   d)ed*ee$   d+eeeef      deeef   f
d,„Z%d(ee#   d-ee
ef   deeef   fd.„Z&ddd/œd0eg ee#   f   d1ee'   d2eee      ddfd3„Z(d(ee#   fd4„Z)d5e#fd6„Z*d7e	d8e+d9ede,fd:„Z-	 d>d7e	d8e+d9edede,f
d;„Z.y)?ÚSpanCategorizerz_Pipeline component to label spans of text.

    DOCS: https://spacy.io/api/spancategorizer
    FrK   ç      ð?TNg      à?)Úadd_negative_labelrU   Únegative_weightrl   Úmax_positiveÚ	thresholdÚscorerÚvocabr'   Ú	suggesterÚnamerŽ   rU   r�   rl   r�   r‘   r’   r-   c                óÜ   — g ||
|	||dœ| _         || _        || _        || _        || _        || _        || _        |s2|	�/|	dkD  r)t        t        j                  j                  |	¬«      «      ‚yyy)a}  Initialize the multi-label or multi-class span categorizer.

        vocab (Vocab): The shared vocabulary.
        model (thinc.api.Model): The Thinc Model powering the pipeline component.
            For multi-class classification (single label per span) we recommend
            using a Softmax classifier as a the final layer, while for multi-label
            classification (multiple possible labels per span) we recommend Logistic.
        suggester (Callable[[Iterable[Doc], Optional[Ops]], Ragged]): A function that suggests spans.
            Spans are returned as a ragged array with two integer columns, for the
            start and end positions.
        name (str): The component instance name, used to add entries to the
            losses during training.
        spans_key (str): Key of the Doc.spans dict to save the spans under.
            During initialization and training, the component will look for
            spans on the reference document under the same key. Defaults to
            `"spans"`.
        add_negative_label (bool): Learn to predict a special 'negative_label'
            when a Span is not annotated.
        threshold (Optional[float]): Minimum probability to consider a prediction
            positive. Defaults to 0.5. Spans with a positive prediction will be saved
            on the Doc.
        max_positive (Optional[int]): Maximum number of labels to consider
            positive per span. Defaults to None, indicating no limit.
        negative_weight (float): Multiplier for the loss terms.
            Can be used to downweight the negative samples if there are too many
            when add_negative_label is True. Otherwise its unused.
        allow_overlap (bool): If True the data is assumed to contain overlapping spans.
            Otherwise it produces non-overlapping spans greedily prioritizing
            higher assigned label scores. Only used when max_positive is 1.
        scorer (Optional[Callable]): The scoring method. Defaults to
            Scorer.score_spans for the Doc.spans[spans_key] with overlapping
            spans allowed.

        DOCS: https://spacy.io/api/spancategorizer#init
        )ÚlabelsrU   r‘   r�   r�   rl   Nr$   )r�   )Úcfgr“   r”   r'   r•   r’   rŽ   Ú
ValueErrorr   ÚE1051Úformat)r1   r“   r'   r”   r•   rŽ   rU   r�   rl   r�   r‘   r’   s               r2   r‚   zSpanCategorizer.__init__Ë   s„   € ðf Ø"Ø"Ø(Ø.Ø*ñ$
ˆŒð ˆŒ
Ø"ˆŒØˆŒ
ØˆŒ	ØˆŒØ"4ˆÔÙ Ð!9¸lÈQÒ>NÜœVŸ\™\×0Ñ0¸lÐ0ÓKÓLÐLð ?OÐ!9ˆ}r4   c                 ó2   — t        | j                  d   «      S )z¿Key of the doc.spans dict to save the spans under. During
        initialization and training, the component will look for spans on the
        reference document under the same key.
        rU   )Ústrr˜   r�   s    r2   rp   zSpanCategorizer.key  s   € ô �4—8‘8˜KÑ(Ó)Ð)r4   c                 ó,  — d}| j                   j                  d«      r| j                   j                  d«      }no| j                   j                  d«      rT| j                   j	                  d«      j                  d«      r*| j                   j	                  d«      j                  d«      }|�j|| j
                  k(  rZ| j                  sMt        t        j                  j                  | j                  | j                   j                  d«      ¬«      «      ‚yyy)z<Raise an error if the component can not add any more labels.NÚnOÚoutput_layer)r•   rŸ   )r'   Úhas_dimÚget_dimÚhas_refÚget_refÚ	_n_labelsÚis_resizabler™   r   ÚE922r›   r•   )r1   rŸ   s     r2   Ú_allow_extra_labelz"SpanCategorizer._allow_extra_label  sÞ   € àˆØ�:‰:×Ñ˜dÔ#Ø—‘×#Ñ# DÓ)‰BØ�Z‰Z×Ñ Ô/°D·J±J×4FÑ4FØó5
ç
‰'�$‹-ð5ð —‘×#Ñ# NÓ3×;Ñ;¸DÓAˆBØˆ>˜b D§N¡NÒ2Ø×$Ò$Ü Ü—K‘K×&Ñ&¨D¯I©I¸$¿*¹*×:LÑ:LÈTÓ:RÐ&ÓSóð ð %ð 3ˆ>r4   Úlabelc                 ó  — t        |t        «      st        t        j                  «      ‚|| j
                  v ry| j                  «        | j                  d   j                  |«       | j                  j                  j                  |«       y)zÎAdd a new label to the pipe.

        label (str): The label to add.
        RETURNS (int): 0 if label is already present, otherwise 1.

        DOCS: https://spacy.io/api/spancategorizer#add_label
        r   r—   r$   )Ú
isinstancer�   r™   r   ÚE187r—   r¨   r˜   rC   r“   Ústringsr„   )r1   r©   s     r2   Ú	add_labelzSpanCategorizer.add_label%  sj   € ô ˜%¤Ô%ÜœVŸ[™[Ó)Ð)Ø�D—K‘KÑØØ×ÑÔ!Ø�‰�Ñ×!Ñ! %Ô(Ø�
‰
×Ñ×Ñ˜uÔ%Ør4   c                 ó2   — t        | j                  d   «      S )z†RETURNS (Tuple[str]): The labels currently added to the component.

        DOCS: https://spacy.io/api/spancategorizer#labels
        r—   )Útupler˜   r�   s    r2   r—   zSpanCategorizer.labels6  s   € ô �T—X‘X˜hÑ'Ó(Ð(r4   c                 ó,   — t        | j                  «      S )z†RETURNS (List[str]): Information about the component's labels.

        DOCS: https://spacy.io/api/spancategorizer#label_data
        )rb   r—   r�   s    r2   Ú
label_datazSpanCategorizer.label_data>  s   € ô �D—K‘KÓ Ð r4   c                 ó`   — t        | j                  «      D ��ci c]  \  }}||“Œ
 c}}S c c}}w )z(RETURNS (Dict[str, int]): The label map.)Ú	enumerater—   )r1   r:   r©   s      r2   Ú
_label_mapzSpanCategorizer._label_mapF  s)   € ô *3°4·;±;Ó)?×@™X˜Q ��q‘Ó@Ð@ùÓ@s   ™*c                 ót   — | j                   rt        | j                  «      dz   S t        | j                  «      S )z RETURNS (int): Number of labels.r$   )rŽ   rA   r—   r�   s    r2   r¥   zSpanCategorizer._n_labelsK  s0   € ð ×"Ò"Ü�t—{‘{Ó# aÑ'Ð'ä�t—{‘{Ó#Ð#r4   c                 óF   — | j                   rt        | j                  «      S y)z8RETURNS (Union[int, None]): Index of the negative label.N)rŽ   rA   r²   r�   s    r2   Ú_negative_label_iz!SpanCategorizer._negative_label_iS  s   € ð ×"Ò"Ü�t—‘Ó'Ð'àr4   r,   c                 ó   — | j                  || j                  j                  ¬«      }|j                  j	                  «       dk(  r*| j                  j                  j                  dd«      }||fS | j                  j                  ||f«      }||fS )zþApply the pipeline's model to a batch of docs, without modifying them.

        docs (Iterable[Doc]): The documents to predict.
        RETURNS: The models prediction for each document.

        DOCS: https://spacy.io/api/spancategorizer#predict
        r*   r   )r”   r'   r+   rL   ÚsumÚalloc2fÚpredict)r1   r,   ÚindicesÚscoress       r2   r¼   zSpanCategorizer.predict[  s}   € ð —.‘. ¨4¯:©:¯>©>�.Ó:ˆØ�?‰?×ÑÓ  AÒ%Ø—Z‘Z—^‘^×+Ñ+¨A¨qÓ1ˆFð ˜ˆÐð —Z‘Z×'Ñ'¨¨w¨Ó8ˆFØ˜ˆÐr4   Ú
candidates)Úcandidates_keyrÀ   c                ó  — | j                  || j                  j                  ¬«      }t        ||«      D ]L  \  }}g |j                  |<   |j
                  D ])  }|j                  |   j                  ||d   |d    «       Œ+ ŒN y)ao  Use the spancat suggester to add a list of span candidates to a list of docs.
        This method is intended to be used for debugging purposes.

        docs (Iterable[Doc]): The documents to modify.
        candidates_key (str): Key of the Doc.spans dict to save the candidate spans under.

        DOCS: https://spacy.io/api/spancategorizer#set_candidates
        r*   r   r$   N)r”   r'   r+   ÚziprK   rJ   rC   )r1   r,   rÀ   Úsuggester_outputr¿   rM   Úindexs          r2   Úset_candidateszSpanCategorizer.set_candidatesj  s‡   € ð  Ÿ>™>¨$°D·J±J·N±N˜>ÓCÐä"Ð#3°TÓ:ò 	K‰OˆJ˜Ø(*ˆC�I‰I�nÑ%Ø#×*Ñ*ò K�Ø—	‘	˜.Ñ)×0Ñ0°°U¸1±XÀÀaÁÐ1IÕJñKñ	Kr4   c           
      óÐ  — |\  }}d}t        |«      D ]Ñ  \  }}||   j                  }t        t        | j                  d   «      }	| j                  d   dk(  r?| j                  ||||||j                  |   z    |	«      |j                  | j                  <   n=| j                  ||||||j                  |   z    «      |j                  | j                  <   ||j                  |   z  }ŒÓ y)a  Modify a batch of Doc objects, using pre-computed scores.

        docs (Iterable[Doc]): The documents to modify.
        scores: The scores to set, produced by SpanCategorizer.predict.

        DOCS: https://spacy.io/api/spancategorizer#set_annotations
        r   rl   r�   r$   N)
r´   rJ   r   Úboolr˜   Ú_make_span_group_singlelabelrL   rK   rp   Ú_make_span_group_multilabel)
r1   r,   Úindices_scoresr½   r¾   Úoffsetr:   rM   Ú	indices_irl   s
             r2   Úset_annotationszSpanCategorizer.set_annotations|  sî   € ð )‰ˆ�ØˆÜ “oò 	)‰FˆAˆsØ ™
×)Ñ)ˆIÜ ¤ t§x¡x°Ñ'@ÓAˆMØ�x‰x˜Ñ'¨1Ò,Ø&*×&GÑ&GØØØ˜6 F¨W¯_©_¸QÑ-?Ñ$?Ð@Ø!ó	'�—	‘	˜$Ÿ(™(Ò#ð '+×&FÑ&FØØØ˜6 F¨W¯_©_¸QÑ-?Ñ$?Ð@ó'�—	‘	˜$Ÿ(™(Ñ#ð
 �g—o‘o aÑ(Ñ(‰Fñ!	)r4   ç        )ÚdropÚsgdÚlossesrh   rÏ   rÐ   rÑ   c                ón  — |€i }|j                  | j                  d«       t        |d«       | j                  |«       t	        d„ |D «       «      s|S |D �cg c]  }|j
                  ‘Œ }}| j                  || j                  j                  ¬«      }|j                  j                  «       dk(  r|S t        | j                  |«       | j                  j                  ||f«      \  }}	| j                  |||f«      \  }
} |	|«       |�| j                  |«       || j                  xx   |
z  cc<   |S c c}w )a1  Learn from a batch of documents and gold-standard information,
        updating the pipe's model. Delegates to predict and get_loss.

        examples (Iterable[Example]): A batch of Example objects.
        drop (float): The dropout rate.
        sgd (thinc.api.Optimizer): The optimizer.
        losses (Dict[str, float]): Optional record of the loss during training.
            Updated using the component name as the key.
        RETURNS (Dict[str, float]): The updated losses dictionary.

        DOCS: https://spacy.io/api/spancategorizer#update
        rÎ   zSpanCategorizer.updatec              3   ób   K  — | ]'  }|j                   rt        |j                   «      nd –— Œ) y­w)r   N)Ú	predictedrA   )Ú.0Úegs     r2   ú	<genexpr>z)SpanCategorizer.update.<locals>.<genexpr>±  s$   è ø€ ÒOÀ¨¯ª”3�r—|‘|Ô$¸!Ó;ÑOùs   ‚-/r*   r   )rv   r•   r"   Ú_validate_categoriesÚanyrÔ   r”   r'   r+   rL   rº   r   Úbegin_updateÚget_lossÚfinish_update)r1   rh   rÏ   rÐ   rÑ   rÖ   r,   rK   r¾   Úbackprop_scoresÚlossÚd_scoress               r2   ÚupdatezSpanCategorizer.update˜  s  € ð( ˆ>ØˆFØ×Ñ˜$Ÿ)™) SÔ)Ü˜(Ð$<Ô=Ø×!Ñ! (Ô+ÜÑOÀhÔOÔOàˆMØ'/Ö0 �—“Ð0ˆÐ0Ø—‘˜t¨¯©¯©�Ó8ˆØ�=‰=×ÑÓ !Ò#ØˆMÜ˜Ÿ™ TÔ*Ø"&§*¡*×"9Ñ"9¸4À¸-Ó"HÑˆ�ØŸ™ x°%¸°ÓA‰ˆˆhÙ˜Ô!Øˆ?Ø×Ñ˜sÔ#Øˆt�y‰yÓ˜TÑ!ÓØˆùò 1s   ÁD2Úspans_scoresc                 óØ  — |\  }}t        | j                  j                  j                  |j                  «      | j                  j                  j                  |j
                  «      «      }t        j                  |j                  |j                  ¬«      }| j                  r"t        j                  |j                  d   «      }d}| j                  }t        |«      D ]Ï  \  }	}
i }||	   j                  }t        |j
                  |	   «      D ],  }t!        ||df   «      }t!        ||df   «      }||z   |||f<   Œ. | j#                  |
«      D ]L  }|j$                  |j&                  f}||v sŒ ||   }||j(                     }d|||f<   | j                  sŒHd|<   ŒN ||j
                  |	   z  }ŒÑ | j                  j                  j+                  |d¬«      }| j                  r)t        j,                  «      d   }d||| j.                  f<   ||z
  }| j                  r/t1        t2        | j4                  d   «      }|dk7  r|xx   |z  cc<   t3        |dz  j7                  «       «      }||fS )	ak  Find the loss and gradient of loss for the batch of documents and
        their predicted scores.

        examples (Iterable[Examples]): The batch of examples.
        spans_scores: Scores representing the model's predictions.
        RETURNS (Tuple[float, float]): The loss and the gradient.

        DOCS: https://spacy.io/api/spancategorizer#get_loss
        r;   r   r$   r�   rÎ   Úfr�   r   )r   r'   r+   Úto_numpyÚdatarL   ÚnumpyrI   rE   r<   rŽ   Úonesrµ   r´   rJ   rc   ÚintÚ_get_aligned_spansrW   rX   Úlabel_rY   Únonzeror¸   r   Úfloatr˜   rº   )r1   rh   rá   rK   r¾   ÚtargetÚnegative_spansrË   Ú	label_mapr:   rÖ   Úspans_indexÚspans_ir…   rW   rX   Ú	gold_spanrp   ÚrowÚkÚnegative_samplesrß   Ú
neg_weightrÞ   s                           r2   rÛ   zSpanCategorizer.get_lossÁ  sK  € ð %‰ˆˆvÜØ�J‰J�N‰N×#Ñ# E§J¡JÓ/°·±·±×1HÑ1HÈÏÉÓ1Wó
ˆô —‘˜VŸ\™\°·±Ô>ˆØ×"Ò"Ü"ŸZ™Z¨¯©°a©Ó:ˆNØˆØ—O‘Oˆ	Ü˜xÓ(ò 	'‰EˆAˆrð ˆKØ˜A‘h—o‘oˆGÜ˜5Ÿ=™=¨Ñ+Ó,ò 7�Ü˜G A q D™MÓ*�Ü˜' ! Q $™-Ó(�Ø,2°Q©J�˜U C˜LÒ)ð7ð "×4Ñ4°RÓ8ò 2�	Ø —‘¨	¯©Ð6�Ø˜+Ò%Ø% cÑ*�CØ! )×"2Ñ"2Ñ3�AØ%(�F˜3 ˜6‘NØ×.Ó.à.1˜ sÒ+ð2ð �e—m‘m AÑ&Ñ&‰Fð+	'ð, —‘—‘×'Ñ'¨°cÐ'Ó:ˆØ×"Ò"Ü$Ÿ}™}¨^Ó<¸QÑ?ÐØ?BˆFÐ# T×%;Ñ%;Ð;Ñ<ð ˜F‘?ˆØ×"Ò"Üœe T§X¡XÐ.?Ñ%@ÓAˆJØ˜SÒ ØÐ)Ó*¨jÑ8Ó*Ü�h ‘k×&Ñ&Ó(Ó)ˆØ�Xˆ~Ðr4   )Únlpr—   Úget_examplesr÷   r—   c                óÀ  — g }|�|D ]  }| j                  |«       Œ  |«       D ]t  }|€P|j                  j                  j                  | j                  g «      D ]  }| j                  |j
                  «       Œ t        |«      dk  sŒd|j                  |«       Œv | j                  «        |r“|D �cg c]  }|j                  ‘Œ }} t        dg¬«      |«      }	| j                  j                  j                  |	j                  j                  d   | j                   «      }
| j                  j#                  ||	f|
¬«       y| j                  j#                  «        yc c}w )a|  Initialize the pipe for training, using a representative set
        of data examples.

        get_examples (Callable[[], Iterable[Example]]): Function that
            returns a representative sample of gold-standard Example objects.
        nlp (Optional[Language]): The current nlp object the component is part of.
        labels (Optional[List[str]]): The labels to add to the component, typically generated by the
            `init labels` command. If no labels are provided, the get_examples
            callback is used to extract the labels from the data.

        DOCS: https://spacy.io/api/spancategorizer#initialize
        Né
   r$   r]   r   )ÚXÚY)r®   Ú	referencerK   ro   rp   rê   rA   rC   Ú_require_labelsÚxr^   r'   r+   r»   rJ   rE   r¥   Ú
initialize)r1   rø   r÷   r—   Úsubbatchr©   rÖ   rZ   r,   rK   rü   s              r2   r   zSpanCategorizer.initializeÿ  s+  € ð& #%ˆØÐØò &�Ø—‘˜uÕ%ð&á“.ò 	$ˆBØˆ~ØŸL™L×.Ñ.×2Ñ2°4·8±8¸RÓ@ò 0�DØ—N‘N 4§;¡;Õ/ð0ä�8‹}˜rÓ!Ø—‘ Õ#ð	$ð 	×ÑÔÙØ#+Ö,˜R�B—D“DÐ,ˆDÐ,Ø4Ô)°°Ô4°TÓ:ˆEØ—
‘
—‘×&Ñ& u§|¡|×'9Ñ'9¸!Ñ'<¸d¿n¹nÓMˆAØ�J‰J×!Ñ! T¨5 M°QÐ!Õ7à�J‰J×!Ñ!Õ#ùò -s   Â1Ec                  ó   — y r/   r0   )r1   rh   s     r2   rØ   z$SpanCategorizer._validate_categories%  s   € àr4   rÖ   c                 ó„   — |j                  |j                  j                  j                  | j                  g «      d¬«      S )NT)rl   )Úget_aligned_spans_y2xrý   rK   ro   rp   )r1   rÖ   s     r2   ré   z"SpanCategorizer._get_aligned_spans)  s:   € Ø×'Ñ'Ø�L‰L×Ñ×"Ñ" 4§8¡8¨RÓ0Àð (ó 
ð 	
r4   rM   r½   r¾   c                 ó0  — t        || j                  ¬«      }|j                  dk(  r|S | j                  j                  j                  |«      }| j                  j                  j                  |«      }| j                  d   }| j                  d   }||k\  }|�Åt        |t        «      sJ ‚| j                  rot        j                  |dd…| j                  f   «      }t        j                   |dd…| j                  f<   |dz  j                  «       }	||dd…| j                  f<   n|dz  j                  «       }	|	dd…|d…f   }
t        |
«      D ]  \  }}d|||f<   Œ g }t!        |j"                  d   «      D ]z  }||df   }||df   }t        ||   «      D ]Y  \  }}|sŒ	|| j                  k7  sŒ|j%                  t'        |||| j(                  |   ¬	«      «       |j%                  |||f   «       Œ[ Œ| t        j*                  |«      |j,                  d
<   |S )z5Find the top-k labels for each span (k=max_positive).©r•   r   r‘   r�   Nr=   Fr$   ©r©   r¾   )r    rp   rP   r'   r+   rä   r˜   r«   rè   rŽ   ræ   Úcopyr¸   ÚinfÚargsortr´   rc   rE   rC   r   r—   ÚarrayÚattrs)r1   rM   r½   r¾   rK   r‘   r�   ÚkeepsÚnegative_scoresÚrankedÚspan_filterr:   ró   Úattrs_scoresrW   rX   r…   Úkeeps                     r2   rÉ   z+SpanCategorizer._make_span_group_multilabel.  s   € ô ˜# D§H¡HÔ-ˆØ�;‰;˜!ÒØˆLØ—‘—‘×(Ñ(¨Ó0ˆØ—*‘*—.‘.×)Ñ)¨'Ó2ˆØ—H‘H˜[Ñ)ˆ	Ø—x‘x Ñ/ˆà˜)Ñ#ˆØÐ#Ü˜l¬CÔ0Ð0Ð0Ø×&Ò&Ü"'§*¡*¨V²A°t×7MÑ7MÐ4MÑ-NÓ"O�Ü5:·Y±Y°J�’q˜$×0Ñ0Ð0Ñ1Ø  2™+×.Ñ.Ó0�Ø4C�’q˜$×0Ñ0Ð0Ò1à  2™+×.Ñ.Ó0�Ø ¢ L¡MÐ!1Ñ2ˆKÜ# KÓ0ò &‘��3Ø %��a˜�f’ð&ð ˆÜ�w—}‘} QÑ'Ó(ò 	:ˆAØ˜A˜q˜D‘MˆEØ˜!˜Q˜$‘-ˆCÜ$ U¨1¡XÓ.ò :‘��4ÚØ˜D×2Ñ2Ó2ØŸ™¤T¨#¨u°cÀÇÁÈQÁÔ%PÔQØ$×+Ñ+¨F°1°a°4©LÕ9ñ	:ð	:ô !&§¡¨LÓ 9ˆ�‰�HÑØˆr4   c           
      ó’  — |j                   dk(  rt        || j                  ¬«      S | j                  j                  j                  |«      }| j                  j                  j                  |«      }|j                  d¬«      }t        j                  |t        j                  |d«      d¬«      }t        j                  |j                  t        ¬«      }| j                  r#t        j                  ||| j                  k7  «      }| j                   d   }|�'t        j                  |||k\  j#                  «       «      }|s5|j#                  «       dz  j%                  «       }	||	   }||	   }||	   }||	   }t'        «       }
t        || j                  ¬«      }g }t)        |j                  d   «      D ]u  }||   sŒ	||   }||df   }||df   }|s||f|
v rŒ%|
j+                  ||«       |j-                  ||   «       |j-                  t/        |||| j0                  |   ¬«      «       Œw t        j2                  |«      |j4                  d	<   |S )
z$Find the argmax label for each span.r   r  r$   )Úaxisr;   r‘   r=   r  r¾   )rP   r    rp   r'   r+   rä   Úargmaxræ   Útake_along_axisÚexpand_dimsrç   rE   rÇ   rŽ   Úlogical_andr¸   r˜   Úsqueezer
  r}   rc   r„   rC   r   r—   r  r  )r1   rM   r½   r¾   rl   rÔ   Úargmax_scoresr  r‘   Úsort_idxÚseenrK   r  r:   r©   rW   rX   s                    r2   rÈ   z,SpanCategorizer._make_span_group_singlelabelW  s  € ð �;‰;˜!ÒÜ˜S t§x¡xÔ0Ð0Ø—‘—‘×(Ñ(¨Ó0ˆØ—*‘*—.‘.×)Ñ)¨'Ó2ˆØ—M‘M q�MÓ)ˆ	Ü×-Ñ-Ø”E×%Ñ% i°Ó3¸!ô
ˆô —
‘
˜9Ÿ?™?´$Ô7ˆà×"Ò"Ü×%Ñ% e¨Y¸$×:PÑ:PÑ-PÓQˆEà—H‘H˜[Ñ)ˆ	ØÐ Ü×%Ñ% e¨m¸yÑ.H×-QÑ-QÓ-SÓTˆEáà%×-Ñ-Ó/°"Ñ4×=Ñ=Ó?ˆHØ)¨(Ñ3ˆMØ! (Ñ+ˆIØ˜hÑ'ˆGØ˜(‘OˆEÜ‹|ˆÜ˜# D§H¡HÔ-ˆØˆÜ�w—}‘} QÑ'Ó(ò 	JˆAØ˜’8Øà˜a‘LˆEØ˜A˜q˜D‘MˆEØ˜!˜Q˜$‘-ˆCá Ø˜3�< 4Ñ'Øà—H‘H˜U CÔ(Ø×Ñ ¨aÑ 0Ô1Ø�L‰Lœ˜c 5¨#°T·[±[ÀÑ5GÔHÕIð	Jô  !&§¡¨LÓ 9ˆ�‰�HÑØˆr4   )Úspancat)r-   N)T)/r5   r6   r7   rŠ   ry   r#   r   r   r	   r   r   r   r)   r�   rÇ   r
   rì   rè   r   r‚   Úpropertyrp   r¨   r®   r—   r²   r   rµ   r¥   r   r¸   r   r¼   rÅ   rÍ   r!   r   rà   rÛ   r   r   rØ   ré   r   r    rÉ   rÈ   r0   r4   r2   rŒ   rŒ   Å   s‚  „ ñð ðAMð $)Ø Ø+.Ø(,Ø&*Ø%(Ø%2òAMàðAMð �U˜4 ™9 fÐ,Ñ-¨xÐ7Ñ8ðAMð ð	AMð
 ðAMð !ðAMð ðAMð " %™ðAMð   ‘~ðAMð ˜s‘mðAMð ˜E‘?ðAMð ˜Ñ"ðAMð 
óAMðF ð*�Sò *ó ð*óð˜sð  só ð" ð)˜˜c™
ò )ó ð)ð ð!˜D ™Iò !ó ð!ð ðA˜D  c ™Nò Aó ðAð ð$˜3ò $ó ð$ð ð 5¨¨d¨Ñ#3ò ó ðð˜H S™Mó ð  =IòKØ˜S‘MðKØ69ðKà	óKð$) H¨S¡Mð )Àdó )ð@ Ø#'Ø-1ò'à˜7Ñ#ð'ð ð	'ð
 �iÑ ð'ð ˜˜c 5˜jÑ)Ñ*ð'ð 
ˆc�5ˆjÑ	ó'ðR<Ø  Ñ)ð<Ø9>¸vÀxÐ?OÑ9Pð<à	ˆu�eˆ|Ñ	ó<ðD #'Ø&*ò$$à˜r 8¨GÑ#4Ð4Ñ5ð$$ð �hÑð	$$ð
 ˜˜c™Ñ#ð$$ð 
ó$$ðL¨X°gÑ->ó ð
 Wó 
ð
'àð'ð ð'ð ð	'ð
 
ó'ð\ #ñ5àð5ð ð5ð ð	5ð
 ð5ð 
ô5r4   rŒ   c                 óÄ   — | dk(  r!t        j                  d«      }|j                  S | dk(  r!t        j                  d«      }|j                  S t	        dt
        › d| › �«      ‚)NÚmake_spancatzspacy.pipeline.factoriesÚmake_spancat_singlelabelzmodule z has no attribute )Ú	importlibÚimport_moduler   r!  ÚAttributeErrorr5   )r•   Úmodules     r2   Ú__getattr__r&  �  sf   € Øˆ~ÒÜ×(Ñ(Ð)CÓDˆØ×"Ñ"Ð"Ø	Ð+Ò	+Ü×(Ñ(Ð)CÓDˆØ×.Ñ.Ð.Ü
˜7¤8 *Ð,>¸t¸fÐEÓ
FÐFr4   )Cr"  Údataclassesr   Ú	functoolsr   Útypingr   r   r   r   r	   r
   r   r   r   ræ   Ú	thinc.apir   r   r   r   r   r   Úthinc.typesr   r   r   r   Úcompatr   r   Úerrorsr   Úlanguager   r’   r   Útokensr   r   r    Útrainingr!   r"   r“   r#   Útrainable_piper%   Úspancat_default_configÚ"spancat_singlelabel_default_configÚDEFAULT_SPANS_KEYÚfrom_strÚDEFAULT_SPANCAT_MODELÚ!DEFAULT_SPANCAT_SINGLELABEL_MODELr)   rè   rT   r�   r[   r^   rd   rg   ry   r{   r}   rŒ   r&  r0   r4   r2   ú<module>r8     s´  ðÛ Ý !Ý ß T× TÕ Tã ß V× Vß 8Ó 8ç 0Ý Ý Ý ß )Ñ )ß 1Ý Ý )ðÐ ð6&Ð "ð4 Ð Ù›×)Ñ)Ð*@ÓAÀ'ÑJÐ Ù$*£H×$5Ñ$5Ø&ó%à	ñ%Ð !ð
 ôY�ó Yó ðYð
 DHòØ
�3‰-ðØ $ S¡	ðØ3;¸C±=ðàóð< BFòØ
�3‰-ðØ$'ðØ19¸#±ðàóð.1  c¡ð 1¨yó 1ð(¨#ð (¸ð (Àó (ð@¨Cð @°Ió @ð
2˜H WÑ-ð 
2¸DÀÀcÀ¹Nó 
2òð ÷ð ó ðô(G�mô GóVGr4   