o
    i
                     @   sb   d Z ddlZddlmZ ddlmZ ddlmZ G dd deZdd	d
dddidZ	dd Z
dS )zLanguage model interface.    N)ScorerInterface)dynamic_import)fill_missing_argsc                   @   s6   e Zd ZdZedd ZedefddZdd Z	d	S )
LMInterfacez-LM Interface for ESPnet model implementation.c                 C   s   | S )z.Add arguments to command line argument parser. parserr   r   L/home/ubuntu/.local/lib/python3.10/site-packages/espnet/nets/lm_interface.pyadd_arguments   s   zLMInterface.add_argumentsn_vocabc                    sH   ddl m   fdd}tjdi |}t||}t|| j}| ||S )zInitialize this class with python-level args.

        Args:
            idim (int): The number of vocabulary.

        Returns:
            LMinterface: A new instance of LMInterface.

        r   
get_parserc                    s    | ddS )NF)requiredr   r   r   r   r	   wrap    s   zLMInterface.build.<locals>.wrapNr   )espnet.bin.lm_trainr   argparse	Namespacer   r
   )clsr   kwargsr   argsr   r   r	   build   s   

zLMInterface.buildc                 C   s   t d)a)  Compute LM loss value from buffer sequences.

        Args:
            x (torch.Tensor): Input ids. (batch, len)
            t (torch.Tensor): Target ids. (batch, len)

        Returns:
            tuple[torch.Tensor, torch.Tensor, torch.Tensor]: Tuple of
                loss to backward (scalar),
                negative log-likelihood of t: -log p(t) (scalar) and
                the number of elements in x (scalar)

        Notes:
            The last two return values are used
            in perplexity: p(t)^{-n} = exp(-log p(t) / n)

        z!forward method is not implemented)NotImplementedError)selfxtr   r   r	   forward(   s   zLMInterface.forwardN)
__name__
__module____qualname____doc__staticmethodr
   classmethodintr   r   r   r   r   r	   r   
   s    
r   z3espnet.nets.pytorch_backend.lm.default:DefaultRNNLMz6espnet.nets.pytorch_backend.lm.seq_rnn:SequentialRNNLMz8espnet.nets.pytorch_backend.lm.transformer:TransformerLM)defaultseq_rnntransformerr#   z)espnet.lm.chainer_backend.lm:DefaultRNNLM)pytorchchainerc                 C   s0   t | t|t }t|tsJ |  d|S )zImport LM class dynamically.

    Args:
        module (str): module_name:class_name or alias in `predefined_lms`
        backend (str): NN backend. e.g., pytorch, chainer

    Returns:
        type: LM class

    z does not implement LMInterface)r   predefined_lmsgetdict
issubclassr   )modulebackendmodel_classr   r   r	   dynamic_import_lmG   s   r/   )r   r   espnet.nets.scorer_interfacer   espnet.utils.dynamic_importr   espnet.utils.fill_missing_argsr   r   r(   r/   r   r   r   r	   <module>   s    5
