Ë
    b›¾j#  ã                   óº  — d dl Z d dlmZ 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 ee
e   ef   Z ed«      Zeee   geee      f   Zddœded	ed
ede	eegef      def
d„Zddœdeded
ede	eegef      def
d„Z	 ddede	eegef      defd„Zddefdee   ded	ed
ededeee      fd„Zddefdee   dedeee      fd„Zefde
e   dedeee      fd„Zy)é    N)Úpartial)	ÚAnyÚCallableÚIterableÚIteratorÚListÚOptionalÚSequenceÚTypeVarÚUnioné   )Ú	minibatchÚItemT)Ú
get_lengthÚsizeÚbufferÚdiscard_oversizer   Úreturnc                 ó:   — |�d|ini }t        t        f| ||dœ|¤ŽS )a‰  Create a batcher that uses the `batch_by_padded_size` strategy.

    The padded size is defined as the maximum length of sequences within the
    batch multiplied by the number of sequences in the batch.

    size (int or Sequence[int]): The largest padded size to batch sequences into.
        Can be a single integer, or a sequence, allowing for variable batch sizes.
    buffer (int): The number of sequences to accumulate before sorting by length.
        A larger buffer will result in more even sizing, but if the buffer is
        very large, the iteration order will be less random, which can result
        in suboptimal training.
    discard_oversize (bool): Whether to discard sequences that are by themselves
        longer than the largest padded batch size.
    get_length (Callable or None): Function to get the length of a sequence item.
        The `len` function is used by default.
    r   )r   r   r   )r   Úminibatch_by_padded_size)r   r   r   r   Ú	optionalss        úa/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/spacy/training/batchers.pyÚ"configure_minibatch_by_padded_sizer      s=   € ð0 /9Ð.D�˜zÑ*È"€IÜÜ ðàØØ)ñ	ð
 ñð ó    Ú	tolerancec                 ó:   — |�d|ini }t        t        f| ||dœ|¤ŽS )a  Create a batcher that uses the "minibatch by words" strategy.

    size (int or Sequence[int]): The target number of words per batch.
        Can be a single integer, or a sequence, allowing for variable batch sizes.
    tolerance (float): What percentage of the size to allow batches to exceed.
    discard_oversize (bool): Whether to discard sequences that by themselves
        exceed the tolerated size.
    get_length (Callable or None): Function to get the length of a sequence
        item. The `len` function is used by default.
    r   )r   r   r   )r   Úminibatch_by_words)r   r   r   r   r   s        r   Úconfigure_minibatch_by_wordsr   8   s=   € ð" /9Ð.D�˜zÑ*È"€IÜÜðàØØ)ñ	ð
 ñð r   c                 ó6   — |�d|ini }t        t        fd| i|¤ŽS )zÜCreate a batcher that creates batches of the specified size.

    size (int or Sequence[int]): The target number of items per batch.
        Can be a single integer, or a sequence, allowing for variable batch sizes.
    r   r   )r   r   )r   r   r   s      r   Úconfigure_minibatchr    S   s*   € ð /9Ð.D�˜zÑ*È"€IÜ”9Ñ5 4Ð5¨9Ñ5Ð5r   é   FÚseqsc              #   ód  K  — t        |t        «      rt        j                  |«      }nt	        |«      }t        | |¬«      D ]f  }t        |«      }t        |«      }t        |||«      D ]>  }|D �	cg c]  }	||	   ‘Œ	 }
}	t        d„ |
D «       «      t        |
«      z  }|r||k\  rŒ;|
–— Œ@ Œh yc c}	w ­w)aq  Minibatch a sequence by the size of padded batches that would result,
    with sequences binned by length within a window.

    The padded size is defined as the maximum length of sequences within the
    batch multiplied by the number of sequences in the batch.

    size (int or Sequence[int]): The largest padded size to batch sequences into.
    buffer (int): The number of sequences to accumulate before sorting by length.
        A larger buffer will result in more even sizing, but if the buffer is
        very large, the iteration order will be less random, which can result
        in suboptimal training.
    discard_oversize (bool): Whether to discard sequences that are by themselves
        longer than the largest padded batch size.
    get_length (Callable or None): Function to get the length of a sequence item.
        The `len` function is used by default.
    )r   c              3   ó2   K  — | ]  }t        |«      –— Œ y ­w©N©Úlen)Ú.0Úseqs     r   ú	<genexpr>z+minibatch_by_padded_size.<locals>.<genexpr>   s   è ø€ Ò;¨3œc #ŸhÑ;ùó   ‚N)Ú
