Files
INTUIA/Programa final/spacy/cli/__pycache__/find_threshold.cpython-312.pyc
T

117 lines
11 KiB
Plaintext
Raw Normal View History

2026-03-15 13:27:50 +00:00
Ë
=û g…%ãó^ddlZddlZddlZddlmZddlmZmZmZm Z m
Z
ddl Z ddl Z
ddlmZddlmZddlmZmZddlmZd d
lmZmZmZmZmZd d d
dœZej<dd
ddœ¬«edd¬«eddd¬«edd¬«edd¬«edd¬«eedddd¬«eddd d!¬«eed"d#d$d%¬«eed&d'd(d)¬«ed
d*d+d,d-¬«f
d.ed/ed0ed1ed2ede d3e ed"e d&e!d4e!fd5„«Z"eded"ed&dd6œd.ed/ed0ed1ed2ede d"e d&e!d7e!d8e
e#e#ee#e#fffd9„Z$y):éN)ÚPath)ÚAnyÚDictÚListÚOptionalÚTupleé)Úutil)ÚErrors)ÚMultiLabel_TextCategorizerÚTextCategorizer)ÚCorpusé)ÚArgÚOptÚappÚ import_codeÚ setup_gpué éÿÿÿÿF)Ún_trialsÚuse_gpuÚ gold_preproczfind-thresholdT)Úallow_extra_argsÚignore_unknown_options)Úcontext_settings.zModel name or path)Úhelpz3Location of binary evaluation data in .spacy format)rÚexistsz&Name of pipe to examine thresholds forz7Key of threshold attribute in component's configurationzMetric to optimizerz
--n_trialsz-nz0Number of trials to determine optimal thresholdsz--codez-czNPath to Python file with additional code (registered functions) to be importedrz--gpu-idz-gzGPU ID or -1 for CPUrz--gold-preprocz-GzUse gold preprocessingz --verbosez-Vz-VVz/Display more information for debugging purposesÚmodelÚ data_pathÚ pipe_nameÚ
threshold_keyÚ
scores_keyÚ code_pathÚverbosec
ó | r-tjjtj«t |«t
||||||||d¬« y)
Runs prediction trials for a trained model with varying thresholds to maximize
the specified metric. The search space for the threshold is traversed linearly
from 0 to 1 in `n_trials` steps. Results are displayed in a table on `stdout`
(the corresponding API call to `spacy.cli.find_threshold.find_threshold()`
returns all results).
This is applicable only for components whose predictions are influenced by
thresholds - e.g. `textcat_multilabel` and `spancat`, but not `textcat`. Note
that the full path to the corresponding threshold attribute in the config has to
be provided.
DOCS: https://spacy.io/api/cli#find-threshold
F) rr r!r"r#rrrÚsilentN)r
ÚloggerÚsetLevelÚloggingÚDEBUGrÚfind_threshold)
rr r!r"r#rr$rrr%s
úYC:\Users\garci\AppData\Roaming\Python\Python312\site-packages\spacy/cli/find_threshold.pyÚfind_threshold_clir.sIñ@Ü ×ÑœWŸ]™]Ô ÔÜØØØØØØØö
ó)rrrr'r'Úreturnc
óŽt||¬«tj|«}|j«s"tj
j
d|d¬«tj|«} || jvr4ttjj|| j¬««| j|«}
t|
d«sttj«t!|
«t"k(rtj
j%d«|s*tj
j'd|d |d
|d ¬ «t)||¬
«} t+| | ««} |j-d«}
dt.t0t2fdt4t0dt6dt.t0t2ffd}dt.t0t2fdt4t0dt0dt.t0t2ffˆfd ŠiŠd|g|
¢}d}t9j:dd|«}t=tj>jAd|g|¬««|D]_}tj||| jB|djE|««jG«||«¬«} t|
d«r.tI| j|«d|tK|
d«|
|««| jM| «}||vr@tj
j
d|ddt+|jO««d¬ «|||<tQ|t6tRf«s%tj
j
d!|d"d¬«t=t j@tU|d#«tU|d#«g|¬««ŒbtWjO«ˆfd$„¬%«}tYt[j]«««dk(r8tj
j%d&tQ|
t^«r|d'vrd(nd)¬*«n%|s#t=d+tU|d,¬-«d.|d/‰|d«||fS)0a:
Runs prediction trials for models with varying thresholds to maximize the specified metric.
model (Union[str, Path]): Pipeline to evaluate. Can be a package or a path to a data directory.
data_path (Path): Path to file with DocBin with docs to use for threshold search.
pipe_name (str): Name of pipe to examine thresholds for.
threshold_key (str): Key of threshold attribute in component's configuration.
scores_key (str): Name of score to metric to optimize.
n_trials (int): Number of trials to determine optimal thresholds.
use_gpu (int): GPU ID or -1 for CPU.
gold_preproc (bool): Whether to use gold preprocessing. Gold preprocessing helps the annotations align to the
tokenization, and may result in sequences of more consistent length. However, it may reduce runtime accuracy due
to train/test skew.
silent (bool): Whether to print non-error-related output to stdout.
RETURNS (Tuple[float, float, Dict[float, float]]): Best found threshold, the corresponding score, scores for all
evaluated thresholds.
)r'zEvaluation data not foundr)Úexits)ÚnameÚoptsÚscorerz—The `textcat` component doesn't use a threshold as it's not applicable to the concept of exclusive classes. All thresholds will yield the same results.zOptimizing for z for component 'z' with z trials.)Útitle)rúconfigÚkeysÚvaluer0cób|tjtj|dd|«|d<|S)a Set item in nested dictionary. Adapted from https://stackoverflow.com/a/54138200.
config (Dict[str, Any]): Configuration dictionary.
keys (List[Any]): Path to value to set.
value (float): Value to set.
RETURNS (Dict[str, Any]): Updated dictionary.
Nr)Ú functoolsÚreduceÚoperatorÚgetitem)r8r9r:s r-Úset_nested_itemz'find_threshold.<locals>.set_nested_itemƒs4ðKPŒ ×Ñœ×)¨4°°¨9°fÓ=¸dÀ2¹hш
r/Úfull_keyc
ó |d|vrNtjjd|d|dgdd|dgdt|j ««d¬«|dt |«dkDr||d|dd |«iS||diS)
a,Filters provided config dictionary so that only the specified keys path remains.
config (Dict[str, Any]): Configuration dictionary.
keys (List[Any]): Path to value to set.
full_key (str): Full user-specified key.
RETURNS (Dict[str, Any]): Filtered dictionary.
rzFailed to look up `z` in config: sub-key z not found.zMake sure you specified z: correctly. The following sub-keys are available instead: r©r6Útextr2N)ÚwasabiÚmsgÚfailÚlistr9Úlen)r8r9rAÚ
filter_configs €r-rJz%find_threshold.<locals>.filter_configø€ð ‰7˜ Ü J‰JO‰OØ+¨H¨:Ð5JÈDÐQRÉGÈ9È+ÐU`аa±° ¨{Ð:tܘŸ
Óð
ô
ð
‰GÜ4y˜1Š}ñ# 6¨$¨q©'¡?°D¸¸°H¸
ð
ð˜˜Q™ð
ð
r/Ú
components)é
rLrÚ Threshold)Úwidths)r8ÚcfgzFailed to look up score `z` in evaluation results.z`Make sure you specified the correct value for `scores_key`. The following scores are available: rCzReturned score for key 'zG' is not numeric. Threshold optimization only works for numeric scores.écó|S))ÚkeyÚscoress €r-ú<lambda>z find_threshold.<locals>.<lambda>Õs ø€¸Àºr/)rSz?All scores are identical. Verify that all settings are correct.)Ú cats_macro_fÚ cats_micro_fÚz\Use `cats_macro_f` or `cats_micro_f` when optimizing the threshold for `textcat_multilabel`.)r6rDz
Best threshold: é)Úndigitsz with z
value of )0rr
Ú ensure_pathrrErFrGÚ
load_modelÚcomponent_namesÚAttributeErrorr ÚE001ÚformatÚget_pipeÚhasattrÚE1045Útyper
ÚwarnÚinforrHÚsplitrÚstrrrÚfloatÚnumpyÚlinspaceÚprintÚtablesÚrowr8ÚjoinÚcopyÚsetattrÚgetattrÚevaluater9Ú
isinstanceÚintÚroundÚmaxrIÚsetÚvaluesr )rr r!r"r#rrrr'ÚnlpÚpipeÚcorpusÚ dev_datasetÚ config_keysr@Úconfig_keys_fullÚtable_col_widthsÚ
thresholdsÚ thresholdÚ eval_scoresÚbest_thresholdrJrTs @@r-r,r,Gsù€ô:ˆg˜fÕ× Ñ  Ó+€IØ × Ñ Ô Ü
Ð3°YÀaˆÔ
/‰/˜
€Cà˜×Ü K‰K× Ñ  I°C×4GÑ4GÐ Ó 
ð
ð <‰<˜ Ó "€DÜ 4˜Ô œVŸ\™\Ó ˆDƒz”_Ò
ð
Mô
ñ
Ü
Ø# J <Ð/?À ¸{È'ÐRZÐQ[ð\ðð ô
ô I¨LÔ
9€FÜ‘v˜c“{Ó#€KØ×% cÓ*€Kð
Ü”Sœ#Xð
Ü&*¬3¡ið