|
29 | 29 |
|
30 | 30 |
|
31 | 31 | class BertScorer(BaseScorer): |
| 32 | + """Scoring module for transformer-based classification using BERT models. |
| 33 | +
|
| 34 | + This module uses a transformer model (like BERT) to perform intent classification. |
| 35 | + It supports both multiclass and multilabel classification tasks, with options for |
| 36 | + early stopping and various training configurations. |
| 37 | +
|
| 38 | + Args: |
| 39 | + classification_model_config: Config of the transformer model (HFModelConfig, str, or dict) |
| 40 | + num_train_epochs: Number of training epochs (default: 3) |
| 41 | + batch_size: Batch size for training (default: 8) |
| 42 | + learning_rate: Learning rate for training (default: 5e-5) |
| 43 | + seed: Random seed for reproducibility (default: 0) |
| 44 | + report_to: Reporting tool for training logs (e.g., "wandb", "tensorboard") |
| 45 | + early_stopping_config: Configuration for early stopping during training |
| 46 | +
|
| 47 | + Example: |
| 48 | + -------- |
| 49 | + .. testcode:: |
| 50 | +
|
| 51 | + from autointent.modules import BertScorer |
| 52 | +
|
| 53 | + # Initialize scorer with BERT model |
| 54 | + scorer = BertScorer( |
| 55 | + classification_model_config="bert-base-uncased", |
| 56 | + num_train_epochs=3, |
| 57 | + batch_size=8, |
| 58 | + learning_rate=5e-5, |
| 59 | + seed=42 |
| 60 | + ) |
| 61 | +
|
| 62 | + # Training data |
| 63 | + utterances = ["This is great!", "I didn't like it", "Awesome product", "Poor quality"] |
| 64 | + labels = [1, 0, 1, 0] |
| 65 | +
|
| 66 | + # Fit the model |
| 67 | + scorer.fit(utterances, labels) |
| 68 | +
|
| 69 | + # Make predictions |
| 70 | + test_utterances = ["Good product", "Not worth it"] |
| 71 | + probabilities = scorer.predict(test_utterances) |
| 72 | + """ |
| 73 | + |
32 | 74 | name = "bert" |
33 | 75 | supports_multiclass = True |
34 | 76 | supports_multilabel = True |
|
0 commit comments