o
    }oi
                     @   sj   d dl mZmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZ dgZG dd deZd	S )
    )DictOptional)Tensor)MultiLayerPerceptron)
Classifier)	typecheck)
NeuralTypeRegressionValuesTypeSequenceRegressionc                       s|   e Zd ZdZedeeeef  fddZ							dd
e
de
dededede
f fddZe dedefddZ  ZS )r
   a,  
    Args:
        hidden_size: the hidden size of the mlp head on the top of the encoder
        num_layers: number of the linear layers of the mlp head on the top of the encoder
        activation: type of activations between layers of the mlp head
        dropout: the dropout used for the mlp head
        use_transformer_init: initializes the weights with the same approach used in Transformer
        idx_conditioned_on: index of the token to use as the sequence representation for the classification task,
            default is the first token
    returnc                 C   s   dt tdt iS )NpredsB)r   tupler	   )self r   k/home/ubuntu/.local/lib/python3.10/site-packages/nemo/collections/nlp/modules/common/sequence_regression.pyoutput_types'   s   zSequenceRegression.output_types   relu        Tr   hidden_size
num_layers
activationdropoutuse_transformer_initidx_conditioned_onc                    s:   t  j||d || _t|d||dd| _| j|d dS )z, Initializes the SequenceRegression module. )r   r      F)num_classesr   r   log_softmax)r   N)super__init___idx_conditioned_onr   mlp	post_init)r   r   r   r   r   r   r   	__class__r   r   r    +   s   

zSequenceRegression.__init__hidden_statesc                 C   s,   |  |}| |dd| jf }|dS )z Forward pass through the module.

        Args:
            hidden_states: hidden states for each token in a sequence, for example, BERT module output
        N)r   r"   r!   view)r   r&   r   r   r   r   forward<   s   

zSequenceRegression.forward)r   r   r   Tr   )__name__
__module____qualname____doc__propertyr   r   strr   r   intfloatboolr    r   r   r)   __classcell__r   r   r$   r   r
      s0    N)typingr   r   torchr   nemo.collections.common.partsr   .nemo.collections.nlp.modules.common.classifierr   nemo.core.classesr   nemo.core.neural_typesr   r	   __all__r
   r   r   r   r   <module>   s   