
    h$                     &   S SK r S SKJr  S SKJrJrJrJrJr  S SK	r	S SK
Jr  S SKJr  SSKJrJr  SSKJr  SS	KJr  SS
KJr  SSKJrJrJrJrJrJr  \R<                  " S5      \R<                  " S5      \" SSS9\" SSSS9\" SSSSSS9\" SSSSS9\" SSSS S9\" SS!S"S#S9\" SS$S%S&SSS'9\" S(S)S*S+S9\" SS,S-S.S9\" S/S0S1S2S94
S3\S4\S5\\   S6\\   S7\ S8\!S9\\   S:\ S;\!S<\4S= jj5       5       r"        SRS3\S4\S5\\   S7\ S8\!S9\\   S:\ S>\!S<\S;\!S?\\\4   4S@ jjr#0 4S/SSA.SB\\\4   SC\\\4   S<\S>\!S?\\\4   4
SD jjjr$     SSSE\\   SF\SG\SH\ SI\!SJ\!SK\!4SL jjr%SM\SB\\\\\&4   4   SN\SO\S?S4
SP jr'SM\SB\\\\\&4   4   S?S4SQ jr(g)T    N)Path)AnyDictListOptionalUnion)fix_random_seed)Printer   )displacyutil)Scorer)Doc)Corpus   )ArgOptappbenchmark_cliimport_code	setup_gpuaccuracyevaluate.zModel name or path)helpz3Location of binary evaluation data in .spacy formatT)r   existsz--outputz-ozOutput JSON file for metricsF)r   dir_okayz--codez-czNPath to Python file with additional code (registered functions) to be importedz--gpu-idz-gzGPU ID or -1 for CPUz--gold-preprocz-GzUse gold preprocessingz--displacy-pathz-dpz+Directory to output rendered parses as HTML)r   r   	file_okay   z--displacy-limitz-dlz!Limit of parses to render as HTMLz--per-componentz-PzSReturn scores per component, only applicable when an output JSON file is specified.scz--spans-keyz-skz*Spans key to use when evaluating Doc.spansmodel	data_pathoutput	code_pathuse_gpugold_preprocdisplacy_pathdisplacy_limitper_component	spans_keyc
                 >    [        U5        [        U UUUUUUUSU	S9
  g)aE  
Evaluate a trained pipeline. Expects a loadable spaCy pipeline and evaluation
data in the binary .spacy format. The --gold-preproc option sets up the
evaluation examples with gold-standard sentences and tokens for the
predictions. 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. To render a sample of
dependency parses in a HTML file, set as output directory as the
displacy_path argument.

DOCS: https://spacy.io/api/cli#benchmark-accuracy
F)r#   r%   r&   r'   r(   r)   silentr*   N)r   r   )
r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   s
             L/home/james-whalen/.local/lib/python3.13/site-packages/spacy/cli/evaluate.pyevaluate_clir.      s2    < 	!#%#    r,   returnc
           
         [        Xw(       + S9n
[        5         [        X7S9  [        R                  " U5      n[        R                  " U5      n[        R                  " U5      nUR                  5       (       d  U
R                  SUSS9  U(       a&  UR                  5       (       d  U
R                  SUSS9  [        XS9n[        R                  " U 5      n[        U" U5      5      nUR                  XS9nU	(       a+  UnUc  U
R                  S	5        GO(U
R                  S
5        GO0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS _S!S"_S#S$_S%S&_S'S(U S)3_S*S(U S+3_S,S(U S-3_S.S/0En0 n0 nUR                  5        H  u  nnUU;   d  M  US :X  a  US0-   UR                  S1S25      -   S3-   n[        UU   [         ["        45      (       a  US/:X  a  UU   S4 UU'   OUU   S5-  S6 UU'   OS7UU'   UU   U[$        R&                  " S8S9UR)                  5       5      '   M     U
R+                  US:S;9  [-        UUXS<9nU(       a  UR.                   Vs/ s H  nUR1                  U5      R2                  PM      nn[        UR5                  S= US U  5       5      5      nS>U;   nS?U;   nS@U;   n[7        UUU UUUUSA9  U
R9                  SBU SC3U5        Ub+  [:        R<                  " UU5        U
R9                  SDU 35        U$ s  snf )ENno_printpretty)r,   zEvaluation data not foundr   )exitsz(Visualization output directory not found)r&   )r)   zdThe per-component option is enabled but there is no output JSON file provided to save the scores to.z7Per-component scores will be saved to output JSON file.TOK	token_accTAGtag_accPOSpos_accMORPH	morph_accLEMMA	lemma_accUASdep_uasLASdep_laszNER Pents_pzNER Rents_rzNER Fents_fTEXTCAT
cats_scorezSENT Psents_pzSENT Rsents_rzSENT Fsents_fzSPAN Pspans__pzSPAN R_rzSPAN F_fSPEEDspeedz (cats_score_descunk)z.0fd   .2f-z[\s/]_Results)titler*   r,   c              3   L   #    U  H  oR                   R                  v   M     g 7f)N)	referencetext).0exs     r-   	<genexpr>evaluate.<locals>.<genexpr>   s     V9U2\\..9Us   "$parsernerspancat)
model_namelimitdepsentsspansz
Generated z parses as HTMLzSaved results to )r
   r	   r   r   ensure_pathr   failr   
load_modellistr   warninfoitemsget
isinstanceintfloatresublowertablehandle_scores_per_type
pipe_namesget_pipe_metafactorypiperender_parsesgoodsrsly
write_json)r!   r"   r#   r%   r&   r'   r(   r,   r*   r)   msgoutput_pathcorpusnlpdev_datasetscoresdatametricsresultsmetrickeyr~   factory_namesdocsrender_depsrender_entsrender_spanss                              r-   r   r   =   s    6*
5Cg%  +I""6*K$$]3M,iqA]1133;]RSTI9F
//%
 Cvc{#K\\+\CF>HHv HHNO
;
9
 9
 [	

 [
 9
 9
 X
 X
 X
 |
 i
 i
 i
 yk,
  yk,!
" yk,#
$ W%
( "==?KFCf},&#d]VZZ8I5-QQTWWFfSkC<88g~-3C[,=-3C[_S,A&)GFO;A#;RVVHc399;78 + 			'	+%fdiWEH^^T^T**4088^TCHHV_n9UVVW-/}, M1 	
 	:n-_=}Md+$[M23K) Us   %Lr[   r   r   c                &   [        X3(       + S9nSU ;   a"  U S   (       a  [        X@S   SS5        U S   US'   SU ;   a"  U S   (       a  [        X@S   SS5        U S   US'   SU ;   a"  U S   (       a  [        X@S   S	S5        U S   US'   S
U S3U ;   a2  U S
U S3   (       a$  [        X@S
U S3   SS5        U S
U S3   US
U S3'   SU ;   a"  U S   (       a  [        X@S   SS5        U S   US'   SU ;   a   U S   (       a  [        X@S   5        U S   US'   U $ )Nr2   morph_per_featr<   featdep_las_per_typerB   typeents_per_typeNERrL   	_per_typeSPANScats_f_per_typez	Textcat Flabelcats_auc_per_type)r
   print_prf_per_typeprint_textcats_auc_per_cat)r   r   r*   r,   r   s        r-   rz   rz      ss    6*
5C6!"#s+;$<gvN%+,<%=D!"V#$%s+=$>vN'-.@'AD#$& /"s?$;UFK$*?$;D!		{)$.F9+Y/0fYKy9:GV 396)I9V2WD6)I./F"#$s+<$={GT&,->&?D"#f$%&&s3F,GH(./B(CD$%Mr/   r   r   rf   rg   rh   ri   rj   c                 b   X S   R                   S'   U(       aF  [        R                  " U S U SSS9nUS-  R                  SSS	9 nUR	                  U5        S S S 5        U(       aI  [        R                  " U S U S
SSS0S9nUS-  R                  SSS	9 nUR	                  U5        S S S 5        U(       aG  [        R                  " U S U SSS9nUS-  R                  SSS	9 nUR	                  U5        S S S 5        g g ! , (       d  f       N= f! , (       d  f       Nn= f! , (       d  f       g = f)Nr   rZ   entT)stylepagezentities.htmlwutf8)encodingdepcompact)r   r   optionszparses.htmlspanz
spans.html)	user_datar   renderopenwrite)	r   r   rf   rg   rh   ri   rj   htmlfile_s	            r-   r   r      s    ",GgtFU|5tDO+11#1G5KK H%LD9d:K
 M)//f/EKK F tFU|6EL(..sV.DKK ED  HG FE
 EDs$   C>D"D >
D
D 
D.r   namer   c           	         / nUR                  5        HY  u  pVU/nS H:  nXh   n	UR                  [        U	[        [        45      (       a  U	S-  S OU	5        M<     UR                  U5        M[     U R                  USSU SU S3S9  g )	N)prfrU   rV   ) PRF)lr   r   r   z (per rT   headeralignsrZ   )rq   appendrs   rt   ru   ry   )
r   r   r   r   r   r   valuerowkvs
             r-   r   r      s     Dlln
e AAJJ:a#u+F+F!c'#AN ! 	C % II"#fTF!$	  r/   c                     U R                  UR                  5        VVs/ s H(  u  p#U[        U[        [        45      (       a  US OU4PM*     snnSSSS9  g s  snnf )NrV   )r   zROC AUC)r   r   zTextcat ROC AUC (per label)r   )ry   rq   rs   ru   rt   )r   r   r   r   s       r-   r   r      se     II 	
& jUCL991S'qA&	
 +  	
s   /A
)Nr   FNr   Tr    F)r      TTT))rv   pathlibr   typingr   r   r   r   r   r   	thinc.apir	   wasabir
   r   r   r   scorerr   tokensr   trainingr   _utilr   r   r   r   r   r   commandstrrt   boolr.   r   rz   r   ru   r   r    r/   r-   <module>r      sY   	  3 3  %      G G  Z S34#$Ybfg z4>\glm #D(D  @P  !Qr:t2HIU$4dAYZ$'.?Mz  DH  TY  %Zb"4eBefe%6  DY  Z}e:fg&& & TN	&
 ~& & & D>& & & & &X "$(^^^ TN^ 	^
 ^ D>^ ^ ^ ^ ^ 
#s(^^F " "cN"
sCx." 	"
 " 
#s(^"P 
s)  	
   6	sDe$445=@HK	$	sDe$445	r/   