o
    ߥix                     @   s   d dl mZmZ d dlZ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gZe	jejejd	G d
d deZdS )    )AnyDictN)Heads
TaskModels)MODELS)EncoderModel)Tasks)parse_label_mappingModelForTextClassification)module_namec                       s:   e Zd ZejZejZdef fddZ	 fddZ
  ZS )r
   	model_dirc                    sv   i | _ |d}|du r(t|}|durt|dkrt|}dd | D | _ ||d< t j|g|R i | dS )zinitialize the sequence classification model from the `model_dir` path.

        Args:
            model_dir (str): the model path.
        
num_labelsNr   c                 S   s   i | ]\}}||qS  r   ).0labelidr   r   i/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/models/nlp/task_models/text_classification.py
<dictcomp>&   s    z7ModelForTextClassification.__init__.<locals>.<dictcomp>)id2labelgetr	   lenitemssuper__init__)selfr   argskwargsr   label2id	__class__r   r   r      s   
z#ModelForTextClassification.__init__c                    sL   t   }t|dr|d d ur|jn|j|d< n|j|d< | jj|d< |S )Nclassifier_dropoutr   )r   parse_head_cfghasattrr    hidden_dropout_probconfigr   )r   head_cfgr   r   r   r!   *   s   



z)ModelForTextClassification.parse_head_cfg)__name__
__module____qualname__r   text_classificationtaskr   	head_typestrr   r!   __classcell__r   r   r   r   r
      s
    )typingr   r   numpynpmodelscope.metainfor   r   modelscope.models.builderr   ,modelscope.models.nlp.task_models.task_modelr   modelscope.utils.constantr   modelscope.utils.hubr	   __all__register_moduler)   r
   r   r   r   r   <module>   s   