Update README.md
Browse files
README.md
CHANGED
|
@@ -7,104 +7,195 @@ tags:
|
|
| 7 |
model-index:
|
| 8 |
- name: schedulebot-nlu-engine
|
| 9 |
results: []
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
-
|
| 12 |
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
| 13 |
should probably proofread and complete it, then remove this comment. -->
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
-
|
| 20 |
-
|
| 21 |
-
- Intent
|
| 22 |
-
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
model-index:
|
| 8 |
- name: schedulebot-nlu-engine
|
| 9 |
results: []
|
| 10 |
+
datasets:
|
| 11 |
+
- andreaceto/hasd
|
| 12 |
+
language:
|
| 13 |
+
- en
|
| 14 |
---
|
|
|
|
| 15 |
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
| 16 |
should probably proofread and complete it, then remove this comment. -->
|
| 17 |
|
| 18 |
+
# Schedulebot-nlu-engine
|
| 19 |
+
|
| 20 |
+
## Model Description
|
| 21 |
+
|
| 22 |
+
This model is a multi-task Natural Language Understanding (NLU) engine designed specifically for an appointment scheduling chatbot. It is fine-tuned from a **`distilbert-base-uncased`** backbone and is capable of performing two tasks simultaneously:
|
| 23 |
+
|
| 24 |
+
- **Intent Classification**: Identifying the user's primary goal (e.g., `schedule`, `cancel`).
|
| 25 |
+
- **Named Entity Recognition (NER)**: Extracting custom, domain-specific entities (e.g., `appointment_type`).
|
| 26 |
+
|
| 27 |
+
This model stands out due to its custom classification heads, which use a more complex architecture to improve performance on nuanced tasks.
|
| 28 |
+
|
| 29 |
+
## Model Architecture
|
| 30 |
+
|
| 31 |
+
The model uses a standard `distilbert-base-uncased` model as its core feature extractor. Two custom classification "heads" are placed on top of this base to perform the downstream tasks.
|
| 32 |
+
|
| 33 |
+
- **Base Model**: `distilbert-base-uncased`
|
| 34 |
+
- **Classifier Heads**: each head is a Multi-Layer Perceptron (MLP) with the following structure to allow for more complex feature interpretation:
|
| 35 |
+
1. A Linear layer projecting the transformer's output dimension (768) to an intermediate size (384).
|
| 36 |
+
2. A GELU activation function.
|
| 37 |
+
3. A Dropout layer with a rate of 0.3 for regularization.
|
| 38 |
+
4. A final Linear layer projecting the intermediate size to the number of output labels for the specific task (intent or NER).
|
| 39 |
+
|
| 40 |
+
## Intended Use
|
| 41 |
+
|
| 42 |
+
This model is intended to be the core NLU component of a conversational AI system for managing appointments.
|
| 43 |
+
|
| 44 |
+
For instructions on how to use the model check the [dedicated file](./how_to_use.md).
|
| 45 |
+
|
| 46 |
+
## Training Data
|
| 47 |
+
|
| 48 |
+
The model was trained on the **HASD (Hybrid Appointment Scheduling Dataset)**, a custom dataset built specifically for this task.
|
| 49 |
+
|
| 50 |
+
- **Source**: The dataset is a hybrid of real-world conversational examples from `clinc/clinc_oos` (for simple intents) and synthetically generated, template-based examples for complex scheduling intents.
|
| 51 |
+
- **Balancing**: To combat class imbalance, intents sourced from `clinc/clinc_oos` were **down-sampled** to a maximum of **150 examples** each.
|
| 52 |
+
- **Augmentation**: To increase data diversity for complex intents (`schedule`, `reschedule`, etc.), **Contextual Word Replacement** was used. A `distilbert-base-uncased` model augmented the templates by replacing non-placeholder words with contextually relevant synonyms.
|
| 53 |
+
|
| 54 |
+
The dataset is available [here](https://huggingface.co/datasets/andreaceto/hasd).
|
| 55 |
+
|
| 56 |
+
### Intents
|
| 57 |
+
|
| 58 |
+
The model is trained to recognize the following intents:
|
| 59 |
+
`schedule`, `reschedule`, `cancel`, `query_avail`, `greeting`, `positive_reply`, `negative_reply`, `bye`, `oos` (out-of-scope).
|
| 60 |
+
|
| 61 |
+
### Entities
|
| 62 |
+
|
| 63 |
+
The model is trained to recognize the following custom named entities:
|
| 64 |
+
`practitioner_name`, `appointment_type`, `appointment_id`.
|
| 65 |
+
|
| 66 |
+
## Training Procedure
|
| 67 |
+
|
| 68 |
+
The model was trained using a two-stage fine-tuning strategy to ensure stability and performance.
|
| 69 |
+
|
| 70 |
+
### Stage 1: Training the Classifier Heads
|
| 71 |
+
|
| 72 |
+
- The `distilbert-base-uncased` base model was entirely **frozen**.
|
| 73 |
+
- Only the randomly initialized MLP heads for intent and NER classification were trained.
|
| 74 |
+
|
| 75 |
+
**Setup**:
|
| 76 |
+
|
| 77 |
+
```python
|
| 78 |
+
# Define a data collator to handle padding for token classification
|
| 79 |
+
data_collator = DataCollatorForTokenClassification(tokenizer=tokenizer)
|
| 80 |
+
# Define Training Arguments
|
| 81 |
+
training_args = TrainingArguments(
|
| 82 |
+
output_dir="path/to/output_dir",
|
| 83 |
+
overwrite_output_dir=True,
|
| 84 |
+
num_train_epochs=200, # Training epochs
|
| 85 |
+
per_device_train_batch_size=32,
|
| 86 |
+
per_device_eval_batch_size=32,
|
| 87 |
+
learning_rate=1e-4, # Learning Rate
|
| 88 |
+
weight_decay=1e-5, # AdamW weight decay
|
| 89 |
+
logging_dir="path/to/logging_dir",
|
| 90 |
+
logging_strategy="epoch",
|
| 91 |
+
eval_strategy="epoch",
|
| 92 |
+
save_strategy="epoch",
|
| 93 |
+
load_best_model_at_end=True,
|
| 94 |
+
metric_for_best_model="eval_loss", # Focus on validation loss as the key metric
|
| 95 |
+
# --- Hub Arguments ---
|
| 96 |
+
push_to_hub=True,
|
| 97 |
+
hub_model_id=hub_model_id,
|
| 98 |
+
hub_strategy="end",
|
| 99 |
+
hub_token=hf_token,
|
| 100 |
+
report_to="tensorboard" # Tensorboard to monitor training
|
| 101 |
+
)
|
| 102 |
+
# Create the Trainer
|
| 103 |
+
trainer = Trainer(
|
| 104 |
+
model=model,
|
| 105 |
+
args=training_args,
|
| 106 |
+
train_dataset=processed_datasets["train"],
|
| 107 |
+
eval_dataset=processed_datasets["validation"],
|
| 108 |
+
processing_class=tokenizer,
|
| 109 |
+
data_collator=data_collator,
|
| 110 |
+
compute_metrics=compute_metrics, # Custom function (check how_to_use.md)
|
| 111 |
+
callbacks=[EarlyStoppingCallback(early_stopping_patience=10)]
|
| 112 |
+
)
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
### Stage 2: Fine-Tuning
|
| 116 |
+
|
| 117 |
+
- The DistilBERT backbone was entirely **unfrozen**.
|
| 118 |
+
- Using a very low LR allows the model to adapt even better to the new data while preserving the powerful, general-purpose knowledge.
|
| 119 |
+
|
| 120 |
+
**Setup**:
|
| 121 |
+
|
| 122 |
+
```python
|
| 123 |
+
# Define Training Arguments
|
| 124 |
+
training_args = TrainingArguments(
|
| 125 |
+
output_dir="path/to/output_dir",
|
| 126 |
+
overwrite_output_dir=True,
|
| 127 |
+
num_train_epochs=50, # Fine-tuning epochs
|
| 128 |
+
per_device_train_batch_size=32,
|
| 129 |
+
per_device_eval_batch_size=32,
|
| 130 |
+
learning_rate=1e-6, # Learning Rate
|
| 131 |
+
weight_decay=1e-3, # AdamW weight decay
|
| 132 |
+
logging_dir="path/to/logging_dir",
|
| 133 |
+
logging_strategy="epoch",
|
| 134 |
+
eval_strategy="epoch",
|
| 135 |
+
save_strategy="epoch",
|
| 136 |
+
load_best_model_at_end=True,
|
| 137 |
+
metric_for_best_model="eval_loss", # Focus on NER F1 as the key metric
|
| 138 |
+
# --- Hub Arguments ---
|
| 139 |
+
push_to_hub=True,
|
| 140 |
+
hub_model_id=hub_model_id,
|
| 141 |
+
hub_strategy="end",
|
| 142 |
+
hub_token=hf_token,
|
| 143 |
+
report_to="tensorboard" # Tensorboard to monitor training
|
| 144 |
+
)
|
| 145 |
+
# Create the Trainer
|
| 146 |
+
trainer = Trainer(
|
| 147 |
+
model=model,
|
| 148 |
+
args=training_args,
|
| 149 |
+
train_dataset=processed_datasets["train"],
|
| 150 |
+
eval_dataset=processed_datasets["validation"],
|
| 151 |
+
processing_class=tokenizer,
|
| 152 |
+
data_collator=data_collator,
|
| 153 |
+
compute_metrics=compute_metrics, # Custom function (check how_to_use.md)
|
| 154 |
+
callbacks=[EarlyStoppingCallback(early_stopping_patience=5)]
|
| 155 |
+
)
|
| 156 |
+
```
|
| 157 |
+
## Evaluation
|
| 158 |
+
|
| 159 |
+
The model was evaluated on a held-out test set, and its performance was measured for both tasks.
|
| 160 |
+
|
| 161 |
+
### Intent Classification Performance
|
| 162 |
+
|
| 163 |
+
| Intent | Precision | Recall | F1-Score | Support |
|
| 164 |
+
| --- | --- | --- | --- | --- |
|
| 165 |
+
| bye | 0.9500 | 0.8261 | 0.8837 | 23 |
|
| 166 |
+
| cancel | 0.9211 | 0.8434 | 0.8805 | 83 |
|
| 167 |
+
| greeting | 0.9545 | 0.9545 | 0.9545 | 22 |
|
| 168 |
+
|negative_reply | 0.9091 | 0.9091 | 0.9091 | 22 |
|
| 169 |
+
| oos | 1.0000 | 0.8696 | 0.9302 | 23 |
|
| 170 |
+
|positive_reply | 0.7407 | 0.9091 | 0.8163 | 22 |
|
| 171 |
+
| query_avail | 0.9620 | 0.9383 | 0.9500 | 81 |
|
| 172 |
+
| reschedule | 0.8506 | 0.8916 | 0.8706 | 83 |
|
| 173 |
+
| schedule | 0.8488 | 0.9125 | 0.8795 | 80 |
|
| 174 |
+
| --- | --- | --- | --- | ---- |
|
| 175 |
+
| **Accuracy** | | | **0.8952** | 439 |
|
| 176 |
+
| **Macro Avg** | **0.9041** | **0.8949** | **0.8972** | 439 |
|
| 177 |
+
| **Weighted Avg** | **0.8998** | **0.8952** | **0.8960** | 439 |
|
| 178 |
+
|
| 179 |
+
### NER (Token Classification) Performance
|
| 180 |
+
|
| 181 |
+
| Entity | Precision | Recall | F1-Score | Support |
|
| 182 |
+
| --- | --- | --- | --- | --- |
|
| 183 |
+
| B-appointment_id | 1.0000 | 1.0000 | 1.0000 | 61 |
|
| 184 |
+
| B-appointment_type | 0.8646 | 0.7477 | 0.8019 | 111 |
|
| 185 |
+
| B-practitioner_name | 0.9161 | 0.9467 | 0.9311 | 150 |
|
| 186 |
+
| B-appointment_id | 0.9667 | 0.9667 | 0.9667 | 210 |
|
| 187 |
+
| I-appointment_type | 0.8182 | 0.7368 | 0.7754 | 171 |
|
| 188 |
+
| I-practitioner_name | 0.9540 | 0.8941 | 0.9231 | 255 |
|
| 189 |
+
| O | 0.9782 | 0.9892 | 0.9837 | 3813 |
|
| 190 |
+
| --- | --- | --- | --- | ---- |
|
| 191 |
+
| **Accuracy** | | | 0.9673 | 4771 |
|
| 192 |
+
| **Macro Avg** | 0.9283 | 0.8973 | 0.9117 | 4771 |
|
| 193 |
+
| **Weighted Avg** | 0.9664 | 0.9673 | 0.9666 | 4771 |
|
| 194 |
+
|
| 195 |
+
The model achieves near-perfect results on the NER task and excellent results on the intent classification task for this specific dataset.
|
| 196 |
+
|
| 197 |
+
## Limitations and Bias
|
| 198 |
+
|
| 199 |
+
- The model's performance is highly dependent on the quality and scope of the **HASD dataset**. It may not generalize well to phrasing or appointment types significantly different from what it was trained on.
|
| 200 |
+
- The dataset was primarily generated from templates, which may not capture the full diversity of real human language.
|
| 201 |
+
- The model inherits any biases present in the `distilbert-base-uncased` model and the `clinc/clinc_oos` dataset.
|