o
    i{                     @   sT   d dl mZ ddlmZ ddlmZ efdededefdd	Zd
edefddZ	dS )    )Model   )LOWER)registry
ngram_sizeattrreturnc                 C   s"   t dt}| |jd< ||jd< |S )Nextract_ngramsr   r   )r   forwardattrs)r   r   model r   K/home/ubuntu/.local/lib/python3.10/site-packages/spacy/ml/extract_ngrams.pyr	      s   


r	   r   is_trainc                 C   s   g }g }|D ]E}| j || jd g}|g}td| jd d D ]}|| j || q"| j j|}	| j jj	|	dd\}	}
||	 ||
 q| j jdd |D d	d
}| j j|}| j j| j j|dd
}dd }|||f|fS )Nr   r   r      T)return_countsc                 S   s   g | ]}|j d  qS )r   )shape).0arrr   r   r   
<listcomp>   s    zforward.<locals>.<listcomp>int32)dtypefc                 S   s   g S )Nr   )dYr   r   r   backprop   s   zforward.<locals>.backprop)
opsasarrayto_arrayr   rangeappendngramsxpconcatenateunique)r   docsr   
batch_keys
batch_valsdocunigramsr    nkeysvalslengthsr   r   r   r   r
      s    
r
   N)
	thinc.apir   r   r   utilr   intr	   boolr
   r   r   r   r   <module>   s
    