# Trainer Classes

## TrainingArguments[[setfit.TrainingArguments]]

#### setfit.TrainingArguments[[setfit.TrainingArguments]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/training_args.py#L23)

TrainingArguments is the subset of the arguments which relate to the training loop itself.
Note that training with SetFit consists of two phases behind the scenes: **finetuning embeddings** and
**training a classification head**. As a result, some of the training arguments can be tuples,
where the two values are used for each of the two phases, respectively. The second value is often only
used when training the model was loaded using `use_differentiable_head=True`.

to_dictsetfit.TrainingArguments.to_dicthttps://github.com/huggingface/setfit/blob/main/src/setfit/training_args.py#L319[]`Dict[str, Any]`The dictionary variant of this dataclass.
Convert this instance to a dictionary.

**Parameters:**

output_dir (`str`, defaults to `"checkpoints"`) : The output directory where the model predictions and checkpoints will be written.

batch_size (`Union[int, Tuple[int, int]]`, defaults to `(16, 2)`) : Set the batch sizes for the embedding and classifier training phases respectively, or set both if an integer is provided. Note that the batch size for the classifier is only used with a differentiable PyTorch head.

num_epochs (`Union[int, Tuple[int, int]]`, defaults to `(1, 16)`) : Set the number of epochs the embedding and classifier training phases respectively, or set both if an integer is provided. Note that the number of epochs for the classifier is only used with a differentiable PyTorch head.

max_steps (`int`, defaults to `-1`) : If set to a positive number, the total number of training steps to perform. Overrides `num_epochs`. The training may stop before reaching the set number of steps when all data is exhausted.

sampling_strategy (`str`, defaults to `"oversampling"`) : The sampling strategy of how to draw pairs in training. Possible values are:  - `"oversampling"`: Draws even number of positive/ negative sentence pairs until every sentence pair has been drawn. - `"undersampling"`: Draws the minimum number of positive/ negative sentence pairs until every sentence pair in the minority class has been drawn. - `"unique"`: Draws every sentence pair combination (likely resulting in unbalanced number of positive/ negative sentence pairs).  The default is set to `"oversampling"`, ensuring all sentence pairs are drawn at least once. Alternatively, setting `num_iterations` will override this argument and determine the number of generated sentence pairs.

num_iterations (`int`, *optional*) : If not set the `sampling_strategy` will determine the number of sentence pairs to generate. This argument sets the number of iterations to generate sentence pairs for and provides compatability with Setfit = 1.6.0

warmup_proportion (`float`, defaults to `0.1`) : Proportion of the warmup in the total training steps. Must be greater than or equal to 0.0 and less than or equal to 1.0.

l2_weight (`float`, *optional*) : Optional l2 weight for both the model body and head, passed to the `AdamW` optimizer in the classifier training phase if a differentiable PyTorch head is used.

max_length (`int`, *optional*) : The maximum token length a tokenizer can generate. If not provided, the maximum length for the `SentenceTransformer` body is used.

samples_per_label (`int`, defaults to `2`) : Number of consecutive, random and unique samples drawn per label. This is only relevant for triplet loss and ignored for `CosineSimilarityLoss`. Batch size should be a multiple of samples_per_label.

show_progress_bar (`bool`, defaults to `True`) : Whether to display a progress bar for the training epochs and iterations.

