
    i5#                        d dl Z d dlmZ d dlmZmZmZ d dlZd dlm	Z	m
Z
mZmZmZ d dlmZ d dlmZ d dlmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZmZmZmZmZm Z   ejB                  dddd       edddd       edd       edddd       edddd       eddd d!       edd"d#d$       edd%d&d'       edd(d)d*       edd+d,d-       edd.d/d0       edd1d2d3       ed4d5d6d7      fd8ejD                  d9ed:e#d;e#d<e$d=e$d>e$d?e$d@e$dAe$dBe$dCe$dDe%fdE       Z&ddFdGeee#ef      fdHZ'dI Z(dOdJe#fdKZ)dL Z*dM Z+dN Z,y)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           
         t        |       t        |d      }|||||||	|
|d	}t        | j                        }t	        |      5  t        j                  ||d      }ddd       j                         }|d   d   }|d	k\  r|rt        |       t	        |      5  t        j                  |      }|j                  j                         }t        j                  |d   t        
      }ddd       d   }|#t        j                  d|        t!        |       j#                  |      }t%        |||||       y# 1 sw Y   xY w# 1 sw Y   axY w)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                         f/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/spacy/cli/debug_model.pydebug_model_clirN       sW   F gF40F   !# "
N .chh7	{	+ 
%%#3


 ##%Fz"?3I!|	)$	{	+ N))*5'')VJ/8LMN V9D'v./<<	"D3^D%
 
N Ns   D=AE	=E	Er=   r>   c          
         t        |d      st        j                  d| dd       |j                  }t	        |t
              s$t        j                  dt        |       dd       |i }t        j                  d|j                          |j                  d	      r!t        j                  d
       t        ||       t        d      5  	 |d   g}t               5  t        | |      \  j                  fd       d d d        t        j                  d       t!        t#        j$                         d            d d d        |j                  d      r!t        j                  d       t        ||       t3        |d       d }|j5                  d      r.d|j7                  d      j8                  v rj;                  d      }|j5                  d      r.d|j7                  d      j8                  v rj;                  d      }t=        d      D ]&  }	|r|j?                         |j?                         ( |j                  d      r!t        j                  d       t        ||       |jA                  D 
cg c]  }
|
jB                   c}
      }|j                  d      r3t        j                  d        t        j                  tE        |             t        jF                  d!       y # 1 sw Y   xY w# t&        $ r 	 t)        d|       t               5  t+               D cg c]  }t-        j.                  |i        nc c}w c}j                  fd       d d d        n# 1 sw Y   nxY wt        j                  d       n&# t0        $ r t        j                  dd       Y nw xY wY xw xY w# 1 sw Y   ~xY wc c}
w )"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                              S N )rJ   rQ   s   rM   <lambda>zdebug_model.<locals>.<lambda>   s    |C'8     z/Initialized the model with the training corpus.      )nOr   c                       S rS   rT   )exampless   rM   rU   zdebug_model.<locals>.<lambda>   s    8 rV   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/Successfully 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   f   s/    4!dV#ST	
 JJEeU#?U}IV	
  HH'z2312.0UN+ 
	 	.~>?I&( :"3FI"F89: HHFGI,,\#->BCH* ,-35UN+ UC }}Y$6%--	:R:W:W$W \\)4i "emmI&>&C&CC \\-81X %%h/H 01-/UN+ x@@AJ,-)+Z!HH>@_: :
  	
1E2*, 5BK+NQ 1 1!R 8NNHNN#345 5 5 AB  A	 Z  As   OL $K5ALO5K?	:L	N?N#M30M
M3*	N3M<8NN? N85N?7N88N?;O>N??OOc                  
    g dS )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   rV   rM   
_sentencesr      s     rV   langc                 z     t        j                  |              }t        |j                  t	                           S rS   )r   get_lang_classrh   rL   r   )r   rJ   s     rM   rm   rm      s-    
#$

d
#
%C&''rV   c                     | j                  d      | j                  d|       | j                  d      rC| j                  d      j                  d      "| j                  d      j                  d|       y y y )NrY   output_layer)has_dimset_dimrp   rq   )r   rY   s     rM   rl   rl      sh    }}T"dB}}^$==(006>MM.)11$; ? %rV   c           
         |j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }t        | j                               D ]  \  }}|r||v st        j                  d| d	|j
                   d
|j                   d       |r;|j                  D ],  }	t        j                  d|	 d|j                  |	              . |r|j                  D ]s  }	|j                  |	      r6t        |j                  |	            }
t        j                  d|	 d|
        Jt        j                  d|	 d|j                  |	              u |r|j                  D ]s  }	|j                  |	      r6t        |j                  |	            }
t        j                  d|	 d|
        Jt        j                  d|	 d|j                  |	              u |s|j                  }|j!                         D ]   \  }	}t        j                  d|	 d|        "  y )Nr'   r"   r)   Fr(   r*   r+   zLayer z: model ID z: ''z - dim z: z	 - param z - grad z - attr )rd   	enumeratewalkr   rD   rc   rr   	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noderr   print_valuer   values                rM   rf   rf      s   "-F##L%8J##L%8J"";6I##L%8JUZZ\* 94fHHvaSDGG9C		{!DE NN KDHHwtfBt/A/A$/G.HIJK ,, MD~~d+&3DNN44H&I9TF"[M!BC9TF"T^^D5I4J!KLM  ,, KD}}T*&3DMM$4G&H8D6K=!AB8D6DMM$4G3H!IJK 

#(;;= 9KD%HHxvRw789/9rV   c                     | t        | t              r| S t        | j                        dz   }| }t	        | j
                  dz
        D ]  }|d   }	 |dd }|t        |      z   }|S )Nz - sample: r   r   rW   )ra   boolrw   shapers   ndim)r   resultsample_matrixds       rM   r   r      ss    }
5$/-FM5::>" )%a()!!A&Mc-((FMrV   )en)-ri   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Contextrw   r   intrN   rF   r   rm   rl   rf   r   rT   rV   rM   <module>r      s     & &    " (  *    *.$O ' X 
J#P 5.&?PQ5.&?PQ%>NO5.'@QR5/57TU,N 5/57ST5/57PQr:t2HI-?E	?E ?E ?E ?E ?E ?E ?E ?E  	!?E" 	#?E( 	)?E* 	+?E, -?E	?EP 04OA T#s(^,OAd(C (
<9D	rV   