
    ёiR.                        S SK Jr  S SKrS SKrS SKJr  S SKJrJrJ	r	  S SK
rS SKrS SKJr  S SKJr  \(       a  S SKJr  \S   r\S   r/ rS	rS
rSrSrSrSrSr " S S\5      rg)    )annotationsN)defaultdict)TYPE_CHECKINGLiteraloverload)_check_exists_and_download)Datasettraintestval)endez2http://paddlemodels.bj.bcebos.com/wmt/wmt16.tar.gz 0c38be43600334966403524a40dcd81ei+  iK  z<s>z<e>z<unk>c                     \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S	\S'   S\S'   S\S'   S\S'   S\S'   S\S'         S"             S#S jjr\ S$       S%S jj5       r\ S$       S&S jj5       r\ S$       S'S jj5       rS(S jr        S)S jr	S*S jr
    S+S jrS,S jr\ S$     S-S jj5       r\ S$     S.S jj5       r\ S$     S/S jj5       rS(S  jrS!rg)0WMT16.   a
  
Implementation of `WMT16 <http://www.statmt.org/wmt16/>`_ test dataset.
ACL2016 Multimodal Machine Translation. Please see this website for more
details: http://www.statmt.org/wmt16/multimodal-task.html#task1

If you use the dataset created for your task, please cite the following paper:
Multi30K: Multilingual English-German Image Descriptions.

.. code-block:: text

    @article{elliott-EtAl:2016:VL16,
     author    = {{Elliott}, D. and {Frank}, S. and {Sima"an}, K. and {Specia}, L.},
     title     = {Multi30K: Multilingual English-German Image Descriptions},
     booktitle = {Proceedings of the 6th Workshop on Vision and Language},
     year      = {2016},
     pages     = {70--74},
     year      = 2016
    }

Args:
    data_file(str|None): path to data tar file, can be set None if
        :attr:`download` is True. Default None.
    mode(str): 'train', 'test' or 'val'. Default 'train'.
    src_dict_size(int): word dictionary size for source language word. Default -1.
    trg_dict_size(int): word dictionary size for target language word. Default -1.
    lang(str): source language, 'en' or 'de'. Default 'en'.
    download(bool): whether to download dataset automatically if
        :attr:`data_file` is not set. Default True.

Returns:
    Dataset: Instance of WMT16 dataset. The instance of dataset has 3 fields:
        - src_ids (np.array) - The sequence of token ids of source language.
        - trg_ids (np.array) - The sequence of token ids of target language.
        - trg_ids_next (np.array) - The next sequence of token ids of target language.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> from paddle.text.datasets import WMT16

        >>> class SimpleNet(paddle.nn.Layer):
        ...     def __init__(self):
        ...         super().__init__()
        ...
        ...     def forward(self, src_ids, trg_ids, trg_ids_next):
        ...         return paddle.sum(src_ids), paddle.sum(trg_ids), paddle.sum(trg_ids_next)

        >>> wmt16 = WMT16(mode='train', src_dict_size=50, trg_dict_size=50)

        >>> for i in range(10):
        ...     src_ids, trg_ids, trg_ids_next = wmt16[i]
        ...     src_ids = paddle.to_tensor(src_ids)
        ...     trg_ids = paddle.to_tensor(trg_ids)
        ...     trg_ids_next = paddle.to_tensor(trg_ids_next)
        ...
        ...     model = SimpleNet()
        ...     src_ids, trg_ids, trg_ids_next = model(src_ids, trg_ids, trg_ids_next)
        ...     print(src_ids.item(), trg_ids.item(), trg_ids_next.item())
        89 32 33
        79 18 19
        55 26 27
        147 36 37
        106 22 23
        135 50 51
        54 43 44
        217 30 31
        146 51 52
        55 24 25
_Wmt16DataSetModemode
str | None	data_file_Wmt16Languagelangintsrc_dict_sizetrg_dict_sizedict[str, int]src_dicttrg_dictzlist[list[int]]src_idstrg_idstrg_ids_nextNc                8   UR                  5       S;   d
   SU 35       eUR                  5       U l        Xl        U R                  c*  U(       d   S5       e[        U[        [
        SU5      U l        XPl        US:  d   S5       eUS:  d   S5       e[        X5S:X  a  [        O[        5      U l
        [        XES:X  a  [        O[        5      U l        U R                  XS5      U l        U R                  US:X  a  SOSU5      U l        U R                  5       U l        g )	Nr
   z1mode should be 'train', 'test' or 'val', but got z>data_file is not set and downloading automatically is disabledwmt16r   z*dict_size should be set as positive numberr   r   )lowerr   r   r   DATA_URLDATA_MD5r   minTOTAL_EN_WORDSTOTAL_DE_WORDSr   r   
_load_dictr   r   
_load_datadata)selfr   r   r   r   r   downloads          Z/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/text/datasets/wmt16.py__init__WMT16.__init__   s    zz|  
 
 	F ?tfE		F 

 JJL	">>! P8 88XwDN 	q N"NN q N"NN  dlN
 !dlN

 <DLDdM

 OO%	    c                    g N r.   r   	dict_sizereverses       r0   r+   WMT16._load_dict        r3   c                    g r5   r6   r7   s       r0   r+   r:      s     r3   c                    g r5   r6   r7   s       r0   r+   r:           +.r3   c                   [         R                  R                  [        R                  R
                  R                  SU SU S35      nSn[         R                  R                  U5      (       a1  [        US5       n[        UR                  5       5      U:H  nS S S 5        U(       d  U R                  XBU5        0 n[        US5       n[        U5       HN  u  pU(       a"  U
R                  5       R                  5       Xy'   M.  XU
R                  5       R                  5       '   MP     S S S 5        U$ ! , (       d  f       N= f! , (       d  f       U$ = f)Nwmt16/_.dictFrb)ospathjoinpaddledatasetcommon	DATA_HOMEexistsopenlen	readlines_build_dict	enumeratestripdecode)r.   r   r8   r9   	dict_path
dict_foundd	word_dictfdictidxlines              r0   r+   r:      s   GGLLNN!!++TF!I;e,
	 
77>>)$$i&! /9<
 'Y48	)T"e&u-	%)ZZ\%8%8%:IN7:djjl1134	 . #  '& #" s   <D0AE0
D>
Ec           	     F   [        [        5      n[        R                  " U R                  SS9 nUR                  S5       H  nUR                  5       nUR                  5       R                  S5      n[        U5      S:w  a  MC  U R                  S:X  a  US   OUS   nUR                  5        H  n	XI==   S-  ss'   M     M     S S S 5        [        US	5       n
U
R                  [         S
[         S
[         S
3R                  5       5        [!        [#        UR%                  5       S SS95       HC  u  pUS-   U:X  a    O7U
R                  US   R                  5       5        U
R                  S5        ME     S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nrr   zwmt16/train	   r   r      wb
c                    U S   $ )Nr_   r6   )xs    r0   <lambda>#WMT16._build_dict.<locals>.<lambda>   s    !r3   T)keyr9         
)r   r   tarfilerL   r   extractfilerR   rQ   splitrM   r   write
START_MARKEND_MARKUNK_MARKencoderP   sorteditems)r.   rS   r8   r   rV   frY   
line_splitsenwfoutrX   words                r0   rO   WMT16._build_dict   sH     $	\\$..s3qm4{{}!ZZ\//5
z?a''+yyD'8jmjmALA%L % 5 4 )T"dJJ:,b
"XJbAIIKL&y(ndK	 7i'

47>>+,

5! #" 43 #"s   BFBF
F
F c           
        U R                   [           nU R                   [           nU R                   [           nU R                  S:X  a  SOSnSU-
  n/ U l        / U l        / U l        [        R                  " U R                  SS9 nUR                  SU R                   35       GH!  nUR                  5       nUR                  5       R                  S5      n[!        U5      S:w  a  MD  X   R                  5       n	U/U	 V
s/ s H  oR                   R#                  X5      PM     sn
-   U/-   nX   R                  5       nU V
s/ s H  oR$                  R#                  X5      PM     nn
/ UQUPnU/UQnU R
                  R'                  U5        U R                  R'                  U5        U R                  R'                  U5        GM$     S S S 5        g s  sn
f s  sn
f ! , (       d  f       g = f)	Nr   r   r_   r[   r\   r@   r]   r^   )r   rm   rn   ro   r   r    r!   r"   ri   rL   r   rj   r   rR   rQ   rk   rM   getr   append)r.   start_idend_idunk_idsrc_coltrg_colrs   rY   rt   	src_wordsrv   r    	trg_wordsr!   r"   s                  r0   r,   WMT16._load_data   s    ==,x(x(yyD(!ag+\\$..s3qtyyk&:;{{}!ZZ\//5
z?a'&/557	J=FGY}}((3YGHh  '/557	AJKA==,,Q7K11&1#.g.##G,##G,!!((6) < 43 H
 L 43s,   A;G$G
&G$G)A#G
G
G-c                    [         R                  " U R                  U   5      [         R                  " U R                  U   5      [         R                  " U R                  U   5      4$ r5   )nparrayr    r!   r"   )r.   rX   s     r0   __getitem__WMT16.__getitem__  sO     HHT\\#&'HHT\\#&'HHT&&s+,
 	
r3   c                ,    [        U R                  5      $ r5   )rM   r    )r.   s    r0   __len__WMT16.__len__  s    4<<  r3   c                    g r5   r6   r.   r   r9   s      r0   get_dictWMT16.get_dict"  r;   r3   c                    g r5   r6   r   s      r0   r   r   '  r;   r3   c                    g r5   r6   r   s      r0   r   r   ,  r>   r3   c                ^   XR                   :X  a  U R                  OU R                  n[        R                  R                  [        R                  R                  R                  SU SU S35      n[        R                  R                  U5      (       d   S5       e  U R                  X5      $ )a  
return the word dictionary for the specified language.

Args:
    lang(string): A string indicating which language is the source
                  language. Available options are: "en" for English
                  and "de" for Germany.
    reverse(bool): If reverse is set to False, the returned python
                   dictionary will use word as key and use index as value.
                   If reverse is set to True, the returned python
                   dictionary will use index as key and word as value.

Returns:
    dict: The word dictionary for the specific language.

Examples:

    .. code-block:: python

        >>> from paddle.text.datasets import WMT16
        >>> wmt16 = WMT16(mode='train', src_dict_size=50, trg_dict_size=50)
        >>> en_dict = wmt16.get_dict('en')

r@   rA   rB   z Word dictionary does not exist. )r   r   r   rD   rE   rF   rG   rH   rI   rJ   rK   r+   )r.   r   r9   r8   rS   s        r0   r   r   1  s    4 #'))"3D9K9K 	 GGLLNN!!++TF!I;e,
	 ww~~i((L*LL(I"t//r3   )r-   r   r   r   r   r   r    r   r   r!   r"   )Nr   r   r   T)r   r   r   r   r   r   r   r   r   r   r/   boolreturnNone).)r   r   r8   r   r9   Literal[True]r   dict[int, str])r   r   r8   r   r9   Literal[False]r   r   )r   r   r8   r   r9   r   r   dict[int, str] | dict[str, int])F)rS   strr8   r   r   r   r   r   )r   r   )rX   r   r   zGtuple[npt.NDArray[np.int_], npt.NDArray[np.int_], npt.NDArray[np.int_]])r   r   )r   r   r9   r   r   r   )r   r   r9   r   r   r   )r   r   r9   r   r   r   )__name__
__module____qualname____firstlineno____doc____annotations__r1   r   r+   rO   r,   r   r   r   __static_attributes__r6   r3   r0   r   r   .   s0   FP 
!! !%")#*&*&  *& 	*&
 *& *& *& 
*&X MP"/2=J	  
 #&	   	
 
  DG."./2.=A.	(. .*""),"4B"	"0#7J



! =@"-:	  >A"-;	  47.".-1.	(. .$0r3   r   )
__future__r   rD   ri   collectionsr   typingr   r   r   numpyr   rG   paddle.dataset.commonr   	paddle.ior	   numpy.typingnptr   r   __all__r&   r'   r)   r*   rm   rn   ro   r   r6   r3   r0   <module>r      sw    # 	  # 3 3   <  67Z(N
?-
g0G g0r3   