
    i              
           d dl mZmZmZ d dlmZmZ d dlmZm	Z	 deee	e	f   e	f   fdZ
ddZded	ee	e	f   d
edee	ef   fdZde	dedefdZde	dedee	ef   fdZy)    )CallableListTuple)Modelto_numpy)Ints1dRaggedreturnc            	      6    t        dt        g i i i t              S )zExtract spans from a sequence of source arrays, as specified by an array
    of (start, end) indices. The output is a ragged array of the
    extracted spans.
    extract_spans)layersrefsattrsdimsinit)r   forwardr        g/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/spacy/ml/extract_spans.pyr   r      s     
 "BRd r   Nc                      y Nr   )modelXYs      r   r   r      s    r   r   source_spansis_trainc                   	
 | j                   |\  }j                  j                  dk(  sJ t        |j                        t              dkD  r?t        |j                     j                  dddf   j                  dddf   z
        }n~t        j                  j                  |j                  j                  |j                  j                        j                  j                  t        |j                        fd            }|j                  j                  
|j                  	dt        dt        t        t        f   f	
fd	}||fS )
z%Get subsequences from source vectors.   r   N   )dtypeidYr
   c                     t         j                         }j                  |j                  | j                         |fS r   )r	   alloc2fscatter_adddataXd)r"   dXindicesopsspans	x_lengthsx_shapes     r   backprop_windowsz!forward.<locals>.backprop_windows'   s<    KCKK)95		7BII6E{r   )r)   r&   ndim_get_span_indiceslengthslenr	   xpzerosshaper    r   )r   r   r   r   r   r-   r(   r)   r*   r+   r,   s         @@@@@r   r   r      s    ))CHAu<<!!!UAII6G
7|a188G$ell1a4&85<<1;M&MNFFLLqxx~~L>FFLL#aii.*#L6
 hhnnG		IV ffn(=  
 r   r*   r0   c           
      "   t        ||      \  }}g }d}t        |      D ]^  \  }}||   j                  |z   }t        |j                  d         D ]'  }|j                  t        ||df   ||df                ) ||z  }` | j                  |      S )zConstruct a flat array that has the indices we want to extract from the
    source data. For instance, if we want the spans (5, 9), (8, 10) the
    indices will be [5, 6, 7, 8, 8, 9].
    r   r   )_ensure_cpu	enumerater&   ranger4   extend	asarray1i)	r)   r*   r0   r(   offsetr!   lengthspans_ijs	            r   r/   r/   /   s    
 !0NE7GFw' 	6(//F*w}}Q'( 	@ANN5A1>?	@&	
 ==!!r   c                 |    t        t        | j                        t        | j                              t        |      fS r   )r	   r   r&   r0   )r*   r0   s     r   r6   r6   ?   s+    (5<<((5==*ABHWDUUUr   )NN)typingr   r   r   	thinc.apir   r   thinc.typesr   r	   r   r   boolr   r/   r6   r   r   r   <module>rD      s    ( ( % &uU66>2F:; 	 %ffn 5AE
684"& "6 "f " Vv V V53H Vr   