text_classification.py 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. from modelscope.metainfo import Models
  3. from modelscope.models.builder import MODELS
  4. from modelscope.models.nlp import ModelForTextClassification
  5. from modelscope.utils import logger as logging
  6. from modelscope.utils.constant import Tasks
  7. logger = logging.get_logger()
  8. @MODELS.register_module(Tasks.text_classification, module_name=Models.bert)
  9. @MODELS.register_module(Tasks.nli, module_name=Models.bert)
  10. @MODELS.register_module(
  11. Tasks.sentiment_classification, module_name=Models.bert)
  12. @MODELS.register_module(Tasks.sentence_similarity, module_name=Models.bert)
  13. @MODELS.register_module(
  14. Tasks.zero_shot_classification, module_name=Models.bert)
  15. class BertForSequenceClassification(ModelForTextClassification):
  16. r"""Bert Model transformer with a sequence classification/regression head on top
  17. (a linear layer on top of the pooled output) e.g. for GLUE tasks.
  18. This model inherits from :class:`SequenceClassificationModel`. Check the superclass documentation for the generic
  19. methods the library implements for all its model (such as downloading or saving, resizing the input embeddings,
  20. pruning heads etc.)
  21. This model is also a PyTorch `torch.nn.Module <https://pytorch.org/docs/stable/nn.html#torch.nn.Module>`__
  22. subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to
  23. general usage and behavior.
  24. """
  25. base_model_type = 'bert'