autointent.modules.PTuningScorer#

class autointent.modules.PTuningScorer(classification_model_config=None, num_train_epochs=3, batch_size=8, learning_rate=5e-05, seed=0, report_to='none', encoder_reparameterization_type='LSTM', num_virtual_tokens=10, encoder_dropout=0.1, encoder_hidden_size=128, encoder_num_layers=2, early_stopping_config=None, print_progress=False, **ptuning_kwargs)#

Bases: autointent.modules.scoring._bert.BertScorer

PEFT P-tuning scorer.

Parameters:
  • classification_model_config (autointent.configs.HFModelConfig | str | dict[str, Any] | None) – Config of the base transformer model (HFModelConfig, str, or dict)

  • num_train_epochs (pydantic.PositiveInt) – Number of training epochs

  • batch_size (pydantic.PositiveInt) – Batch size for training

  • learning_rate (float) – Learning rate for training

  • seed (int) – Random seed for reproducibility

  • report_to (autointent._callbacks.REPORTERS_NAMES | Literal['none']) – Reporting tool for training logs

  • **ptuning_kwargs (Any) – Arguments for PromptEncoderConfig

  • encoder_reparameterization_type (Literal['MLP', 'LSTM'])

  • num_virtual_tokens (pydantic.PositiveInt)

  • encoder_dropout (float)

  • encoder_hidden_size (pydantic.PositiveInt)

  • encoder_num_layers (pydantic.PositiveInt)

  • early_stopping_config (autointent.configs.EarlyStoppingConfig | None)

  • print_progress (bool)

  • **ptuning_kwargs

Example:#

from autointent.modules import PTuningScorer
scorer = PTuningScorer(
    classification_model_config="prajjwal1/bert-tiny",
    num_train_epochs=3,
    batch_size=8,
    num_virtual_tokens=10,
    seed=42
)
utterances = ["hello", "goodbye", "allo", "sayonara"]
labels = [0, 1, 0, 1]
scorer.fit(utterances, labels)
test_utterances = ["hi", "bye"]
probabilities = scorer.predict(test_utterances)
name = 'ptuning'#

Name of the module to reference in search space configuration.

classmethod from_context(context, classification_model_config=None, num_train_epochs=3, batch_size=8, learning_rate=5e-05, seed=0, encoder_reparameterization_type='LSTM', num_virtual_tokens=10, encoder_dropout=0.1, encoder_hidden_size=128, encoder_num_layers=2, **ptuning_kwargs)#

Create a PTuningScorer instance using a Context object.

Parameters:
  • context (autointent.Context) – Context containing configurations and utilities

  • classification_model_config (autointent.configs.HFModelConfig | str | dict[str, Any] | None) – Config of the base model, or None to use the best embedder

  • num_train_epochs (pydantic.PositiveInt) – Number of training epochs

  • batch_size (pydantic.PositiveInt) – Batch size for training

  • learning_rate (float) – Learning rate for training

  • seed (int) – Random seed for reproducibility

  • encoder_reparameterization_type (Literal['MLP', 'LSTM']) – Reparametrization type for the prompt encoder

  • num_virtual_tokens (pydantic.PositiveInt) – Number of virtual tokens for the prompt encoder

  • encoder_dropout (float) – Dropout for the prompt encoder

  • encoder_hidden_size (pydantic.PositiveInt) – Hidden size for the prompt encoder

  • encoder_num_layers (pydantic.PositiveInt) – Number of layers for the prompt encoder

  • **ptuning_kwargs (Any) – Arguments for PromptEncoderConfig

Return type:

PTuningScorer

dump(path)#

Dump all data needed for inference.

Parameters:

path (str) – Path to dump

Return type:

None