isinstanceÚintÚ	itertoolsÚrepeatÚiterr   ÚlistÚnextÚ_batch_by_lengthÚmaxr'   )r"   r   r   r   r   Úsize_Úouter_batchÚtarget_sizeÚindicesÚiÚsubbatchÚpadded_sizes               r   r   r   _   s³   è ø€ ô. �$œÔÜ× Ñ  Ó&‰ä�T“
ˆÜ  ¨FÔ3ò 	ˆÜ˜;Ó'ˆÜ˜5“kˆÜ'¨°[À*ÓMò 	ˆGØ07Ö8¨1˜ A›Ð8ˆHÐ8ÜÑ;°(Ô;Ó;¼cÀ(»mÑKˆKÙ K°;Ò$>Øà“ñ	ñ	ùò 9ùs   ‚A,B0Á.B+Á:6B0gš™™™™™É?c              #   ó”  K  — t        |t        «      rt        j                  |«      }nt	        |«      }t        |«      }||z  }g }g }	d}
d}| D ]Þ  } ||«      }|||z   kD  r	|rŒ|g–— Œ|dk(  r|
|z   |k  r|j                  |«       |
|z  }
Œ@|
|z   |z   ||z   k  r|	j                  |«       ||z  }Œe|r|–— t        |«      }||z  }|	}|}
g }	d}|
|z   |k  r|j                  |«       |
|z  }
Œ¢|
|z   ||z   k  r|	j                  |«       ||z  }ŒÄ|r|–— t        |«      }||z  }|g}|}
Œà |j                  |	«       |r|–— yy­w)aê  Create minibatches of roughly a given number of words. If any examples
    are longer than the specified batch length, they will appear in a batch by
    themselves, or be discarded if discard_oversize=True.

    seqs (Iterable[Sequence]): The sequences to minibatch.
    size (int or Sequence[int]): The target number of words per batch.
        Can be a single integer, or a sequence, allowing for variable batch sizes.
    tolerance (float): What percentage of the size to allow batches to exceed.
    discard_oversize (bool): Whether to discard sequences that by themselves
        exceed the tolerated size.
    get_length (Callable or None): Function to get the length of a sequence
        item. The `len` function is used by default.
    r   N)r,   r-   r.   r/   r0   r2   ÚappendÚextend)r"   r   r   r   r   r5   r7   Útol_sizeÚbatchÚoverflowÚ
batch_sizeÚoverflow_sizer)   Ún_wordss                 r   r   r   †   sœ  è ø€ ô( �$œÔÜ× Ñ  Ó&‰ä�T“
ˆÜ�u“+€KØ˜YÑ&€HØ€EØ€HØ€JØ€MØò (%ˆÙ˜S“/ˆð �[ 8Ñ+Ò+Ú#Ø�e“à˜aÒ Z°'Ñ%9¸kÒ$IØ�L‰L˜ÔØ˜'Ñ!‰Jà˜=Ñ(¨7Ñ2¸ÀhÑ8NÒOØ�O‰O˜CÔ Ø˜WÑ$‰Mñ Ø’Ü˜u›+ˆKØ" YÑ.ˆHØˆEØ&ˆJØˆHØˆMà˜WÑ$¨Ò4Ø—‘˜SÔ!Ø˜gÑ%‘
à˜wÑ&¨K¸(Ñ,BÒCØ—‘ Ô$Ø Ñ(‘ñ Ø’KÜ" 5›k�Ø&¨Ñ2�Ø˜�Ø$‘
ðQ(%ðR 
‡L�L�ÔÙØ‹ð ùs   ‚A!EÁ$C$EÚ	max_wordsc                 óô  — t        | «      D ��cg c]  \  }} ||«      |f‘Œ }}}|j                  «        g }g }|D ]S  \  }}|s|j                  |«       Œ|t        |«      dz   z  |k  r|j                  |«       Œ@|j                  |«       |g}ŒU |r|j                  |«       t	        d„ |D «       «      t        | «      k(  sJ ‚|D �cg c]  }t        |«      ‘Œ }}|j                  «        |S c c}}w c c}w )zçGiven a list of sequences, return a batched list of indices into the
    list, where the batches are grouped by length, in descending order.

    Batches may be at most max_words in size, defined as max sequence length * size.
    é   c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr%   r&   )r(   Úbs     r   r*   z#_batch_by_length.<locals>.<genexpr>ê   s   è ø€ Ò'˜!Œs�1�vÑ'ùr+   )Ú	enumerateÚsortr=   r'   ÚsumÚsortedÚreverse)	r"   rE   r   r9   r)   Úlengths_indicesÚbatchesr@   Úlengths	            r   r3   r3   Ò   sò   € ô ;DÀD»/×J±°°3™
 3›¨Ò+ÐJ€OÑJØ×ÑÔØ€GØ€EØ$ò ‰	ˆ�ÙØ�L‰L˜�OØ”s˜5“z A‘~Ñ&¨)Ò3Ø�L‰L˜�Oà�N‰N˜5Ô!Ø�C‰Eðñ Ø�‰�uÔäÑ'˜wÔ'Ó'¬3¨t«9Ò4Ð4Ð4Ø*1Ö2 Œv�e�}Ð2€GÐ2Ø‡O�OÔØ€Nùó% Kùò  3s   �C/Ã	C5r%   )r.   Ú	functoolsr   Útypingr   r   r   r   r   r	   r
   r   r   Úutilr   r-   ÚSizingr   ÚBatcherTÚboolr   Úfloatr   r    r'   r   r   r3   © r   r   ú<module>rZ      sä  ðÛ Ý ÷
÷ 
õ 
õ à	ˆx˜‰}˜cÐ!Ñ	"€Ù�Ó€Ø�X˜e‘_Ð% x°°U±Ñ'<Ð<Ñ=€ð 48òà
ðð ðð ð	ð
 ˜ 5 '¨3 ,Ñ/Ñ0ðð óðN 48òà
ðð ðð ð	ð
 ˜ 5 '¨3 ,Ñ/Ñ0ðð óð8 BFñ	6Ø
ð	6Ø& x°°¸°Ñ'=Ñ>ð	6àó	6ð Ø"Øñ$Ø
�5‰/ð$à
ð$ð ð$ð ð	$ð
 ð$ð ˆd�5‰kÑó$ðT ØØñIØ
�5‰/ðIà
ðIð ˆd�5‰kÑóIðZ 58ñØ
�3‰-ðØ$'ðà	ˆ$ˆs‰)�_ôr   