o
    id                     @   s6   d Z ddlZddlmZ ddlmZ G dd dZdS )zMT Interface module.    N
get_parser)fill_missing_argsc                   @   sb   e Zd ZdZedd ZededefddZdd	 Z	dddZ
dddZdd Zedd Zd
S )MTInterfacez-MT Interface for ESPnet model implementation.c                 C   s   | S )zAdd arguments to parser. parserr   r   L/home/ubuntu/.local/lib/python3.10/site-packages/espnet/nets/mt_interface.pyadd_arguments   s   zMTInterface.add_argumentsidimodimc                 K   s:   dd }t jdi |}t||}t|| j}| |||S )a  Initialize this class with python-level args.

        Args:
            idim (int): The number of an input feature dim.
            odim (int): The number of output vocab.

        Returns:
            ASRinterface: A new instance of ASRInterface.

        c                 S   s   t | ddS )NF)requiredr   r   r   r   r	   wrap   s   zMTInterface.build.<locals>.wrapNr   )argparse	Namespacer   r
   )clsr   r   kwargsr   argsr   r   r	   build   s
   
zMTInterface.buildc                 C      t d)ae  Compute loss for training.

        :param xs:
            For pytorch, batch of padded source sequences torch.Tensor (B, Tmax, idim)
            For chainer, list of source sequences chainer.Variable
        :param ilens: batch of lengths of source sequences (B)
            For pytorch, torch.Tensor
            For chainer, list of int
        :param ys:
            For pytorch, batch of padded source sequences torch.Tensor (B, Lmax)
            For chainer, list of source sequences chainer.Variable
        :return: loss value
        :rtype: torch.Tensor for pytorch, chainer.Variable for chainer
        z!forward method is not implementedNotImplementedErrorselfxsilensysr   r   r	   forward%   s   zMTInterface.forwardNc                 C   r   )aa  Translate x for evaluation.

        :param ndarray x: input acouctic feature (B, T, D) or (T, D)
        :param namespace trans_args: argment namespace contraining options
        :param list char_list: list of characters
        :param torch.nn.Module rnnlm: language model module
        :return: N-best decoding results
        :rtype: list
        z#translate method is not implementedr   r   x
trans_args	char_listrnnlmr   r   r	   	translate6      
zMTInterface.translatec                 C   r   )at  Beam search implementation for batch.

        :param torch.Tensor x: encoder hidden state sequences (B, Tmax, Henc)
        :param namespace trans_args: argument namespace containing options
        :param list char_list: list of characters
        :param torch.nn.Module rnnlm: language model module
        :return: N-best decoding results
        :rtype: list
        z$Batch decoding is not supported yet.r   r   r   r   r	   translate_batchB   r$   zMTInterface.translate_batchc                 C   r   )a_  Calculate attention.

        :param list xs: list of padded input sequences [(T1, idim), (T2, idim), ...]
        :param ndarray ilens: batch of lengths of input sequences (B)
        :param list ys: list of character id sequence tensor [(L1), (L2), (L3), ...]
        :return: attention weights (B, Lmax, Tmax)
        :rtype: float ndarray
        z2calculate_all_attentions method is not implementedr   r   r   r   r	   calculate_all_attentionsN   s   	z$MTInterface.calculate_all_attentionsc                 C   s   ddl m} |S )zGet attention plot class.r   )PlotAttentionReport)espnet.asr.asr_utilsr'   )r   r'   r   r   r	   attention_plot_classY   s   z MTInterface.attention_plot_class)NN)__name__
__module____qualname____doc__staticmethodr
   classmethodintr   r   r#   r%   r&   propertyr)   r   r   r   r	   r      s    


r   )r-   r   espnet.bin.asr_trainr   espnet.utils.fill_missing_argsr   r   r   r   r   r	   <module>   s
    