o
    i                  
   @   s   d dl mZmZmZmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZ eZeZeddd	eed
f dee deeef fddZdeeef dededeeef fddZ	ddeeef dee dee ddfddZdS )    )CallableOptionalTuplecast   )registry)Model)Floats1dFloats2d)	get_widthzMultiSoftmax.v1NnOs.nIreturnc              	   C   s(   t dttt| |dd| iddddS )aB  Neural network layer that predicts several multi-class attributes at once.
    For instance, we might predict one class with 6 variables, and another with 5.
    We predict the 11 neurons required for this, and then softmax them such
    that columns 0-6 make a probability distribution and columns 6-11 make another.
    multisoftmax)nOr   r   N)Wb)initdimsattrsparams)r   forwardr   sum)r   r    r   M/home/ubuntu/.local/lib/python3.10/site-packages/thinc/layers/multisoftmax.pyMultiSoftmax   s   r   modelXis_trainc           	         s   j d }ttd ttd}dtdtf fdd}jj dd	}||7 }d
}|D ]}jj	|d d ||| f dd ||7 }q3||fS )Nr   r   r   dYr   c                    s<    djj| dd  d| jdd j|  S )Nr   T)trans1r   r   )axis)inc_gradopsgemmr   )r   r   r   r   r   r   backprop"   s   zforward.<locals>.backpropT)trans2r   )inplace)
r   r   r
   	get_paramr	   OutTInTr#   r$   softmax)	r   r   r   r   r   r&   Yiout_sizer   r%   r   r      s   
$
r   r-   c                 C   sZ   |d ur|  dt| | d}| d}| d| j|| | d| j| d S )Nr   r   r   r   )set_dimr   get_dim	set_paramr#   alloc2falloc1f)r   r   r-   r   r   r   r   r   r   0   s   

r   )N)NN)typingr   r   r   r   configr   r   r   typesr	   r
   utilr   r+   r*   layersintr   boolr   r   r   r   r   r   <module>   s(    .*
