Files
INTUIA/Programa final/spacy/pipeline/__pycache__/span_finder.cpython-312.pyc
T

178 lines
15 KiB
Plaintext
Raw Normal View History

2026-03-15 13:27:50 +00:00
Ë
>û g-1ãóddlmZmZmZmZmZmZmZddlm Z m
Z
m Z m Z ddl
mZddlmZddlmZddlmZddlmZmZdd lmZdd
lmZd d lmZd d
lmZdZ e «jCe «dZ"ejFddgde"eddddidœdedddedddeddi¬«ded e$de
eeefd!e$d"e%d#ee&d$ee&d%eed&d'fd(„«Z'ejPd«d)„«Z)d*eed&ee$effd+„Z*d,ed&ee&e&ffd-„Z+Gd.„d'e«Z,y)/é)ÚAnyÚCallableÚDictÚIterableÚListÚOptionalÚTuple)ÚConfigÚModelÚ OptimizerÚset_dropout_rate)ÚFloats2dé)ÚErrors)ÚLanguage)ÚScorer)ÚDocÚSpan)ÚExample)Úregistryé)ÚDEFAULT_SPANS_KEY)Ú
TrainablePipeaó
[model]
@architectures = "spacy.SpanFinder.v1"
[model.scorer]
@layers = "spacy.LinearLogistic.v1"
nO = 2
[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
ÚmodelÚ span_finderz doc.spansçà?éNz@scorerszspacy.span_finder_scorer.v1)Ú thresholdrÚ spans_keyÚ
max_lengthÚ
min_lengthÚscorerÚspans_Ú_fgð?Ú_pçÚ_r)ÚassignsÚdefault_configÚdefault_score_weightsÚnlpÚnamerrr r!r"ÚreturnÚ
SpanFinderc
ó(t||||||||¬«S)Create a SpanFinder component. The component predicts whether a token is
the start or the end of a potential span.
model (Model[List[Doc], Floats2d]): A model instance that
is given a list of documents and predicts a probability for each token.
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.
threshold (float): Minimum probability to consider a prediction positive.
max_length (Optional[int]): Maximum length of the produced spans, defaults
to None meaning unlimited length.
min_length (Optional[int]): Minimum length of the produced spans, defaults
to None meaning shortest span length is 1.
scorer (Optional[Callable]): The scoring method. Defaults to
Scorer.score_spans for the Doc.spans[spans_key] with overlapping
spans allowed.
)rrr,r"r r!r)r.)r+r,rrrr r!r"s ú[C:\Users\garci\AppData\Roaming\Python\Python312\site-packages\spacy/pipeline/span_finder.pyÚmake_span_finderr1,s*ôX Ø ØØØ
ØØØØô ð ócótS©N)Úspan_finder_score©r2r0Úmake_span_finder_scorerr7dsä Ðr2Úexamplesc óRt|«}dŠ|dŠ|jd«|jdˆfd«|jdˆfd«|jdd «|jd
d «tj|fi|¤Ž}|j |dd d«|S)
Nr#rÚattrÚgettercóT|jj|t«dg«Sr4)ÚspansÚgetÚlen)ÚdocÚkeyÚ attr_prefixs €r0ú<lambda>z#span_finder_score.<locals>.<lambda>os!ø€ 3§9¡9§=¡=°´S¸Ó5EÐ5GÐ1HÈ"Ô#Mr2Úhas_annotationcó |jvSr4)r=)r@rAs €r0rCz#span_finder_score.<locals>.<lambda>qsø€°C¸3¿9¹9Ñ4Dr2Ú
allow_overlapTÚlabeledFÚ _per_type)ÚdictÚ
setdefaultrÚ score_spansÚpop)r8ÚkwargsÚscoresrBrAs @@r0r5r5iù€Ü
&\€FØ€KØ
Ñ
€CØ
×Ñf  
¨c¨UÐ
×ÑØÓð ×ÑÐ&Ó(DÔ
×Ño 
×Ñi Ô
×
Ñ
 Ñ
3¨FÑ
3€FØ
‡JJ&˜! Ð+¨TÔ €Mr2Úspancód|dj}|djt|d«z}||fS)Nréÿÿÿÿ)Úidxr?)rOÚstartÚends r0Ú
_char_indicesrUys3Ø ‰GK‰K€EØ
ˆr‰(,‰,œ˜T "™XÑ
&€CØ #ˆr2cóDeZdZdZ dedddedœdedeee e
fde de d e d
e
ed e
ed e
ed
dfdZdee fdZdee de
d
dfdZddddœdeede de
ede
ee e fd
ee e ff
dZd
ee e
ffdZd
ee
e
ffdZddœdegeefde
ed
dfdZy) r.zUPipeline that learns span boundaries.
DOCS: https://spacy.io/api/spanfinder
rN)rrr r!r"r+rr,rrr r!r"r-cóØ|j|_||dks|/|dkr*ttjj ||¬««||_||_||_||||dœ|_y)a Initialize the span finder.
model (thinc.api.Model): The Thinc Model powering the pipeline
component.
name (str): The component instance name, used to add entries to the
losses during training.
threshold (float): Minimum probability to consider a prediction
positive.
scorer (Optional[Callable]): The scoring method.
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.
max_length (Optional[int]): Maximum length of the produced spans,
defaults to None meaning unlimited length.
min_length (Optional[int]): Minimum length of the produced spans,
defaults to None meaning shortest span length is 1.
DOCS: https://spacy.io/api/spanfinder#init
Nr)r!r )r!r rr) ÚvocabÚ
ValueErrorrÚE1053Úformatrr,r"Úcfg) Úselfr+rr,rrr r!r"s r0Ú__init__zSpanFinder.__init__…swð<—YYˆŒ
Ø Ð " z°A¢~Ø Ð " z°A¢~äÜ ×#¨zÀjÐð
ðˆŒ
؈Œ ؈Œ à$
ˆr2Údocscó<|jj|«}|S)aApply 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/spanfinder#predict
)rÚpredict)r]r_rNs r0razSpanFinder.predict´sð×# DÓØˆ
r2rNc ó¼d}t|«D]K\}}g|j|jd<g}g}|||t|«z}t ||«D]f\} }
|
d|jdk\r|j | j «|
d|jdk\sŒL|j | j «Œh|D} |D]…} | dz| z
}
|
dkrŒ|jd|jd|
ksŒ3|jd|
|jdksŒU|j|jdj || | dz«Œ‡ŒŽ|t|«z
}ŒNy)aModify a batch of Doc objects, using pre-computed scores.
docs (Iterable[Doc]): The documents to modify.
scores: The scores to set, produced by SpanFinder predict method.
DOCS: https://spacy.io/api/spanfinder#set_annotations
rrrrr!Nr )Ú enumerater=r\r?ÚzipÚappendÚi)r]r_rNÚoffsetrfr@ÚstartsÚendsÚ
doc_scoresÚtokenÚ token_scorerSrTÚ span_lengths r0Úset_annotationszSpanFinder.set_annotationsÀsZðˆÜ —o‰FˆAˆsØ/1ˆCI‰Id—hh˜ ˆF؈DØ ¨´#°c³(Ñ):Ð;ˆJä&)¨#¨zÖ&:Ñ"˜q> T§X¡X¨kÑ%:Ò—MM %§'¡'Ô˜q> T§X¡X¨kÑ%:Ó—KK §¡Õ';ó  ÛCØ"%¨¡'¨E¡/" QØ àŸ ÑŸ8™8 LÑ1°[ÓŸ Ñ&¨$¯(©(°<Ñ*@ÓŸ ™  $§(¡(¨;Ñ"7Ñ8×ÀEÈCÐRSÉGÐ@TÕ ð ð
”c˜#“hÑ ŠFñ3&r2r&)ÚdropÚsgdÚlossesr8rorprqcóx|i}|j|jd«|Dcgc]}|jŒ}}t|j|«|jj |«\}}|j
||«\} }
||
«||j|«||jxx| z
cc<|Scc}w)a?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 (Optional[thinc.api.Optimizer]): The optimizer.
losses (Optional[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/spanfinder#update
r&)rJr,Ú predictedr
rÚ begin_updateÚget_lossÚ
finish_update) r]r8rorprqÚegrsrNÚbackprop_scoresÚlossÚd_scoress r0ÚupdatezSpanFinder.updateãð& ˆ>؈×ј$Ÿ)™) SÔ)Ù,4Ó5©H bR—\“\¨Hˆ ИŸ *Ø"&§*¡*×"9Ñ"9¸)Ó"Dш؟ x°Ó8‰ˆˆhÙ˜Ô ˆ?Ø × Ñ ˜sÔ ˆty‰yÓ˜TÑØˆ
ùò6s¥B7cóî|j||jj«\}}||jjj|«z
}||z}t |dzj ««}||fS)abFind the loss and gradient of loss for the batch of documents and
their predicted scores.
examples (Iterable[Examples]): The batch of examples.
scores: Scores representing the model's predictions.
RETURNS (Tuple[float, Floats2d]): The loss and the gradient.
DOCS: https://spacy.io/api/spanfinder#get_loss
r)Ú_get_aligned_truth_scoresrÚopsÚ asarray2fÚfloatÚsum)r]r8rNÚtruthsÚmasksrzrys r0ruzSpanFinder.get_losssjð×6°xÀÇÁÇÁÓP‰
ˆØ˜DŸJ™JŸN™N×4°VÓ<ˆØˆÜh k×)ˆØXˆr2cóg}g}|D]¸}|jj|jjk7r)ttj
j
d¬««t|j«}|jj|dfd¬«}|jj|dfd¬«}|jd|jjvrÅ|jj|jdD} t| «\}
} |jj!|
| d¬«} t| «\}
}|
|
k(}|| k(}|rd || d
j"d
f<nd