seed (`int`, defaults to `42`) : Random seed that will be set at the beginning of training. To ensure reproducibility across runs, use the `model_init` argument to [Trainer](/docs/setfit/main/en/reference/trainer#setfit.Trainer) to instantiate the model if it has some randomly initialized parameters.

report_to (`str` or `List[str]`, *optional*, defaults to `"all"`) : The list of integrations to report the results and logs to. Supported platforms are `"azure_ml"`, `"comet_ml"`, `"mlflow"`, `"neptune"`, `"tensorboard"`,`"clearml"` and `"wandb"`. Use `"all"` to report to all integrations installed, `"none"` for no integrations.

run_name (`str`, *optional*) : A descriptor for the run. Typically used for [wandb](https://www.wandb.com/) and [mlflow](https://www.mlflow.org/) logging.

logging_dir (`str`, *optional*) : [TensorBoard](https://www.tensorflow.org/tensorboard) log directory. Will default to *runs/**CURRENT_DATETIME_HOSTNAME***.

logging_strategy (`str` or `IntervalStrategy`, *optional*, defaults to `"steps"`) : The logging strategy to adopt during training. Possible values are:  - `"no"`: No logging is done during training. - `"epoch"`: Logging is done at the end of each epoch. - `"steps"`: Logging is done every `logging_steps`. 

logging_first_step (`bool`, *optional*, defaults to `False`) : Whether to log and evaluate the first `global_step` or not.

logging_steps (`int`, defaults to 50) : Number of update steps between two logs if `logging_strategy="steps"`.

eval_strategy (`str` or `IntervalStrategy`, *optional*, defaults to `"no"`) : The evaluation strategy to adopt during training. Possible values are:  - `"no"`: No evaluation is done during training. - `"steps"`: Evaluation is done (and logged) every `eval_steps`. - `"epoch"`: Evaluation is done at the end of each epoch. 

eval_steps (`int`, *optional*) : Number of update steps between two evaluations if `eval_strategy="steps"`. Will default to the same value as `logging_steps` if not set.

eval_delay (`float`, *optional*) : Number of epochs or steps to wait for before the first evaluation can be performed, depending on the eval_strategy.

eval_max_steps (`int`, defaults to `-1`) : If set to a positive number, the total number of evaluation steps to perform. The evaluation may stop before reaching the set number of steps when all data is exhausted. 

save_strategy (`str` or `IntervalStrategy`, *optional*, defaults to `"steps"`) : The checkpoint save strategy to adopt during training. Possible values are:  - `"no"`: No save is done during training. - `"epoch"`: Save is done at the end of each epoch. - `"steps"`: Save is done every `save_steps`.

save_steps (`int`, *optional*, defaults to 500) : Number of updates steps before two checkpoint saves if `save_strategy="steps"`.

save_total_limit (`int`, *optional*, defaults to `1`) : If a value is passed, will limit the total amount of checkpoints. Deletes the older checkpoints in `output_dir`. Note, the best model is always preserved if the `eval_strategy` is not `"no"`.

load_best_model_at_end (`bool`, *optional*, defaults to `False`) : Whether or not to load the best model found during training at the end of training.    When set to `True`, the parameters `save_strategy` needs to be the same as `eval_strategy`, and in the case it is "steps", `save_steps` must be a round multiple of `eval_steps`.  

**Returns:**

``Dict[str, Any]``

The dictionary variant of this dataclass.
#### from_dict[[setfit.TrainingArguments.from_dict]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/training_args.py#L327)

Initialize a TrainingArguments instance from a dictionary.

**Parameters:**

arguments (`Dict[str, Any]`) : A dictionary of arguments.

ignore_extra (`bool`, *optional*) : Whether to ignore arguments that do not occur in the TrainingArguments __init__ signature. Defaults to False.

**Returns:**

``TrainingArguments``

The instantiated TrainingArguments instance.
#### copy[[setfit.TrainingArguments.copy]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/training_args.py#L343)

Create a shallow copy of this TrainingArguments instance.
#### update[[setfit.TrainingArguments.update]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/training_args.py#L347)

## Trainer[[setfit.Trainer]]

#### setfit.Trainer[[setfit.Trainer]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L257)

Trainer to train a SetFit model.

add_callbacksetfit.Trainer.add_callbackhttps://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L367[{"name": "callback", "val": ": typing.Union[type, transformers.trainer_callback.TrainerCallback]"}]- **callback** (`type` or [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)) --
  A [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback) class or an instance of a [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback). In the
  first case, will instantiate a member of that class.0

Add a callback to the current list of [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback).

**Parameters:**

model (`SetFitModel`, *optional*) : The model to train. If not provided, a `model_init` must be passed.

args (`TrainingArguments`, *optional*) : The training arguments to use.

train_dataset (`Dataset`) : The training dataset.

eval_dataset (`Dataset`, *optional*) : The evaluation dataset.

model_init (`Callable[[], SetFitModel]`, *optional*) : A function that instantiates the model to be used. If provided, each call to [Trainer.train()](/docs/setfit/main/en/reference/trainer#setfit.Trainer.train) will start from a new instance of the model as given by this function when a `trial` is passed.

metric (`str` or `Callable`, *optional*, defaults to `"accuracy"`) : The metric to use for evaluation. If a string is provided, we treat it as the metric name and load it with default settings. If a callable is provided, it must take two arguments (`y_pred`, `y_test`) and return a dictionary with metric keys to values.

metric_kwargs (`Dict[str, Any]`, *optional*) : Keyword arguments passed to the evaluation function if `metric` is an evaluation string like "f1". For example useful for providing an averaging strategy for computing f1 in a multi-label setting.

callbacks (`List[`[TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)`]`, *optional*) : A list of callbacks to customize the training loop. Will add those to the list of default callbacks detailed in [here](https://huggingface.co/docs/transformers/main/en/main_classes/callback). If you want to remove one of the default callbacks used, use the [Trainer.remove_callback()](/docs/setfit/main/en/reference/trainer#setfit.Trainer.remove_callback) method.

column_mapping (`Dict[str, str]`, *optional*) : A mapping from the column names in the dataset to the column names expected by the model. The expected format is a dictionary with the following format: `{"text_column_name": "text", "label_column_name": "label"}`.
#### apply_hyperparameters[[setfit.Trainer.apply_hyperparameters]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L405)

Applies a dictionary of hyperparameters to both the trainer and the model

**Parameters:**

params (`Dict[str, Any]`) : The parameters, usually from `BestRun.hyperparameters`

final_model (`bool`, *optional*, defaults to `False`) : If `True`, replace the `model_init()` function with a fixed model based on the parameters.
#### evaluate[[setfit.Trainer.evaluate]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L658)

Computes the metrics for a given classifier.

**Parameters:**

dataset (`Dataset`, *optional*) : The dataset to compute the metrics on. If not provided, will use the evaluation dataset passed via the `eval_dataset` argument at `Trainer` initialization.

**Returns:**

``Dict[str, float]``

The evaluation metrics.
#### hyperparameter_search[[setfit.Trainer.hyperparameter_search]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L720)

Launch a hyperparameter search using `optuna`. The optimized quantity is determined
by `compute_objective`, which defaults to a function returning the evaluation loss when no metric is provided,
the sum of all metrics otherwise.

To use this method, you need to have provided a `model_init` when initializing your [Trainer](/docs/setfit/main/en/reference/trainer#setfit.Trainer): we need to
reinitialize the model at each new run.

**Parameters:**

hp_space (`Callable[["optuna.Trial"], Dict[str, float]]`, *optional*) : A function that defines the hyperparameter search space. Will default to `default_hp_space_optuna`.

compute_objective (`Callable[[Dict[str, float]], float]`, *optional*) : A function computing the objective to minimize or maximize from the metrics returned by the `evaluate` method. Will default to `default_compute_objective` which uses the sum of metrics.

n_trials (`int`, *optional*, defaults to 100) : The number of trial runs to test.

direction (`str`, *optional*, defaults to `"maximize"`) : Whether to optimize greater or lower objects. Can be `"minimize"` or `"maximize"`, you should pick `"minimize"` when optimizing the validation loss, `"maximize"` when optimizing one or several metrics.

backend (`str` or `HPSearchBackend`, *optional*) : The backend to use for hyperparameter search. Only optuna is supported for now. TODO: add support for ray and sigopt.

hp_name (`Callable[["optuna.Trial"], str]]`, *optional*) : A function that defines the trial/run name. Will default to None.

kwargs (`Dict[str, Any]`, *optional*) : Additional keyword arguments passed along to `optuna.create_study`. For more information see:  - the documentation of [optuna.create_study](https://optuna.readthedocs.io/en/stable/reference/generated/optuna.study.create_study.html)

**Returns:**

``trainer_utils.BestRun``

All the information about the best run.
#### pop_callback[[setfit.Trainer.pop_callback]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L378)

Remove a callback from the current list of [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback) and returns it.

If the callback is not found, returns `None` (and no error is raised).

**Parameters:**

callback (`type` or [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)) : A [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback) class or an instance of a [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback). In the first case, will pop the first member of that class found in the list of callbacks.

**Returns:**

`[TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)`

The callback removed, if found.
#### push_to_hub[[setfit.Trainer.push_to_hub]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L796)

Upload model checkpoint to the Hub using `huggingface_hub`.

See the full list of parameters for your `huggingface_hub` version in the        [huggingface_hub documentation](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.ModelHubMixin.push_to_hub).

**Parameters:**

repo_id (`str`) : The full repository ID to push to, e.g. `"tomaarsen/setfit-sst2"`.

config (`dict`, *optional*) : Configuration object to be saved alongside the model weights.

commit_message (`str`, *optional*) : Message to commit while pushing.

private (`bool`, *optional*) : Whether to make the repo private. If `None` (default), the repo will be public unless the organization's default is private. This value is ignored if the repo already exists.

api_endpoint (`str`, *optional*) : The API endpoint to use when pushing the model to the hub.

token (`str`, *optional*) : The token to use as HTTP bearer authorization for remote files. If not set, will use the token set when logging in with `transformers-cli login` (stored in `~/.huggingface`).

branch (`str`, *optional*) : The git branch on which to push the model. This defaults to the default branch as specified in your repository, which defaults to `"main"`.

create_pr (`boolean`, *optional*) : Whether or not to create a Pull Request from `branch` with that commit. Defaults to `False`.

allow_patterns (`List[str]` or `str`, *optional*) : If provided, only files matching at least one pattern are pushed.

ignore_patterns (`List[str]` or `str`, *optional*) : If provided, files matching any of the patterns are not pushed.

**Returns:**

`str`

The url of the commit of your model in the given repository.
#### remove_callback[[setfit.Trainer.remove_callback]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L394)

Remove a callback from the current list of [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback).

**Parameters:**

callback (`type` or [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)) : A [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback) class or an instance of a [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback). In the first case, will remove the first member of that class found in the list of callbacks.
#### train[[setfit.Trainer.train]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L492)

Main training entry point.

**Parameters:**

args (`TrainingArguments`, *optional*) : Temporarily change the training arguments for this training call.

trial (`optuna.Trial` or `Dict[str, Any]`, *optional*) : The trial run or the hyperparameter dictionary for hyperparameter search.
#### train_classifier[[setfit.Trainer.train_classifier]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L631)

Method to perform the classifier phase: fitting a classifier head.

**Parameters:**

x_train (`List[str]`) : A list of training sentences.

y_train (`Union[List[int], List[List[int]]]`) : A list of labels corresponding to the training sentences.

args (`TrainingArguments`, *optional*) : Temporarily change the training arguments for this training call.
#### train_embeddings[[setfit.Trainer.train_embeddings]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L537)

Method to perform the embedding phase: finetuning the `SentenceTransformer` body.

**Parameters:**

x_train (`List[str]`) : A list of training sentences.

y_train (`Union[List[int], List[List[int]]]`) : A list of labels corresponding to the training sentences.

args (`TrainingArguments`, *optional*) : Temporarily change the training arguments for this training call.

## DistillationTrainer[[setfit.DistillationTrainer]]

#### setfit.DistillationTrainer[[setfit.DistillationTrainer]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer_distillation.py#L23)

Trainer to compress a SetFit model with knowledge distillation.

add_callbacksetfit.DistillationTrainer.add_callbackhttps://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L367[{"name": "callback", "val": ": typing.Union[type, transformers.trainer_callback.TrainerCallback]"}]- **callback** (`type` or [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)) --
  A [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback) class or an instance of a [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback). In the
  first case, will instantiate a member of that class.0

Add a callback to the current list of [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback).

**Parameters:**

teacher_model (`SetFitModel`) : The teacher model to mimic.

student_model (`SetFitModel`, *optional*) : The model to train. If not provided, a `model_init` must be passed.

args (`TrainingArguments`, *optional*) : The training arguments to use.

train_dataset (`Dataset`) : The training dataset.

eval_dataset (`Dataset`, *optional*) : The evaluation dataset.

model_init (`Callable[[], SetFitModel]`, *optional*) : A function that instantiates the model to be used. If provided, each call to [train()](/docs/setfit/main/en/reference/trainer#setfit.Trainer.train) will start from a new instance of the model as given by this function when a `trial` is passed.

metric (`str` or `Callable`, *optional*, defaults to `"accuracy"`) : The metric to use for evaluation. If a string is provided, we treat it as the metric name and load it with default settings. If a callable is provided, it must take two arguments (`y_pred`, `y_test`).

column_mapping (`Dict[str, str]`, *optional*) : A mapping from the column names in the dataset to the column names expected by the model. The expected format is a dictionary with the following format: `{"text_column_name": "text", "label_column_name": "label"}`.
#### apply_hyperparameters[[setfit.DistillationTrainer.apply_hyperparameters]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L405)

Applies a dictionary of hyperparameters to both the trainer and the model

**Parameters:**

params (`Dict[str, Any]`) : The parameters, usually from `BestRun.hyperparameters`

final_model (`bool`, *optional*, defaults to `False`) : If `True`, replace the `model_init()` function with a fixed model based on the parameters.
#### evaluate[[setfit.DistillationTrainer.evaluate]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L658)

Computes the metrics for a given classifier.

**Parameters:**

dataset (`Dataset`, *optional*) : The dataset to compute the metrics on. If not provided, will use the evaluation dataset passed via the `eval_dataset` argument at `Trainer` initialization.

**Returns:**

``Dict[str, float]``

The evaluation metrics.
#### hyperparameter_search[[setfit.DistillationTrainer.hyperparameter_search]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L720)

Launch a hyperparameter search using `optuna`. The optimized quantity is determined
by `compute_objective`, which defaults to a function returning the evaluation loss when no metric is provided,
the sum of all metrics otherwise.

To use this method, you need to have provided a `model_init` when initializing your [Trainer](/docs/setfit/main/en/reference/trainer#setfit.Trainer): we need to
reinitialize the model at each new run.

**Parameters:**

hp_space (`Callable[["optuna.Trial"], Dict[str, float]]`, *optional*) : A function that defines the hyperparameter search space. Will default to `default_hp_space_optuna`.

compute_objective (`Callable[[Dict[str, float]], float]`, *optional*) : A function computing the objective to minimize or maximize from the metrics returned by the `evaluate` method. Will default to `default_compute_objective` which uses the sum of metrics.

n_trials (`int`, *optional*, defaults to 100) : The number of trial runs to test.

direction (`str`, *optional*, defaults to `"maximize"`) : Whether to optimize greater or lower objects. Can be `"minimize"` or `"maximize"`, you should pick `"minimize"` when optimizing the validation loss, `"maximize"` when optimizing one or several metrics.

backend (`str` or `HPSearchBackend`, *optional*) : The backend to use for hyperparameter search. Only optuna is supported for now. TODO: add support for ray and sigopt.

hp_name (`Callable[["optuna.Trial"], str]]`, *optional*) : A function that defines the trial/run name. Will default to None.

kwargs (`Dict[str, Any]`, *optional*) : Additional keyword arguments passed along to `optuna.create_study`. For more information see:  - the documentation of [optuna.create_study](https://optuna.readthedocs.io/en/stable/reference/generated/optuna.study.create_study.html)

**Returns:**

``trainer_utils.BestRun``

All the information about the best run.
#### pop_callback[[setfit.DistillationTrainer.pop_callback]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L378)

Remove a callback from the current list of [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback) and returns it.

If the callback is not found, returns `None` (and no error is raised).

**Parameters:**

callback (`type` or [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)) : A [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback) class or an instance of a [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback). In the first case, will pop the first member of that class found in the list of callbacks.

**Returns:**

`[TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)`

The callback removed, if found.
#### push_to_hub[[setfit.DistillationTrainer.push_to_hub]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L796)

Upload model checkpoint to the Hub using `huggingface_hub`.

See the full list of parameters for your `huggingface_hub` version in the        [huggingface_hub documentation](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.ModelHubMixin.push_to_hub).

**Parameters:**

repo_id (`str`) : The full repository ID to push to, e.g. `"tomaarsen/setfit-sst2"`.

config (`dict`, *optional*) : Configuration object to be saved alongside the model weights.

commit_message (`str`, *optional*) : Message to commit while pushing.

private (`bool`, *optional*) : Whether to make the repo private. If `None` (default), the repo will be public unless the organization's default is private. This value is ignored if the repo already exists.

api_endpoint (`str`, *optional*) : The API endpoint to use when pushing the model to the hub.

token (`str`, *optional*) : The token to use as HTTP bearer authorization for remote files. If not set, will use the token set when logging in with `transformers-cli login` (stored in `~/.huggingface`).

branch (`str`, *optional*) : The git branch on which to push the model. This defaults to the default branch as specified in your repository, which defaults to `"main"`.

create_pr (`boolean`, *optional*) : Whether or not to create a Pull Request from `branch` with that commit. Defaults to `False`.

allow_patterns (`List[str]` or `str`, *optional*) : If provided, only files matching at least one pattern are pushed.

ignore_patterns (`List[str]` or `str`, *optional*) : If provided, files matching any of the patterns are not pushed.

**Returns:**

`str`

The url of the commit of your model in the given repository.
#### remove_callback[[setfit.DistillationTrainer.remove_callback]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L394)

Remove a callback from the current list of [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback).

**Parameters:**

callback (`type` or [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)) : A [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback) class or an instance of a [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback). In the first case, will remove the first member of that class found in the list of callbacks.
#### train[[setfit.DistillationTrainer.train]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L492)

Main training entry point.

**Parameters:**

args (`TrainingArguments`, *optional*) : Temporarily change the training arguments for this training call.

trial (`optuna.Trial` or `Dict[str, Any]`, *optional*) : The trial run or the hyperparameter dictionary for hyperparameter search.
#### train_classifier[[setfit.DistillationTrainer.train_classifier]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer_distillation.py#L99)

Method to perform the classifier phase: fitting the student classifier head.

**Parameters:**

x_train (`List[str]`) : A list of training sentences.

args (`TrainingArguments`, *optional*) : Temporarily change the training arguments for this training call.
#### train_embeddings[[setfit.DistillationTrainer.train_embeddings]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/trainer.py#L537)

Method to perform the embedding phase: finetuning the `SentenceTransformer` body.

**Parameters:**

x_train (`List[str]`) : A list of training sentences.

y_train (`Union[List[int], List[List[int]]]`) : A list of labels corresponding to the training sentences.

args (`TrainingArguments`, *optional*) : Temporarily change the training arguments for this training call.

## AbsaTrainer[[setfit.AbsaTrainer]]

#### setfit.AbsaTrainer[[setfit.AbsaTrainer]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/span/trainer.py#L20)

Trainer to train a SetFit ABSA model.

add_callbacksetfit.AbsaTrainer.add_callbackhttps://github.com/huggingface/setfit/blob/main/src/setfit/span/trainer.py#L238[{"name": "callback", "val": ": typing.Union[type, transformers.trainer_callback.TrainerCallback]"}]- **callback** (`type` or [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)) --
  A [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback) class or an instance of a [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback). In the
  first case, will instantiate a member of that class.0

Add a callback to the current list of [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback).

**Parameters:**

model (`AbsaModel`) : The AbsaModel model to train.

args (`TrainingArguments`, *optional*) : The training arguments to use. If `polarity_args` is not defined, then `args` is used for both the aspect and the polarity model.

polarity_args (`TrainingArguments`, *optional*) : The training arguments to use for the polarity model. If not defined, `args` is used for both the aspect and the polarity model.

train_dataset (`Dataset`) : The training dataset. The dataset must have "text", "span", "label" and "ordinal" columns.

eval_dataset (`Dataset`, *optional*) : The evaluation dataset. The dataset must have "text", "span", "label" and "ordinal" columns.

metric (`str` or `Callable`, *optional*, defaults to `"accuracy"`) : The metric to use for evaluation. If a string is provided, we treat it as the metric name and load it with default settings. If a callable is provided, it must take two arguments (`y_pred`, `y_test`).

metric_kwargs (`Dict[str, Any]`, *optional*) : Keyword arguments passed to the evaluation function if `metric` is an evaluation string like "f1". For example useful for providing an averaging strategy for computing f1 in a multi-label setting.

callbacks (`List[`[TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)`]`, *optional*) : A list of callbacks to customize the training loop. Will add those to the list of default callbacks detailed in [here](https://huggingface.co/docs/transformers/main/en/main_classes/callback). If you want to remove one of the default callbacks used, use the [Trainer.remove_callback()](/docs/setfit/main/en/reference/trainer#setfit.Trainer.remove_callback) method.

column_mapping (`Dict[str, str]`, *optional*) : A mapping from the column names in the dataset to the column names expected by the model. The expected format is a dictionary with the following format: `{"text_column_name": "text", "span_column_name": "span", "label_column_name: "label", "ordinal_column_name": "ordinal"}`.
#### evaluate[[setfit.AbsaTrainer.evaluate]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/span/trainer.py#L316)

Computes the metrics for a given classifier.

**Parameters:**

dataset (`Dataset`, *optional*) : The dataset to compute the metrics on. If not provided, will use the evaluation dataset passed via the `eval_dataset` argument at `Trainer` initialization.

**Returns:**

``Dict[str, Dict[str, float]]``

The evaluation metrics.
#### pop_callback[[setfit.AbsaTrainer.pop_callback]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/span/trainer.py#L250)

Remove a callback from the current list of [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback) and returns it.

If the callback is not found, returns `None` (and no error is raised).

**Parameters:**

callback (`type` or [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)) : A [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback) class or an instance of a [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback). In the first case, will pop the first member of that class found in the list of callbacks.

**Returns:**

``Tuple[`[TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback), [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)`]``

The callbacks removed from the
aspect and polarity trainers, if found.
#### push_to_hub[[setfit.AbsaTrainer.push_to_hub]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/span/trainer.py#L279)

Upload model checkpoint to the Hub using `huggingface_hub`.

See the full list of parameters for your `huggingface_hub` version in the        [huggingface_hub documentation](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.ModelHubMixin.push_to_hub).

**Parameters:**

repo_id (`str`) : The full repository ID to push to, e.g. `"tomaarsen/setfit-aspect"`.

repo_id (`str`) : The full repository ID to push to, e.g. `"tomaarsen/setfit-sst2"`.

config (`dict`, *optional*) : Configuration object to be saved alongside the model weights.

commit_message (`str`, *optional*) : Message to commit while pushing.

private (`bool`, *optional*) : Whether to make the repo private. If `None` (default), the repo will be public unless the organization's default is private. This value is ignored if the repo already exists.

api_endpoint (`str`, *optional*) : The API endpoint to use when pushing the model to the hub.

token (`str`, *optional*) : The token to use as HTTP bearer authorization for remote files. If not set, will use the token set when logging in with `transformers-cli login` (stored in `~/.huggingface`).

branch (`str`, *optional*) : The git branch on which to push the model. This defaults to the default branch as specified in your repository, which defaults to `"main"`.

create_pr (`boolean`, *optional*) : Whether or not to create a Pull Request from `branch` with that commit. Defaults to `False`.

allow_patterns (`List[str]` or `str`, *optional*) : If provided, only files matching at least one pattern are pushed.

ignore_patterns (`List[str]` or `str`, *optional*) : If provided, files matching any of the patterns are not pushed.
#### remove_callback[[setfit.AbsaTrainer.remove_callback]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/span/trainer.py#L267)

Remove a callback from the current list of [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback).

**Parameters:**

callback (`type` or [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback)) : A [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback) class or an instance of a [TrainerCallback](https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback). In the first case, will remove the first member of that class found in the list of callbacks.
#### train[[setfit.AbsaTrainer.train]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/span/trainer.py#L183)

Main training entry point.

**Parameters:**

args (`TrainingArguments`, *optional*) : Temporarily change the aspect training arguments for this training call.

polarity_args (`TrainingArguments`, *optional*) : Temporarily change the polarity training arguments for this training call.

trial (`optuna.Trial` or `Dict[str, Any]`, *optional*) : The trial run or the hyperparameter dictionary for hyperparameter search.
#### train_aspect[[setfit.AbsaTrainer.train_aspect]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/span/trainer.py#L204)

Train the aspect model only.

**Parameters:**

args (`TrainingArguments`, *optional*) : Temporarily change the aspect training arguments for this training call.

trial (`optuna.Trial` or `Dict[str, Any]`, *optional*) : The trial run or the hyperparameter dictionary for hyperparameter search.
#### train_polarity[[setfit.AbsaTrainer.train_polarity]]

[Source](https://github.com/huggingface/setfit/blob/main/src/setfit/span/trainer.py#L221)

Train the polarity model only.

**Parameters:**

args (`TrainingArguments`, *optional*) : Temporarily change the aspect training arguments for this training call.

trial (`optuna.Trial` or `Dict[str, Any]`, *optional*) : The trial run or the hyperparameter dictionary for hyperparameter search.

