TextClassifier¶
- class flash.text.classification.model.TextClassifier(num_classes=None, labels=None, backbone='prajjwal1/bert-medium', max_length=128, loss_fn=None, optimizer='Adam', lr_scheduler=None, metrics=None, learning_rate=None, multi_label=False, enable_ort=False, **kwargs)[source]¶
The
TextClassifieris aTaskfor classifying text. For more details, see Text Classification. TheTextClassifieralso supports multi-label classification withmulti_label=True. For more details, see Multi-label Text Classification.- Parameters
num_classes¶ (
Optional[int]) – Number of classes to classify.backbone¶ (
str) – A model to use to compute text features can be any BERT model from HuggingFace/transformersimage.max_length¶ (
int) – The maximum length to pad / truncate sequences to.optimizer¶ (
TypeVar(OPTIMIZER_TYPE,str,Callable,Tuple[str,Dict[str,Any]],None)) – Optimizer to use for training.lr_scheduler¶ (
Optional[TypeVar(LR_SCHEDULER_TYPE,str,Callable,Tuple[str,Dict[str,Any]],Tuple[str,Dict[str,Any],Dict[str,Any]],None)]) – The LR scheduler to use during training.metrics¶ (
Optional[TypeVar(METRICS_TYPE,Metric,Mapping,Sequence,None)]) – 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 totorchmetrics.Accuracy.learning_rate¶ (
Optional[float]) – Learning rate to use for training, defaults to 1e-3multi_label¶ (
bool) – Whether the targets are multi-label or not.enable_ort¶ (
bool) – Enable Torch ONNX Runtime Optimization: https://onnxruntime.ai/docs/#onnx-runtime-for-training
- classmethod available_finetuning_strategies(cls)¶
Returns a list containing the keys of the available Finetuning Strategies.
- classmethod available_lr_schedulers(cls)¶
Returns a list containing the keys of the available LR schedulers.
- classmethod available_optimizers(cls)¶
Returns a list containing the keys of the available Optimizers.