
    9i!                         S SK r S SKJr  S SKJr  S SKJrJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr  S	S
KJr  \	R$                  " \R&                  \R(                  S9 " S S\\5      5       rg)    N)RobertaForTokenClassification)Models)Model
TorchModel)MODELS)'AttentionTokenClassificationModelOutput)Tasks)parse_labels_in_order   )
VecoConfig)module_namec                   R   ^  \ rS rSrSr\rU 4S jrU 4S jr\	U 4S j5       r
SrU =r$ )VecoForTokenClassification   aD  Veco Model with a token classification head on top (a linear layer on top of the hidden-states output) e.g.
for Named-Entity-Recognition (NER) tasks.

This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic
methods the library implements for all its model (such as downloading or saving, resizing the input embeddings,
pruning heads etc.)

This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module)
subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to
general usage and behavior.

Parameters:
    config ([`VecoConfig`]): Model configuration class with all the parameters of the
        model. Initializing with a config file does not load the weights associated with the model, only the
        configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model
        weights.

This class overrides [`RobertaForTokenClassification`]. Please check the superclass for the
appropriate documentation alongside usage examples.
c                 b   > [         TU ]  " UR                  40 UD6  [         [        U ]  U5        g )N)super__init__name_or_pathr   )selfconfigkwargs	__class__s      o/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/models/nlp/veco/token_classification.pyr   #VecoForTokenClassification.__init__7   s*    ,,77eT#F+    c                    > SUS'   [         [        U ]
  " U0 UD6n[        UR                  UR
                  UR                  UR                  S9$ )NTreturn_dict)losslogitshidden_states
attentions)r   r   forwardr   r   r   r    r!   )r   argsr   outputsr   s       r   r"   "VecoForTokenClassification.forward;   sP     $}t,d=f=6>>!//))	
 	
r   c                    > UR                  SS5      nUR                  SS5      n[        X#40 UD6nUc  [        S0 UD6nU " U5      nU$ [        [        U ]  " SSU0UD6nU$ )a$  Instantiate the model.

Args:
    kwargs: Input args.
            model_dir: The model dir used to load the checkpoint and the label information.
            num_labels: An optional arg to tell the model how many classes to initialize.
                            Method will call utils.parse_label_mapping if num_labels is not input.
            label2id: An optional label2id mapping, which will cover the label2id in configuration (if exists).

Returns:
    The loaded model, which is initialized by transformers.PreTrainedModel.from_pretrained
	model_dirNcfgpretrained_model_name_or_path )popr
   r   r   r   from_pretrained)clsr   r'   r(   
model_argsr   modelr   s          r   _instantiate'VecoForTokenClassification._instantiateF   s     JJ{D1	jj%*9DVD
-*-FKE  %5 G.7G;EGEr   r*   )__name__
__module____qualname____firstlineno____doc__r   config_classr   r"   classmethodr0   __static_attributes____classcell__)r   s   @r   r   r      s-    * L,	
  r   r   )torchtransformersr   modelscope.metainfor   modelscope.modelsr   r   modelscope.models.builderr   modelscope.outputsr   modelscope.utils.constantr	   modelscope.utils.nlp.utilsr
   configurationr   register_moduletoken_classificationvecor   r*   r   r   <module>rG      s[   $  6 & / , F + < % 22L@-J @ M@r   