Files
INTUIA/Programa final/spacy/tokens/__pycache__/_serialize.cpython-312.pyc
T

134 lines
18 KiB
Plaintext
Raw Normal View History

2026-03-15 13:27:50 +00:00
Ë
?û g
0ãó,ddlZddlmZddlmZmZmZmZmZm Z m
Z
ddl Z ddl Z ddl m
Z
ddlmZddlmZmZmZmZddlmZdd lmZdd
lmZmZdd lmZd d
lmZd dl m!Z"d dl m#Z#Gdd«Z$dZ%dZ&dZ'ejPe$e&e'«e$Z)dgZ*y)éN)ÚPath)ÚDictÚIterableÚIteratorÚListÚOptionalÚSetÚUnion)Úndarray)ÚNumpyOpsé)ÚIDSÚORTHÚSPACYÚ intify_attr)Úcopy_reg)ÚErrors)ÚSimpleFrozenListÚ ensure_path)ÚVocabé)Ú
SpanGroups)ÚDOCBIN_ALL_ATTRS)ÚDocc óÐeZdZdZede«fdeededee ddfdZ
de fd „Z d
e ddfd Z
d edee fd
ZddZdefdZdeddfdZdeeefddfdZdeeefddfdZy)ÚDocBinaÕPack Doc objects for binary serialization.
The DocBin class lets you efficiently serialize the information from a
collection of Doc objects. You can control which information is serialized
by passing a list of attribute IDs, and optionally also specify whether the
user data is serialized. The DocBin is faster and produces smaller data
sizes than pickle, and allows you to deserialize without executing arbitrary
Python code.
The serialization format is gzipped msgpack, where the msgpack object has
the following structure:
{
"attrs": List[uint64], # e.g. [TAG, HEAD, ENT_IOB, ENT_TYPE]
"tokens": bytes, # Serialized numpy uint64 array with the token data
"spans": List[Dict[str, bytes]], # SpanGroups data for each doc
"spaces": bytes, # Serialized numpy boolean array with spaces data
"lengths": bytes, # Serialized numpy int32 array with the doc lengths
"strings": List[str] # List of unique strings in the token data
"version": str, # DocBin version number
}
Strings for the words, tags, labels etc are represented by 64-bit hashes in
the token data, and every string that occurs at least once is passed via the
strings object. This means the storage is more efficient if you pack more
documents together, because you have less duplication in the strings.
A notable downside to this format is that you can't easily extract just one
document from the DocBin.
attrsÚstore_user_dataÚdocsÚreturnNcór|Dcgc]
}t|«Œ}}d|vrY|Dcgc]}t|«Œ|Œ}}ttjj d|t j «¬««dt|«}d|_|Dcgc]}|tk7sŒ
|tk7sŒ|Œc}|_ |jjdt«g|_
g|_g|_g|_g|_g|_t'«|_||_|D]}|j-|«Œycc}wcc}wcc}w)a~Create a DocBin object to hold serialized annotations.
attrs (Iterable[str]): List of attributes to serialize. 'orth' and
'spacy' are always serialized, so they're not required.
store_user_data (bool): Whether to write the `Doc.user_data` to bytes/file.
docs (Iterable[Doc]): Docs to add.
DOCS: https://spacy.io/api/docbin#init
Nr)ÚdictÚkeyÚkeysz0.1r)rÚKeyErrorrÚE983Úformatrr$ÚsortedÚversionrrrÚinsertÚtokensÚspacesÚcatsÚ span_groupsÚ user_dataÚflagsÚsetÚstringsrÚadd)ÚselfrrrÚattrÚ int_attrsÚ non_validÚdocs úXC:\Users\garci\AppData\Roaming\Python\Python312\site-packages\spacy/tokens/_serialize.pyÚ__init__zDocBin.__init__4sñ49Ó9±5¨4”[ Õ&°5ˆ Ð  Ù*/ÓM©% $´;¸tÓ3DÑ3Lš¨%ˆÜ ×°YÄSÇXÁXÃZÐàð
ô؈Œ Ù',ÓO¡u˜t°¼³ ÀÌÃ’d uÑŒ
Ø
×ј!œTÔ"Ø%'ˆŒ Ø%'ˆŒ Ø "ˆŒ Ø(*ˆÔØ02ˆŒØ!#ˆŒ
Ü!$£ˆŒ ØÔÛˆCØ H‰HSùò%:ùâMùò Ps!D*¡D/²D/ D4 D4Â%D4có,t|j«S)z7RETURNS: The number of Doc objects added to the DocBin.)Úlenr+)r4s r9Ú__len__zDocBin.__len__Xsä4—;Ðór8có|j|j«}t|j«dk(r |j |jddf«}|j
j
|«|jt«}|jd|jdk(sJ|j |jddf«}|jj
tj|t¬««|jj
d|ji«|D]Y}|jj|j «|jj|j"«|jj|j$«|jj|j&«|jjt)|j*««|jj|j,«|jj|j.«|jj|j0«|jj|j2«Œ\|j4j
|j4«|j6r8|j8j
t;j<|j8««|j>j
|j@jC««|j@jE«D\}}|D}|jj|jF«|jH|jJjLjvr%|jj|jN«|jP|jJjLjvsŒ¦|jj|jR«ŒÌŒÖy)zAdd a Doc's annotations to the DocBin for serialization.
doc (Doc): The Doc object to add.
DOCS: https://spacy.io/api/docbin#add
rr©ÚdtypeÚhas_unknown_spacesN)*Úto_arrayrr<ÚshapeÚreshaper+Úappendrr,ÚnumpyÚasarrayÚboolr0rBr2r3ÚtextÚtag_Úlemma_Únorm_ÚstrÚmorphÚdep_Ú ent_type_Ú
ent_kb_id_Úent_id_r-rr/ÚsrslyÚ
msgpack_dumpsr.ÚspansÚto_bytesÚitemsÚlabel_Úkb_idr8ÚvocabÚkb_id_ÚidÚid_)r4r8Úarrayr,Útokenr#ÚgroupÚspans r9r3z
DocBin.add\ð ˜TŸZ™ZÓÜ ˆu{‰{Ó ˜qÒ Ø—MM 5§;¡;¨q¡>°1Ð"5Ó6ˆ ×ј5ÔœeÓØ{‰{˜1‰~ §¡¨a¡Ò §¡¨a¡°!Ð 4ÓØ ×Ñœ5Ÿ=™=¨´tÔ
×ÑÐ×1GÑ1GЈEØ L‰L× Ñ ˜UŸZ™ZÔ L‰L× Ñ ˜UŸZ™ZÔ L‰L× Ñ ˜UŸ\™\Ô L‰L× Ñ ˜UŸ[™[Ô L‰L× Ñ œS §¡Ó L‰L× Ñ ˜UŸZ™ZÔ L‰L× Ñ ˜UŸ_™_Ô L‰L× Ñ ˜U× L‰L× Ñ ˜UŸ]™]Ö ð
‰ ×јŸÔ × Ò Ø N‰N× !¤%×"5Ñ"5°c·m±mÓ"DÔ  ×Ñ×Ñ § ¡ × 2Ñ 2Ó 4ÔŸ)™)Ÿ/™/Ö+‰JˆCÛØ × Ñ  §¡Ô—:‘: §¡§¡×!7Ñ!7Ñ—L‘L×$ T§[¡[Ô—7‘7˜dŸh™hŸn™n×—L‘L×$ T§X¡XÕ ñ,r>r[c#ó‚K|jD]}||Œ |jjt«}t t |j ««D]d}|j|}|j |}|j|}|jd«rd}t||dd|f|¬«}|j|j|«}|j||_ |j|rI|j|tjk7r)|j j#|j|«n|j j%«|t |j&«krN|j&|?t)j*|j&|d¬«} |j&j-| «|Œgy­w)aaRecover Doc objects from the annotations, using the given vocab.
Note that the user data of each doc will be read (if available) and returned,
regardless of the setting of 'self.store_user_data'.
vocab (Vocab): The shared vocab.
YIELDS (Doc): The Doc objects.
DOCS: https://spacy.io/api/docbin#get_docs
rBN)Úwordsr,F)Úuse_list)r2rÚindexrÚranger<r+r0r,ÚgetrÚ
from_arrayr-r.rÚ _EMPTY_BYTESrVÚ
from_bytesÚclearr/rTÚ
msgpack_loadsÚupdate)
r4r[ÚstringÚorth_colÚir0r+r,r8r/s
r9Úget_docszDocBin.get_docss^èø€ð—l”lˆ &—::×#¤DÓ)ˆÜ”s˜4Ÿ;™;Ó(ˆ—JJ˜qMˆ—[‘[ ‘^ˆFØ(,¯ © °A©ˆFØy‰yÐÜe 6ª!¨X¨+Ñ#6¸vÔFˆCØ—.‘. §¡¨VÓ4ˆCØ—y‘y ‘|ˆCŒHà×Ñ Ò" t×'7Ñ'7¸Ñ':¼j×>UÑ>UÒ'UØ ×$ T×%5Ñ%5°aÑ%8ÕÔ”3t—~&¨4¯>©>¸!Ñ+<Ð+HÜ!×·±¸qÑ0AÈEÔR Ø
×$ ŒIñ#)ùsF=F?cój|j|jk7r?ttjj d|j|j¬««|j
|j
k7r?ttjj d|j
|j
¬««|j j|j «|jj|j«|jj|j«|jj|j«|jj|j«|jj|j«|jj|j«y)abExtend the annotations of this DocBin with the annotations from
another. Will raise an error if the pre-defined attrs of the two
DocBins don't match, or if they differ in whether or not to store
user data.
other (DocBin): The DocBin to merge into the current bin.
DOCS: https://spacy.io/api/docbin#merge
r)ÚparamÚcurrentÚotherrN)rÚ
ValueErrorrÚE166r'rr+Úextendr,r2rnr-r.r0r/)r4rvs r9Úmergez DocBin.merge¢s1ð :‰:˜ŸÒ Ü ×¸$¿*¹*ÈEÏKÉKÐð
ð × Ñ  5×#8Ñ#8Ò Ü × ××óð
ð
×ј5Ÿ<™<Ô ×ј5Ÿ<™<Ô ×јEŸM™MÔ ‰ ×јŸÔ ×Ñ×Ñ × 1Ñ 1Ô
×ј%Ÿ+™+Ô ×јeŸo™oÕ.r>c
ó‚|jD]+}t|j«dk(rŒJ|j«|jDcgc]
}t|«Œ}}|jrtj|j«ntj
g«}|j rtj|j «ntj
g«}|j|j|jd«|jd«tj
|d¬«jd«tt|j««|j|j|jdœ }|j r|j"|d<t%j&t)j*|««Scc}w)z¡Serialize the DocBin's annotations to a bytestring.
RETURNS (bytes): The serialized DocBin.
DOCS: https://spacy.io/api/docbin#to_bytes
r
Úint32r@) r)rr+r,Úlengthsr2r-r0r.r/)r+r<rDrGÚvstackrHr,r)rÚtobytesÚlistr(r2r-r0r.rr/ÚzlibÚcompressrTrU)r4r+r~r,Úmsgs r9rWzDocBin.to_bytesÀs:ð—k”kˆFÜv—|‘|ÓÓ 7¨6¯<©<Ó "à-1¯[ª[Ó9©[ 6”3v•;¨[ˆÐ9Ø.2¯kªk”˜dŸk™kÔ*¼u¿}¹}ÈRÓ?PˆØ.2¯kªk”˜dŸk™kÔ*¼u¿}¹}ÈRÓ?Pˆà—|‘|Ø—Z‘ZØ—n‘n SÓ—n‘n —}} W°GÔ<×DÀSÓœF 4§<¡<Ó—I—Z‘ZØ×

ˆð × Ò Ø#Ÿ~™~ˆC Ñ Ü}‰}œU×Ó6ùò!:sÁ F<Ú
bytes_datacód tjtj|««}|d|_t|d«|_
tj|dd¬«}tj|dt¬«}tj|dd¬«}|jt|j«zt|j«f}|j!|«}|j!|jd f«}t#«j%||«|_t#«j%||«|_|d
|_|j-d |Dcgc]}d Œc}«|_|j-d
|Dcgc]}iŒc}«|_d|vrt3|d«|_ndgt|«z|_|j&D]+}t|j6«dk(rŒJ|j6«|S#tj$rt t j«wxYwcc}wcc}w)z×Deserialize the DocBin's annotations from a bytestring.
bytes_data (bytes): The data to load from.
RETURNS (DocBin): The loaded DocBin.
DOCS: https://spacy.io/api/docbin#from_bytes
rr2r~r}r@r,r+Úuint64rr-r.r>r0r/Nr
)rTrmrÚ