
    hg                        S SK JrJrJrJrJr  S SKJrJr  S SK	J
r
  S SKJr  S SKJr  \\" 5       SSSS.S	\\   S
\S\\
\/\4   S\\   S\S\\   S\\   S\\\4   4S jjrS	\\   S\\\4   4S jrS rS	\\   S\\\4   4S jrS rg)    )AnyCallableDictIterableOptional)PRFScoreROCAUCScore)Doc)Example)SimpleFrozenListTN)getterlabelsmulti_labelpositive_label	thresholdexamplesattrr   r   r   r   r   returnc                   Uc  U(       a  SOSnU Vs0 s H  o[        5       _M     n	nU Vs0 s H  o[        5       _M     n
n[        U5      nU(       ao  U  Hi  nUR                  UR                  R
                  R                  5       5        UR                  UR                  R
                  R                  5       5        Mk     U  GHN  nU" UR                  U5      nU" UR                  U5      nU HO  nUR                  US5      nUR                  U5      nU(       d	  U(       d  SnUc  M;  X   R                  UU5        MQ     U(       a  U H  nUR                  US5      nUR                  U5      nUc  M+  X:  a  US:  a  X   =R                  S-  sl
        MO  X:  a  US:X  a  X   =R                  S-  sl        Ms  X:  d  Mz  US:  d  M  X   =R                  S-  sl        M     GM(  U(       a  U(       a  [        UR                  5       S S9u  nn[        UR                  5       S S9u  nnUU:X  a   X:  a  U	U   =R                  S-  sl
        GM  U	U   =R                  S-  sl        X:  a  U	U   =R                  S-  sl        GM  GM  U(       a2  [        US	 S9u  nnUS:  a  U	U   =R                  S-  sl        GM  GM  U(       d  GM  [        UR                  5       S
 S9u  nnX:  d  GM6  U	U   =R                  S-  sl        GMQ     [        5       nU	R                  5        H`  nU=R                  UR                  -  sl
        U=R                  UR                  -  sl        U=R                  UR                  -  sl        Mb     [!        U	5      S-   n[#        S U	R                  5        5       5      U-  n[#        S U	R                  5        5       5      U-  n[#        S U	R                  5        5       5      U-  n[#        S U
R                  5        5       5      U-  nU S3SU S3SU S3UR$                  U S3UR&                  U S3UR(                  U S3UU S3UU S3UU S3UU S3U	R                  5        VVs0 s H  u  nnUUR+                  5       _M     snnU S3U
R                  5        VVs0 s H*  u  nnUUR-                  5       (       a  UR.                  OS_M,     snn0n[!        U5      S:X  a2  U(       d+  U(       a$  UU S3   U   S   nUUU S3'   SU S3UU S3'   U$ U(       d  UU S3   UU S3'   SUU S3'   U$ UU S3   UU S3'   S UU S3'   U$ s  snf s  snf s  snnf s  snnf )!aO  Returns PRF and ROC AUC scores for a doc-level attribute with a
dict with scores for each label like Doc.cats. The reported overall
score depends on the scorer settings.

examples (Iterable[Example]): Examples to score
attr (str): The attribute to score.
getter (Callable[[Doc, str], Any]): Defaults to getattr. If provided,
    getter(doc, attr) should return the values for the individual doc.
labels (Iterable[str]): The set of possible labels. Defaults to [].
multi_label (bool): Whether the attribute allows multiple labels.
    Defaults to True. When set to False (exclusive labels), missing
    gold labels are interpreted as 0.0.
positive_label (str): The positive label for a binary task with
    exclusive classes. Defaults to None.
threshold (float): Cutoff to consider a prediction "positive". Defaults
    to 0.5 for multi-label, and 0.0 (i.e. whatever's highest scoring)
    otherwise.
RETURNS (Dict[str, Any]): A dictionary containing the scores, with
    inapplicable scores as None:
    for all:
        attr_score (one of attr_micro_f / attr_macro_f / attr_macro_auc),
        attr_score_desc (text description of the overall score),
        attr_micro_p,
        attr_micro_r,
        attr_micro_f,
        attr_macro_p,
        attr_macro_r,
        attr_macro_f,
        attr_macro_auc,
        attr_f_per_type,
        attr_auc_per_type
Ng      ?        r      c                     U S   $ Nr    its    N/home/james-whalen/.local/lib/python3.13/site-packages/spacy_legacy/scorers.py<lambda>score_cats_v1.<locals>.<lambda>U       2a5    )keyc                     U S   $ r   r   r   s    r   r   r   V   r    r!   c                     U S   $ r   r   r   s    r   r   r   ^   s    2a5r!   c                     U S   $ r   r   r   s    r   r   r   b   r    r!   g0.++c              3   8   #    U  H  oR                   v   M     g 7fN)	precision.0prfs     r   	<genexpr> score_cats_v1.<locals>.<genexpr>k   s     ?+>C--+>   c              3   8   #    U  H  oR                   v   M     g 7fr'   )recallr)   s     r   r,   r-   l        <(;**(;r.   c              3   8   #    U  H  oR                   v   M     g 7fr'   )fscorer)   s     r   r,   r-   m   r1   r.   c              3   f   #    U  H'  oR                  5       (       a  UR                  OS v   M)     g7f)r   N)	is_binaryscore)r*   aucs     r   r,   r-   q   s#     S=RcCIIc1=Rs   /1_score_score_desc_micro_p_micro_r_micro_f_macro_p_macro_r_macro_f
_macro_auc_f_per_type_auc_per_type   fzF ()zmacro Fz	macro AUC)r   r	   setupdate	predictedcatskeys	referenceget	score_settpfpfnmaxitemsvalueslensumr(   r0   r3   to_dictr5   r6   )r   r   r   r   r   r   r   cfglabel
f_per_typeauc_per_typeegexample	pred_cats	gold_cats
pred_score
gold_score
pred_label
gold_label	micro_prf	label_prfn_catsmacro_pmacro_rmacro_f	macro_auckvresultspositive_label_fs                                 r   score_cats_v1rn      s|   V &CC	178#J86<=fU;=(fL=[FBMM",,++0023MM",,++0023  7,,d3	7,,d3	E"uc2J"u-Jk 
%#--j*E  &]]5#6
&]]51
)!.:>"),,1,#0Z1_"),,1,#/JN"),,1,   9%():@P%Q"J
%():@P%Q"J
Z'J,C:&))Q.)):&))Q.)*z*--2-- +%(8H%I"J
A~:&))Q.)) Y%():@P%Q"J
&:&))Q.))Q R 
I&&(		$	$	$ ) _v%F?:+<+<+>??&HG<
(9(9(;<<vEG<
(9(9(;<<vEG 	S\=P=P=RSS
	 
 &&d&9..&9++&9++&7&7&7&
Y&*:J:J:LM:L$!Qq!))+~:LM&>J>P>P>R!
>RdaA!++--qwwT1>R!
G 6{a"dV;#78HM#34& *-n-=Q(?4&$% N #*dV8+<#=4& (14&$% N $+dV:+>#?4& (34&$%Nq 9=P N!
s   U9U>V,1V	0c                      [        U S4SS0UD6$ )NrI   r   Frn   r   kwargss     r   textcat_score_v1rs      s)      	 r!   c                      [         $ r'   )rs   r   r!   r   make_textcat_scorer_v1ru      s    r!   c                      [        U S4SS0UD6$ )NrI   r   Trp   rq   s     r   textcat_multilabel_score_v1rw      s+       	 r!   c                      [         $ r'   )rw   r   r!   r   !make_textcat_multilabel_scorer_v1ry      s    &&r!   )typingr   r   r   r   r   spacy.scorerr   r	   spacy.tokensr
   spacy.trainingr   
spacy.utilr   getattrstrboolfloatrn   rs   ru   rw   ry   r   r!   r   <module>r      s    : : .  " ' )0,.$(!%EwE
E c3Z_%	E
 SME E SME E 
#s(^EPx0 tCH~ w	#s(^'r!   