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

174 lines
24 KiB
Plaintext
Raw Normal View History

2026-03-15 13:27:50 +00:00
Ë
>û g
Kãó@ddlZddlZddlmZddlmZddlmZmZm Z m
Z
m Z m Z m
Z
ddlZddlmZmZmZmZddlmZddlmZdd lmZmZdd
lmZmZdd lmZdd l m!Z!dd
l"m#Z#ddl$m%Z%m&Z&ddl'm(Z(m)Z)m*Z*ddlm+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1dZ2dZ3Gdde1«Z4y)éN)Úislice)ÚPath)ÚAnyÚCallableÚDictÚIterableÚListÚOptionalÚUnion)ÚCosineDistanceÚModelÚ OptimizerÚset_dropout_rate)ÚFloats2dé)Úutil)ÚErrorsÚWarnings)Ú CandidateÚ
KnowledgeBase)ÚLanguage)Úempty_kb)ÚScorer)ÚDocÚSpan)ÚExampleÚvalidate_examplesÚvalidate_get_examples)ÚSimpleFrozenList)ÚVocabé)Údeserialize_config)Ú
TrainablePipeTc óPtj|fdtjgi|¤ŽS)negative_labels)rÚ score_linksÚEntityLinker_v1ÚNIL)ÚexamplesÚkwargss údC:\Users\garci\AppData\Roaming\Python\Python312\site-packages\spacy/pipeline/legacy/entity_linker.pyÚentity_linker_scorer,s'Ü × Ñ ˜ ×9LÑ9LÐ8MÐ XÐQWÑ có"eZdZdZdZ d0eedœdedede de
e de d e d
e d e d e
eege
efd
e dee
ddfdZde
egeffdZd1dZdddœde
ge
efdeedee
egeffdZddddœde
ededeedeee efdee eff
dZde
ed efd!„Zd"e
edee fd#„Z d"e
ed$ee ddfd%„Z!e"«d&œd'„Z#e"«d&œd(„Z$e%«d&œd)e&e e'fd*e
e ddfd+„Z(e%«d&œd)e&e e'fd*e
e ddfd,„Z)ddd-œd.„Z*d/„Z+y)2r'z^Pipeline component for named entity linking.
DOCS: https://spacy.io/api/entitylinker
r()Ú overwriteÚscorerÚvocabÚmodelÚnameÚlabels_discardÚn_sentsÚ
incl_priorÚ incl_contextÚentity_vector_lengthÚget_candidatesr/r0ÚreturnNcó||_||_||_t|«|_||_||_||_| |_d|
i|_ td¬«|_ t|«|j«|_
| |_y)aInitialize an entity linker.
vocab (Vocab): The shared vocabulary.
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.
labels_discard (Iterable[str]): NER labels that will automatically get a "NIL" prediction.
n_sents (int): The number of neighbouring sentences to take into account.
incl_prior (bool): Whether or not to include prior probabilities from the KB in the model.
incl_context (bool): Whether or not to include the local context in the model.
entity_vector_length (int): Size of encoding vectors in the KB.
get_candidates (Callable[[KnowledgeBase, Span], Iterable[Candidate]]): Function that
produces a list of candidates, given a certain knowledge base and a textual mention.
scorer (Optional[Callable]): The scoring method. Defaults to Scorer.score_links.
DOCS: https://spacy.io/api/entitylinker#init
r/F)Ú normalizeN)r1r2r3Úlistr4r5r6r7r9Úcfgr ÚdistancerÚkbr0) Úselfr1r2r3r4r5r6r7r8r9r/r0s r+Ú__init__zEntityLinker_v1.__init__+s}ð>ˆŒ
؈Œ
؈Œ Ü" Ô؈Œ ØŒØÔØÔØ$/°Ð#;ˆŒÜÔ7ˆŒ
ð1”(з±ÓŒØˆ r-Ú kb_loadercó¬t|«s2ttjj t |«¬««||j «|_y)ziDefine the KB of this pipe by providing a function that will
create it using this object's vocab.)Úarg_typeN)ÚcallableÚ
ValueErrorrÚE885ÚformatÚtyper1r@)rArCs r+Úset_kbzEntityLinker_v1.set_kbYs=ô˜ ÔœVŸ[™[׸i»Ð ˜DŸJ™JÓ'ˆr-có|j€3ttjj |j
¬««t
|j«dk(r3ttjj |j
¬««y)r3r)r@rGrÚE1018rIr3ÚlenÚE139©rAs r+Ú validate_kbzEntityLinker_v1.validate_kbasbà 7‰7ˆœVŸ\™\×0°d·i±iÐ ˆtw‰w<˜ ÜœVŸ[™[×/°T·Y±YÐ  r-)ÚnlprCÚ get_examplesrScóØt|d«||j|«|j«|jj}g}g}t |«d«D]Q}|j
|j«|j
|jjj|««ŒSt|«dkDs/Jtjj|j¬««t|«dkDs/Jtjj|j¬««|jj!||jjj#|d¬«¬«y) 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 (Language): The current nlp object the component is part of.
kb_loader (Callable[[Vocab], KnowledgeBase]): A function that creates an InMemoryLookupKB from a Vocab instance.
Note that providing this argument, will overwrite all data accumulated in the current KB.
Use this only when loading a KB as-such from file.
DOCS: https://spacy.io/api/entitylinker#initialize
zEntityLinker_v1.initializeNé
rrMÚfloat32)Údtype)ÚY)rrKrRr@r8rÚappendÚxr2ÚopsÚalloc1frOrÚE923rIr3Ú
initializeÚasarray)rArTrSrCÚnOÚ
doc_sampleÚ
vector_sampleÚexamples r+r`zEntityLinker_v1.initializehsô& ˜lÐ,HÔ Ð Ø K‰K˜ Ô  ×ÑÔØ
W‰W×
)ˆØˆ
؈
Ü™l›n¨bÖ1ˆGØ × Ñ ˜gŸi™iÔ × Ñ  §¡§¡×!7Ñ!7¸Ó!;Õ : ÒF¤F§K¡K×$6Ñ$6¸D¿I¹IÐ$6Ó$FÓ! I¤v§{¡{×'9Ñ'9¸t¿y¹yÐ'9Ó'IÓ
×ÑØ˜DŸJ™JŸN™N×2°=È Ð õ
r-ç)ÚdropÚsgdÚlossesr)rgrhricól|j«|i}|j|jd«|s|St|d«g}|D] }|jj
Dcgc]}|Œ}}|j
dd¬«} |jjD}
| |
j} | sŒ |j|
j«} td| |j z
«}
t#t%|«dz
| |j z«}||
j}||j&}|j(||j+«}|j-|«Œ¼Œt/|j0|«|s5t3j4t6j8j;d ¬
««|S|j0j=|«\}}|j?||¬ «\}}||«||jA|«||jxx|z
cc<|Scc}w#t$rttj«dwxYw) 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 (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/entitylinker#update
NrfzEntityLinker_v1.updateÚ ENT_KB_IDT©Ú as_stringréz
Entity LinkerrM)Úsentence_encodingsr))!rRÚ
setdefaultr3rÚ referenceÚsentsÚ get_alignedÚentsÚstartÚindexÚsentÚAttributeErrorÚ RuntimeErrorrÚE030Úmaxr5ÚminrOÚendÚ predictedÚas_docr[rr2ÚwarningsÚwarnrÚW093rIÚ begin_updateÚget_lossÚ
finish_update)rAr)rgrhriÚ
sentence_docsÚegÚsÚ sentencesÚkb_idsÚentÚkb_idÚ
sent_indexÚstart_sentenceÚ end_sentenceÚ start_tokenÚ end_tokenÚsent_docroÚ
bp_contextÚlossÚd_scoress r+ÚupdatezEntityLinker_v1.updatesð(
×ÑÔØ ˆ>؈FØ×ј$Ÿ)™) SÔØˆMܘ(Ð$<Ôˆ
܈BØ$&§L¡L×$6Ò$6Ó7Ñ$6˜Ð$6ˆ—^^ K¸4@ˆFØ—|‘|×(à˜sŸy™yÑ)ÚðBà%.§_¡_°S·X±XÓ%>˜
ô
&)¨¨J¸¿¹Ñ,EÓ%FNä#&¤s¨9£~¸Ñ'9¸Ï É Ñ;TÓ#ULà"+¨NÑ";×"AÑ"AKØ )¨,Ñ 7× ;Ñ ;!Ÿ|™|¨K¸ ÐB×K!×Õ2ò'ô. ˜Ÿ TÔÜ M‰Mœ(Ÿ-™-×.°OÐ ˆMØ)-¯©×)@Ñ)@ÀÓ)OјŸØ1¸
ˆˆhñ Ø ˆ?Ø × Ñ ˜sÔ ˆty‰yÓ˜TÑØˆ
ùòE8øôBä*¬6¯;©;Ó7¸BúsÁ! H
Â+HÈ$H3rocó~t|d«g}|D]n}|jdd¬«}|jjD]@}||j}|sŒ|j
j
|«}|j|«ŒBŒp|jjj|«}|j|jk7r,tjjdd¬«} t| «|j j#||«}
|j j%||«} | t'|«z } t)| «|
fS)NzEntityLinker_v1.get_lossrkTrlr„zgold entities do not match up©ÚmethodÚmsg)rrsrqrtrur@Ú
get_vectorr[r2r]Ú asarray2fÚshaperÚE147rIryr?Úget_gradr„rOÚfloat) rAr)roÚentity_encodingsr‡rÚentity_encodingÚerrÚ gradientsr”s r+r„zEntityLinker_v1.get_lossÌs"ܘ(Ð$>ÔÐÛˆ—^‘^ K¸4@ˆFØ—|‘|×(ؘsŸy™yÑ)ÚØ&*§g¡g×&8Ñ&8¸Ó&?$×+¨OÕð Ÿ:™:Ÿ>™>×3Ð4DÓØ × #Ð'7×'=Ñ'=Ò —++×!Ð'Fðˆ˜sÓ —M‘M×*Ð+=Ð?OÓPˆ Ø}‰}×%Ð&8Ð:JÓKˆØ”cÐÜT{˜%r-Údocscó|j«d}g}|s|St|t«r|g}t|«D\}}|jDcgc]}|Œ}}t |«dkDsŒ/|j D]E}|j} |j| «}
|
dk\sJtd|
|jz
«} tt |«dz
|
|jz«} || j}
|| j}||
|j«}|jj j"}|j$rF|jj'|g«d}|j(}|j*j-|«}|dz
}|j.|j0vr|j3|j4«ŒCt7|j9|j:|««}|s|j3|j4«Œ‡t |«dk(r |j3|dj<«Œµt?j@|«|jC|Dcgc]}|jDŒc}«}|jFs|jC|Dcgc]}dŒc}«}|}|j$rÜ|jC|Dcgc]}|jHŒc}«}|j*j-|d¬«}t |«t |«k7r*tKtLjNjQdd¬««|jS|«|zz }|jT|jTk7rtWtLjX«||z||zz
}|j[«j]«}||}|j3|j<«ŒHŒ†t |«|k(s,tLjNjQdd¬«}tK|«|Scc}wcc}wcc}wcc}w) apApply the pipeline's model to a batch of docs, without modifying them.
Returns the KB IDs for each entity in each doc, including NIL if there is
no prediction.
docs (Iterable[Doc]): The documents to predict.
RETURNS (List[str]): The models prediction for each document.
DOCS: https://spacy.io/api/entitylinker#predict
rrnrf)ÚaxisÚpredictzvectors not of equal lengthr˜z$result variables not of equal length)/rRÚ
isinstancerÚ enumeraterrrOrtrwrvr{r5r|rur}rr2r]Úxpr7ÚlinalgÚnormÚlabel_r4r[r(r=r9r@Úentity_ÚrandomÚshuffleraÚ
prior_probr6Ú
entity_vectorryrrIÚdotrrGÚE161ÚargmaxÚitem)rAÚ entity_countÚ final_kb_idsÚdocrˆr‰rrwrrrrrÚsentence_encodingÚsentence_encoding_tÚ
sentence_normÚ
candidatesÚ prior_probsÚscoresr¡Ú entity_normÚsimsÚ
best_indexÚbest_candidater£s r+zEntityLinker_v1.predictás™ð
×ÑÔØˆ Ø"$ˆ ÙØÐ Ü dœCÔ Ø6ˆDÜ —o‰FˆAˆsØ$'§I¢IÓ.¡I˜ Iˆ3x˜!Ÿ88Ÿ8™8DØ!*§¡°Ó!6š?Ð*˜?ä%(¨¨J¸¿¹Ñ,EÓ%FNÜ#&¤s¨9£~¸Ñ'9¸Ï É Ñ;TÓ#ULØ"+¨NÑ";×"AÑ"AKØ )¨,Ñ 7× ;Ñ ;" ;¨yÐ9×BŸŸ×*×(Ø,0¯J©J×,>Ñ,>À¸zÓ,JÈ1Ñ,MÐ)Ø.?×.AÑ.AÐ+Ø(*¯ © ¯©Ð7JÓ(K˜
Ø  %—zz T×%8Ñ%8Ñ$×+¨D¯H©HÖ5ä%)¨$×*=Ñ*=¸d¿g¹gÀsÓ*KÓ%L˜
Ù·±Ö  ›_°Ò
¸
×0EÑ0EÖ"ŸN™N¨:Ô6à*,¯*©*ÉJÓ5WÉJÀq°a·l³lÈJÑ5WÓ*X˜KØ#'§?¢?Ø.0¯j©jÁzÓ9RÁzÀ!º#ÀzÑ9RÓ.S  Ø%0˜#×0Ø35·:±:Ù>HÓ$I¹j¸ Q§_£_¸jÑ$Ió4"Ð 0ð/1¯i©i¯n©nÐ=MÐTU¨nÓ.V  Ü#&Ð'7Ó#8¼CÀ Ó<LÒ#LÜ*6Ü(.¯ © ×(:Ñ(:Ø3<Ø0Mð);ó)*ó+&ð%&ð(*§v¡vÐ.>Ð@SÓ'TØ$1°KÑ$?ñ(" ð$(§:¡:°×1BÑ1BÒ#BÜ*4´V·[±[Ó*AÐ$AØ)4°tÑ);¸{ÈTÑ?QÑ)R Ø)/¯©«×)=Ñ)=Ó)?˜JØ-7¸
Ñ-C˜(××0FÑ0FÖGòs&ô|! —++× Ð&LðˆCô˜sÓ ÐùòE/ùòD6Xùâ9Rùò
%JsÁ O:É O? Ê P Ê-P cót|Dcgc]}|jD]}|ŒŒc}}«}|t|«k7r3ttjj |t|«¬««d}|j d}|D]=}|jD],}||}|dz
}|D]} | jdk(s|sŒ|| _ŒŒ.Œ?ycc}}w)aModify a batch of documents, using pre-computed scores.
docs (Iterable[Doc]): The documents to modify.
kb_ids (List[str]): The IDs to set, produced by EntityLinker.predict.
DOCS: https://spacy.io/api/entitylinker#set_annotations
)rtÚidsrr/rnN) rOrtrGrÚE148rIr>Ú ent_kb_idÚ
ent_kb_id_)
rArÚ
count_entsr»r/Útokens
r+Úset_annotationszEntityLinker_v1.set_annotations7ô©Ô #¸¿¼°#š#¸˜#¨Ò
Ø œ˜V›Ò œVŸ[™[×/°ZÄSÈÃ[Ð
ˆØ—H‘H˜[Ñ)ˆ ÛˆCØ—x”xؘq™ ØQ‘Û ¨!Ò+ªyØ+0˜Õ ñùó CsC
©Úexcludecó j«i}td«rjˆfd|d<ˆˆfd|d<jj|d<j
j|d<t
j|«S)zéSerialize the pipe to a bytestring.
exclude (Iterable[str]): String names of serialization fields to exclude.
RETURNS (bytes): The serialized object.
DOCS: https://spacy.io/api/entitylinker#to_bytes