o
    i                      @   sv  d dl mZ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mZmZ ddlmZmZ eee eef ZeZee ZeZedi d dfd	eeef d
ed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ed		 dddd	eeeeef eeef f  d
e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S )    )	AnyCallableDictHashableOptionalSequenceTupleUnioncast   )registry)Model)DTypesInts1dInts2d)is_xp_arrayto_numpyzremap_ids.v1imapping_tabledefaultdtypereturnc                 C   s   t dt| ||ddS )a	  Remap string or integer inputs using a mapping table, usually as a
    preprocess before embeddings. The mapping table can be passed in on input,
    or updated after the layer has been created. The mapping table is stored in
    the "mapping_table" attribute.
    	remap_ids)r   r   r   attrs)r   forward)r   r   r    r   J/home/ubuntu/.local/lib/python3.10/site-packages/thinc/layers/remap_ids.pyr      s
   	
r   modelinputsis_trainc                    sl   | j d | j d  | j d } fdd|D }| jj||d}| j|dd}d	td
tfdd}||fS )Nr   r   r   c                       g | ]} | qS r   get.0xr   tabler   r   
<listcomp>%       zforward.<locals>.<listcomp>r      dYr   c                 S   s   g S Nr   r.   r   r   r   backprop)   s   zforward.<locals>.backprop)r   ops	asarray2i	reshape2iOutT_v1InT)r   r   r    r   valuesarroutputr1   r   r'   r   r      s   


r   zremap_ids.v2N)columnr:   c                C   s   t dt| ||ddS )a  Remap string or integer inputs using a mapping table,
    usually as a preprocessing step before embeddings.
    The mapping table can be passed in on input,
    or updated after the layer has been created.
    The mapping table is stored in the "mapping_table" attribute.
    Two dimensional arrays can be provided as input in which case
    the 'column' chooses which column to process. This is useful
    to work together with FeatureExtractor in spaCy.
    r   r   r   r:   r   )r   
forward_v2r;   r   r   r   remap_ids_v2/   s
   
r=   c           	         s   j d d u rtdj d  j d }t|r4d|d ur/ttt|d d |f }n	t|}nd|} fdd|D }jj|d	d
}j|dd}dt	dt
ffdd}||fS )Nr   z'mapping table' not setr   r:   TFc                    r!   r   r"   r$   r'   r   r   r)   W   r*   zforward_v2.<locals>.<listcomp>r   r+   r,   r-   r.   r   c                    s   r
 j j| jS g S r/   )r2   xpemptyshaper0   )r   xp_inputr   r   r1   [   s   zforward_v2.<locals>.backprop)r   
ValueErrorr   r   r
   r   r2   r3   r4   OutTr6   )	r   r   r    r:   idxr7   r8   r9   r1   r   )r   r   r(   rA   r   r<   F   s"   



r<   )Nr   )!typingr   r   r   r   r   r   r   r	   r
   configr   r   r   typesr   r   r   utilr   r   r6   rC   InT_v1r5   layersintr   boolr   strr=   r<   r   r   r   r   <module>   sh   , 







