
    iu              
       f   d dl mZmZmZ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  ed      Z ed      Z ed	      Z e
j(                  d
      dedefd       Zdeeef   deeef   deeef   deeef   fdZdeeef   dededeeef   fdZ	 	 ddeeef   dee   dee   ddfdZy)    )AnyCallableDictListOptionalTupleTypeVarcast   )registry)Model)
XY_YZ_OutT)	get_widthInTMidTOutTzchain.v1layerreturnc                      t        |  S N)chain)r   s    c/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/thinc/layers/chain.pychain_no_typesr      s    %=    layer1layer2layersc                 z   | |g}|j                  |       ddi}|d   j                  d      du r|d   j                  d      |d<   |d   j                  d      d|d<   |d   j                  d      du r|d   j                  d      |d<   t        dj	                  d |D              t
        t        ||	      }|S )
a
  Compose two models `f` and `g` such that they become layers of a single
    feed-forward model that computes `g(f(x))`.
    Also supports chaining more than 2 layers.
    Note that the type checking for additional layers is carried out by the Thinc Mypy plugin.
    nONr   nITz>>c              3   4   K   | ]  }|j                     y wr   )name).0r   s     r   	<genexpr>zchain.<locals>.<genexpr>(   s     5%**5s   )initdimsr   )extendhas_dimget_dimr   joinforwardr&   )r   r   r   
all_layersr'   models         r   r   r      s     *0(8Jf&*D\D!}T"d*]**40T
!}T"*T
"~d#t+^++D1T
$)		5*55%E Lr   r.   Xis_trainc                     g | j                   D ]"  } |||      \  }}j                  |       |}$ dt        dt        ffd}|fS )zbApply the layers of `model` in sequence, feeding the output from one
    layer into the next.
    )r0   dYr   c                 <    t              D ]  } ||       }|}  S r   )reversed)r2   callbackdX	callbackss      r   backpropzforward.<locals>.backprop;   s,     + 	H"BB	 	r   )r   appendr   r   )r.   r/   r0   r   Yinc_layer_gradr8   r7   s          @r   r,   r,   1   s`     I !!h7>(
T c  h;r   Nr:   c                    ||| j                   D ]  }|j                           | j                   d   j                  d      r.| j                  d| j                   d   j	                  d             | j                   d   j                  d      r.| j                  d| j                   d   j	                  d             |}| j                   D ]M  }|j                  d      |j                  ||       n|j                  |       |=|j                  |      }O | j                   d   j                  d      r.| j                  d| j                   d   j	                  d             | j                  d      	 t        |      }| j                  d|       y y # t        $ rS | j                   d   j                  d      r2| j                   d   j	                  d      }| j                  d|       Y y Y y w xY w)Nr   r    r!   r   )r/   r:   )r/   )r   
initializer)   set_dimr*   predictr   
ValueError)r.   r/   r:   r   
curr_inputr   s         r   r&   r&   D   s   
 	yQY\\ 	E	<<?""4(MM$Q 7 7 =><<##D)MM$R 0 8 8 >? J 3==&zQ/z*!z2J3 ||At$dELLO33D9:}}T"	(:&BMM$# #  	(||B''-\\"%--d3dB' .	(s   :F AG54G5)NN)typingr   r   r   r   r   r   r	   r
   configr   r.   r   typesr   utilr   r   r   r   r   r   r   boolr,   r&    r   r   <module>rH      s   L L L    envv 5 U  #t)&+D#I&6AFsCx
3
?<5d#  t dHn@U * #(d#(}#( ~#( 
	#(r   