
    h"                     L   S SK r S SKJr  S SKJrJrJr  S SKrS SKJ	r	J
r
JrJrJr  S SKJr  S SKJr  S SK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J r   \RB                  " SSSS.S9\" SSSSS9\" 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9\" SS%S&S'S9\" SS(S)S*S9\" SS+S,S-S9\" SS.S/S0S9\" SS1S2S3S9\" S4S5S6S7S94S8\RD                  S9\S:\#S;\#S<\$S=\$S>\$S?\$S@\$SA\$SB\$SC\$SD\%4SE jj5       r&SSF.SG\\\#\4      4SH jjr'SI r(SOSJ\#4SK jjr)SL r*SM r+SN r,g)P    N)Path)AnyDictOptional)Modeldata_validationfix_random_seedset_dropout_rateset_gpu_allocator)msg)Example)resolve_dot_names   )util)ConfigSchemaTraining)registry   )ArgOpt	debug_cliparse_config_overrides	setup_gpushow_validation_errorstring_to_listmodelT)allow_extra_argsignore_unknown_options)context_settings.zPath to config file)helpexists
allow_dashzDName of the pipeline component of which the model should be analysed)r    z--layersz-lz+Comma-separated names of layer IDs to printFz--dimensionsz-DIMzShow dimensionsz--parametersz-PARzShow parametersz--gradientsz-GRADzShow gradientsz--attributesz-ATTRzShow attributesz--print-step0z-P0zPrint model before trainingz--print-step1z-P1z Print model after initializationz--print-step2z-P2zPrint model after trainingz--print-step3z-P3zPrint final predictionsz--gpu-idz-gzGPU ID or -1 for CPUctxconfig_path	componentlayers
dimensions
parameters	gradients
attributesP0P1P2P3use_gpuc           
         [        U5        [        USS9nUUUUUUU	U
US.	n[        U R                  5      n[	        U5         [
        R                  " XSS9nSSS5        WR                  5       nUS   S   nUS	:  a  U(       a  [        U5        [	        U5         [
        R                  " U5      nUR                  R                  5       n[        R                  " US   [        S
9nSSS5        WS   nUb$  [        R                  " SU 35        [!        U5        WR#                  U5      n[%        UUUUUS9  g! , (       d  f       N= f! , (       d  f       Nj= f)z
Analyze a Thinc model implementation. Includes checks for internal structure
and activations during training.

DOCS: https://spacy.io/api/cli#debug-model
T)intify)	r(   r)   r*   r+   r'   print_before_trainingprint_after_initprint_after_trainingprint_predictionF)	overridesinterpolateNtraininggpu_allocatorr   )schemaseedzFixing random seed: print_settings)r   r   r   argsr   r   load_configr8   r   load_model_from_configconfigr   resolver   r   infor	   get_pipedebug_model)r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r>   config_overrides
raw_configrB   	allocatornlpTr<   pipes                         O/home/james-whalen/.local/lib/python3.13/site-packages/spacy/cli/debug_model.pydebug_model_clirN       sA   6 gF40F   !# "
N .chh7	{	+%%

 
, ##%Fz"?3I!|	)$	{	+))*5'')VJ/8LM 
, V9D'v./<<	"D3^D% 
,	+ 
,	+s   D;AE;
E	
Er=   r>   c          
      >  ^^^ [        US5      (       d  [        R                  " SU S3SS9  UR                  n[	        U[
        5      (       d"  [        R                  " S[        U5       S3SS9  Uc  0 n[        R                  " SUR                   35        UR                  S	5      (       a!  [        R                  " S
5        [        XT5        [        S5          US   /n[        5          [        X5      u  mTR                  UU4S j5        S S S 5        [        R                  " S5        [!        ["        R$                  " T" T5      S5      5      mS S S 5        UR                  S5      (       a!  [        R                  " S5        [        XT5        [3        US5        S nUR5                  S5      (       a0  SUR7                  S5      R8                  ;   a  TR;                  S5      nUR5                  S5      (       a0  SUR7                  S5      R8                  ;   a  TR;                  S5      n[=        S5       H,  n	U(       a  UR?                  T5        UR?                  T5        M.     UR                  S5      (       a!  [        R                  " S5        [        XT5        URA                  T V
s/ s H  oRB                  PM     sn
5      nUR                  S5      (       a5  [        R                  " S 5        [        R                  " [E        U5      5        [        RF                  " S!5        g ! , (       d  f       GN#= f! [&         a     [)        SUS9  [        5          [+        5        Vs/ s H  n[,        R.                  " U0 5      PM     Os  snf snmTR                  U4S j5        S S S 5        O! , (       d  f       O= f[        R                  " S5         GN! [0         a    [        R                  " SSS9    GNf = ff = f! , (       d  f       GN= fs  sn
f )"Nr   zThe component 'z0' does not specify an object that holds a Model.r   )exitsz1Requires a Thinc Model to be analysed, but found z	 instead.zAnalysing model with ID r3   zSTEP 0 - before trainingFtrain_corpusc                     > T" T 5      $ N )rJ   rQ   s   rM   <lambda>debug_model.<locals>.<lambda>   s
    |C'8    z/Initialized the model with the training corpus.      )nOr   c                     > T $ rS   rT   )exampless   rM   rU   rV      s    8rW   z&Initialized the model with dummy data.zjCould not initialize the model: you'll have to provide a valid 'train_corpus' argument in the config file.r4   zSTEP 1 - after initializationg?tok2vecztok2vec-listenerztransformer-listenertransformer   r5   zSTEP 2 - after trainingr6   zSTEP 3 - predictionz.Succesfully ended analysis - model looks good.)$hasattrr   failr   
isinstancer   typerD   idgetdivider_print_modelr   r   r   
initializelist	itertoolsislice
ValueError_set_output_dim	_get_docsr   	from_dict	Exceptionr
   has_refget_refnamerE   rangeupdatepredict	predictedstrgood)rB   resolved_train_configrJ   rL   r>   r   	dot_namesxupstream_componenteex
predictionr\   rQ   s     `         @@rM   rF   rF   ^   s&    4!!dV#ST	
 JJEeU##?U}IV	
  HH'z23122.0U+ 
		.~>?I&("3F"F89 ) HHFGI,,\#->BCH 
 * ,--35U+ UC }}Y$6%--	:R:W:W$W \\)4i  "emmI&>&C&CC \\-81X%%h/H  011-/U+ x@xx@AJ,--)+Z!HH=?_ )(
  	
1E2*,BK+N+Q 1 1!R 8+NHNN#34 -,, AB  A	 
 	Z  As   PL?-$L-AL?/P-
L<	7L??
P
ON3+!N
N3*	O3
O=OPP<P=P PPP
Pc                  
    / SQ$ )N)z6Apple is looking at buying U.K. startup for $1 billionz>Autonomous cars shift insurance liability toward manufacturersz8San Francisco considers banning sidewalk delivery robotsz+London is a big city in the United Kingdom.rT   rT   rW   rM   
_sentencesr      s     rW   langc                 |    [         R                  " U 5      " 5       n[        UR                  [	        5       5      5      $ rS   )r   get_lang_classri   rL   r   )r   rJ   s     rM   rn   rn      s+    


d
#
%C&''rW   c                     U R                  S5      c  U R                  SU5        U R                  S5      (       aD  U R                  S5      R                  S5      c"  U R                  S5      R                  SU5        g g g )NrZ   output_layer)has_dimset_dimrq   rr   )r   rZ   s     rM   rm   rm      sk    }}T"dB}}^$$==(006>MM.)11$; ? %rW   c           
         UR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      n[        U R                  5       5       GH  u  pxU(       a  Xr;   d  M  [        R                  " SU S	UR
                   S
UR                   S35        U(       a>  UR                   H.  n	[        R                  " SU	 SUR                  U	5       35        M0     U(       a  UR                   H|  n	UR                  U	5      (       a8  [        UR                  U	5      5      n
[        R                  " SU	 SU
 35        MQ  [        R                  " SU	 SUR                  U	5       35        M~     U(       a  UR                   H|  n	UR                  U	5      (       a8  [        UR                  U	5      5      n
[        R                  " SU	 SU
 35        MQ  [        R                  " SU	 SUR                  U	5       35        M~     U(       d  GM  UR                  nUR!                  5        H!  u  p[        R                  " SU	 SU 35        M#     GM     g )Nr'   r"   r)   Fr(   r*   r+   zLayer z: model ID z: ''z - dim z: z	 - param z - grad z - attr )re   	enumeratewalkr   rD   rd   rs   	dim_namesmaybe_get_dimparam_names	has_param_print_matrix	get_paramhas_gradget_gradattrsitems)r   r>   r'   r)   r(   r*   r+   inoders   print_valuer   values                rM   rg   rg      s   "-F##L%8J##L%8J"";6I##L%8JUZZ\*HHvaSDGG9C		{!DE NNDHHwtfBt/A/A$/G.HIJ + ,,D~~d++&3DNN44H&I9TF"[M!BC9TF"T^^D5I4J!KL -  ,,D}}T**&3DMM$4G&H8D6K=!AB8D6DMM$4G3H!IJ - z

#(;;=KDHHxvRw78 $1/ +rW   c                     U b  [        U [        5      (       a  U $ [        U R                  5      S-   nU n[	        U R
                  S-
  5       H  nUS   nM
     USS nU[        U5      -   nU$ )Nz - sample: r   r   rX   )rb   boolrx   shapert   ndim)r   resultsample_matrixds       rM   r   r      sq    }
5$//-FM5::>"%a( #!!A&Mc-((FMrW   )en)-rj   pathlibr   typingr   r   r   typer	thinc.apir   r   r	   r
   r   wasabir   spacy.trainingr   
spacy.utilr   r"   r   schemasr   r   _utilr   r   r   r   r   r   r   commandContextrx   r   intrN   rF   r   rn   rm   rg   r   rT   rW   rM   <module>r      s     & &    " (  *    *.$O C&;DUYZ#ijb*d1^_5.&?PQ5.&?PQ%>NO5.'@QR5/57TU5/57YZ5/57ST5/57PQr:t2HI7E	7E 7E 	7E
 7E 7E 7E 7E 7E 	7E 	7E 	7E 	7E 7E	7E@ 04O@ T#s(^,O@d(C (
<9D	rW   