o
    }oi                     @   sb   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
mZmZ dgZG dd deZdS )	    )DictOptional)MultiLayerPerceptron)
Classifier)	typecheck)
LogitsTypeLogprobsType
NeuralTypeSequenceClassifierc                       sx   e 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de
de	f fddZe dd Z  ZS )r
   returnc                 C   s&   | j sdtdt iS dtdt iS )Nlogits)BD	log_probs)log_softmaxr	   r   r   )self r   k/home/ubuntu/.local/lib/python3.10/site-packages/nemo/collections/nlp/modules/common/sequence_classifier.pyoutput_types   s   zSequenceClassifier.output_types   reluT        r   hidden_sizenum_classes
num_layers
activationr   dropoutuse_transformer_initidx_conditioned_onc	           	         s@   t  j||d || _|| _t|||||d| _| j|d dS )a  
        Initializes the SequenceClassifier module.
        Args:
            hidden_size: the hidden size of the mlp head on the top of the encoder
            num_classes: number of the classes to predict
            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
            log_softmax: applies the log softmax on the output
            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
        )r   r   )r   r   r   r   r   )r   N)super__init__r   _idx_conditioned_onr   mlp	post_init)	r   r   r   r   r   r   r   r   r   	__class__r   r   r    !   s   zSequenceClassifier.__init__c                 C   s&   |  |}| |d d | jf }|S )N)r   r"   r!   )r   hidden_statesr   r   r   r   forwardD   s   
zSequenceClassifier.forward)r   r   Tr   Tr   )__name__
__module____qualname__propertyr   r   strr	   r   intboolfloatr    r   r'   __classcell__r   r   r$   r   r
      s8    
	#N)typingr   r   nemo.collections.common.partsr   .nemo.collections.nlp.modules.common.classifierr   nemo.core.classesr   nemo.core.neural_typesr   r   r	   __all__r
   r   r   r   r   <module>   s   