class_docstr: The ``TextClassifier`` is a :class:`~flash.Task` for classifying text. For more details, see
  :ref:`text_classification`. The ``TextClassifier`` also supports multi-label classification with
  ``multi_label=True``. For more details, see :ref:`text_classification_multi_label`.
  
  Args:
      num_classes: Number of classes to classify.
      backbone: A model to use to compute text features can be any BERT model from HuggingFace/transformersimage.
      max_length: The maximum length to pad / truncate sequences to.
      optimizer: Optimizer to use for training.
      lr_scheduler: The LR scheduler to use during training.
      metrics: Metrics to compute for training and evaluation. Can either be an metric from the `torchmetrics`
          package, a custom metric inherenting from `torchmetrics.Metric`, a callable function or a list/dict
          containing a combination of the aforementioned. In all cases, each metric needs to have the signature
          `metric(preds,target)` and return a single scalar tensor. Defaults to :class:`torchmetrics.Accuracy`.
      learning_rate: Learning rate to use for training, defaults to `1e-3`
      multi_label: Whether the targets are multi-label or not.
      enable_ort: Enable Torch ONNX Runtime Optimization: https://onnxruntime.ai/docs/#onnx-runtime-for-training
class_docstr_tok: ["The","``","TextClassifier","``","is","a",":","class",":","`","~flash.Task","`","for","classifying","text",".","For","more","details",",","see",":","ref",":","`","text_classification","`",".","The","``","TextClassifier","``","also","supports","multi-label","classification","with","``","multi_label=True","``",".","For","more","details",",","see",":","ref",":","`","text_classification_multi_label","`",".","Args",":","num_classes",":","Number","of","classes","to","classify",".","backbone",":","A","model","to","use","to","compute","text","features","can","be","any","BERT","model","from","HuggingFace\/transformersimage",".","max_length",":","The","maximum","length","to","pad","\/","truncate","sequences","to",".","optimizer",":","Optimizer","to","use","for","training",".","lr_scheduler",":","The","LR","scheduler","to","use","during","training",".","metrics",":","Metrics","to","compute","for","training","and","evaluation",".","Can","either","be","an","metric","from","the","`","torchmetrics","`","package",",","a","custom","metric","inherenting","from","`","torchmetrics.Metric","`",",","a","callable","function","or","a","list\/dict","containing","a","combination","of","the","aforementioned",".","In","all","cases",",","each","metric","needs","to","have","the","signature","`","metric","(","preds",",","target",")","`","and","return","a","single","scalar","tensor",".","Defaults","to",":","class",":","`","torchmetrics.Accuracy","`",".","learning_rate",":","Learning","rate","to","use","for","training",",","defaults","to","`","1e-3","`","multi_label",":","Whether","the","targets","are","multi-label","or","not",".","enable_ort",":","Enable","Torch","ONNX","Runtime","Optimization",":","https",":","\/\/onnxruntime.ai\/docs\/","#","onnx-runtime-for-training"]
code: def __init__(
      self,
      num_classes: Optional[int] = None,
      labels: Optional[List[str]] = None,
      backbone: str = "prajjwal1/bert-medium",
      max_length: int = 128,
      loss_fn: LOSS_FN_TYPE = None,
      optimizer: OPTIMIZER_TYPE = "Adam",
      lr_scheduler: LR_SCHEDULER_TYPE = None,
      metrics: METRICS_TYPE = None,
      learning_rate: Optional[float] = None,
      multi_label: bool = False,
      enable_ort: bool = False,
      **kwargs,
  ):
      self.save_hyperparameters()
  
      if labels is not None and num_classes is None:
          num_classes = len(labels)
  
      metadata = self.backbones.get(backbone, with_metadata=True)
      adapter = metadata["metadata"]["adapter"].from_task(
          self,
          backbone=metadata["fn"],
          num_classes=num_classes,
          max_length=max_length,
          **kwargs,
      )
  
      super().__init__(
          adapter,
          loss_fn=loss_fn,
          learning_rate=learning_rate,
          optimizer=optimizer,
          lr_scheduler=lr_scheduler,
          metrics=metrics,
          multi_label=multi_label,
          num_classes=num_classes,
          labels=labels,
      )
  
      self.enable_ort = enable_ort
      self.max_length = max_length
  
file_path: lightning-flash/src/flash/text/classification/model.py
imports: from typing import Any, Dict, List, Optional, Type, Union
  from pytorch_lightning import Callback
  from flash.core.classification import ClassificationAdapterTask
  from flash.core.data.io.input import ServeInput
  from flash.core.data.io.input_transform import InputTransform
  from flash.core.data.io.output import Output
  from flash.core.registry import FlashRegistry
  from flash.core.serve import Composition
  from flash.core.utilities.imports import requires
  from flash.core.utilities.types import INPUT_TRANSFORM_TYPE, LOSS_FN_TYPE, LR_SCHEDULER_TYPE, METRICS_TYPE, OPTIMIZER_TYPE
  from flash.text.classification.backbones import TEXT_CLASSIFIER_BACKBONES
  from flash.text.input import TextDeserializer
  from flash.text.ort_callback import ORTCallback
label_desc: Use image node_id 1 to create a new TextClassifier object from inherited base classes: ClassificationAdapterTask with example: obj = TextClassifier(num_classes, labels, backbone, max_length, loss_fn, optimizer, lr_scheduler, metrics, learning_rate, multi_label, enable_ort)