o
    i                     @   sP   d Z ddlm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S )	)Embedding Frontend for text based inputs.    )TupleN)check_argument_types)AbsFrontend)PositionalEncodingc                       sl   e Zd ZdZddedfdededef fddZd	ej	d
ej	de
ej	ej	f fddZdefddZ  ZS )	Embeddingr   i  g?
input_size	embed_dimpositional_dropout_ratec                    s>   t  sJ t   || _tjtj|||||| _dS )a  Initialize.

        Args:
            input_size: Number of input tokens.
            embed_dim: Embedding Size.
            pos_enc_class: PositionalEncoding or ScaledPositionalEncoding
            positional_dropout_rate: dropout rate after adding positional encoding
        N)	r   super__init__r	   torchnn
Sequentialr   embed)selfr   r	   pos_enc_classr
   	__class__ Q/home/ubuntu/.local/lib/python3.10/site-packages/espnet2/mt/frontend/embedding.pyr      s   


zEmbedding.__init__inputinput_lengthsreturnc                 C   s   |  |}||fS )a!  Apply a sliding window on the input.

        Args:
            input: Input (B, T) or (B, T,D), with D.
            input_lengths: Input lengths within batch.

        Returns:
            Tensor: Output with dimensions (B, T, D).
            Tensor: Output lengths within batch.
        )r   )r   r   r   xr   r   r   forward+   s   
zEmbedding.forwardc                 C   s   | j S )zDReturn output length of feature dimension D, i.e. the embedding dim.)r	   )r   r   r   r   output_size<   s   zEmbedding.output_size)__name__
__module____qualname____doc__r   intfloatr   r   Tensorr   r   r   __classcell__r   r   r   r   r      s*    
r   )r    typingr   r   	typeguardr   !espnet2.asr.frontend.abs_frontendr   1espnet.nets.pytorch_backend.transformer.embeddingr   r   r   r   r   r   <module>   s   