andreaceto commited on
Commit
3091eee
·
verified ·
1 Parent(s): 0fe3bdc

End of training

Browse files
README.md CHANGED
@@ -7,192 +7,104 @@ tags:
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: Selective 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.8636 | 0.8261 | 0.8444 | 23 |
166
- | cancel | 0.8902 | 0.8795 | 0.8848 | 83 |
167
- | greeting | 0.8636 | 0.8636 | 0.8636 | 22 |
168
- |negative_reply | 0.9048 | 0.8636 | 0.8837 | 22 |
169
- | oos | 0.9524 | 0.8696 | 0.9091 | 23 |
170
- |positive_reply | 0.7308 | 0.8636 | 0.7917 | 22 |
171
- | query_avail | 0.9268 | 0.9383 | 0.9325 | 81 |
172
- | reschedule | 0.8974 | 0.8434 | 0.8696 | 83 |
173
- | schedule | 0.8824 | 0.9375 | 0.9091 | 80 |
174
- | --- | --- | --- | --- | ---- |
175
- | **Accuracy** | | | **0.8884** | 439 |
176
- | **Macro Avg** | **0.8791** | **0.8761** | **0.8765** | 439 |
177
- | **Weighted Avg** | **0.8902** | **0.8884** | **0.8885** | 439 |
178
-
179
- ### NER (Token Classification) Performance
180
-
181
- | Entity | Precision | Recall | F1-Score | Support |
182
- | --- | --- | --- | --- | --- |
183
- | B-appointment_id | 0.9813 | 0.9705 | 0.9759 | 271 |
184
- | B-appointment_type | 0.8517 | 0.7943 | 0.8220 | 282 |
185
- | B-practitioner_name | 0.9540 | 0.9210 | 0.9372 | 405 |
186
- | O | 0.9782 | 0.9874 | 0.9828 | 3813 |
187
- | --- | --- | --- | --- | ---- |
188
- | **Accuracy** | | | 0.9694 | 4771 |
189
- | **Macro Avg** | 0.9413 | 0.9183 | 0.9295 | 4771 |
190
- | **Weighted Avg** | 0.9688 | 0.9694 | 0.9690 | 4771 |
191
-
192
- The model achieves near-perfect results on the NER task and excellent results on the intent classification task for this specific dataset.
193
-
194
- ## Limitations and Bias
195
-
196
- - 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.
197
- - The dataset was primarily generated from templates, which may not capture the full diversity of real human language.
198
- - The model inherits any biases present in the `distilbert-base-uncased` model and the `clinc/clinc_oos` dataset.
 
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
+ # schedulebot-nlu-engine
16
+
17
+ This model is a fine-tuned version of [distilbert-base-uncased](https://huggingface.co/distilbert-base-uncased) on an unknown dataset.
18
+ It achieves the following results on the evaluation set:
19
+ - Loss: 0.3194
20
+ - Intent Accuracy: 0.9224
21
+ - Intent F1: 0.9216
22
+ - Ner F1: 0.9320
23
+
24
+ ## Model description
25
+
26
+ More information needed
27
+
28
+ ## Intended uses & limitations
29
+
30
+ More information needed
31
+
32
+ ## Training and evaluation data
33
+
34
+ More information needed
35
+
36
+ ## Training procedure
37
+
38
+ ### Training hyperparameters
39
+
40
+ The following hyperparameters were used during training:
41
+ - learning_rate: 1e-06
42
+ - train_batch_size: 32
43
+ - eval_batch_size: 32
44
+ - seed: 42
45
+ - optimizer: Use OptimizerNames.ADAMW_TORCH with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
46
+ - lr_scheduler_type: linear
47
+ - num_epochs: 50
48
+
49
+ ### Training results
50
+
51
+ | Training Loss | Epoch | Step | Validation Loss | Intent Accuracy | Intent F1 | Ner F1 |
52
+ |:-------------:|:-----:|:----:|:---------------:|:---------------:|:---------:|:------:|
53
+ | No log | 1.0 | 64 | 0.6763 | 0.8196 | 0.8178 | 0.9239 |
54
+ | No log | 2.0 | 128 | 0.6300 | 0.8470 | 0.8460 | 0.9227 |
55
+ | No log | 3.0 | 192 | 0.6008 | 0.8356 | 0.8347 | 0.9239 |
56
+ | No log | 4.0 | 256 | 0.5762 | 0.8539 | 0.8541 | 0.9240 |
57
+ | No log | 5.0 | 320 | 0.5599 | 0.8470 | 0.8468 | 0.9246 |
58
+ | No log | 6.0 | 384 | 0.5391 | 0.8493 | 0.8483 | 0.9263 |
59
+ | No log | 7.0 | 448 | 0.5222 | 0.8676 | 0.8670 | 0.9256 |
60
+ | 0.8885 | 8.0 | 512 | 0.5053 | 0.8607 | 0.8603 | 0.9269 |
61
+ | 0.8885 | 9.0 | 576 | 0.4875 | 0.8607 | 0.8597 | 0.9279 |
62
+ | 0.8885 | 10.0 | 640 | 0.4723 | 0.8721 | 0.8708 | 0.9274 |
63
+ | 0.8885 | 11.0 | 704 | 0.4599 | 0.8858 | 0.8854 | 0.9297 |
64
+ | 0.8885 | 12.0 | 768 | 0.4536 | 0.8973 | 0.8966 | 0.9291 |
65
+ | 0.8885 | 13.0 | 832 | 0.4432 | 0.8790 | 0.8783 | 0.9279 |
66
+ | 0.8885 | 14.0 | 896 | 0.4334 | 0.8881 | 0.8873 | 0.9290 |
67
+ | 0.8885 | 15.0 | 960 | 0.4268 | 0.8813 | 0.8806 | 0.9295 |
68
+ | 0.6688 | 16.0 | 1024 | 0.4180 | 0.8881 | 0.8872 | 0.9295 |
69
+ | 0.6688 | 17.0 | 1088 | 0.4119 | 0.8995 | 0.8991 | 0.9296 |
70
+ | 0.6688 | 18.0 | 1152 | 0.4061 | 0.8973 | 0.8964 | 0.9290 |
71
+ | 0.6688 | 19.0 | 1216 | 0.3949 | 0.8950 | 0.8940 | 0.9285 |
72
+ | 0.6688 | 20.0 | 1280 | 0.3899 | 0.9018 | 0.9012 | 0.9296 |
73
+ | 0.6688 | 21.0 | 1344 | 0.3855 | 0.9087 | 0.9083 | 0.9302 |
74
+ | 0.6688 | 22.0 | 1408 | 0.3768 | 0.8950 | 0.8942 | 0.9296 |
75
+ | 0.6688 | 23.0 | 1472 | 0.3756 | 0.8950 | 0.8948 | 0.9308 |
76
+ | 0.5511 | 24.0 | 1536 | 0.3693 | 0.9110 | 0.9100 | 0.9308 |
77
+ | 0.5511 | 25.0 | 1600 | 0.3658 | 0.9064 | 0.9057 | 0.9308 |
78
+ | 0.5511 | 26.0 | 1664 | 0.3598 | 0.9110 | 0.9101 | 0.9320 |
79
+ | 0.5511 | 27.0 | 1728 | 0.3647 | 0.9041 | 0.9035 | 0.9309 |
80
+ | 0.5511 | 28.0 | 1792 | 0.3500 | 0.9201 | 0.9190 | 0.9314 |
81
+ | 0.5511 | 29.0 | 1856 | 0.3466 | 0.9155 | 0.9145 | 0.9314 |
82
+ | 0.5511 | 30.0 | 1920 | 0.3481 | 0.9155 | 0.9149 | 0.9314 |
83
+ | 0.5511 | 31.0 | 1984 | 0.3431 | 0.9155 | 0.9150 | 0.9314 |
84
+ | 0.4859 | 32.0 | 2048 | 0.3409 | 0.9110 | 0.9104 | 0.9314 |
85
+ | 0.4859 | 33.0 | 2112 | 0.3404 | 0.9201 | 0.9195 | 0.9308 |
86
+ | 0.4859 | 34.0 | 2176 | 0.3346 | 0.9132 | 0.9127 | 0.9309 |
87
+ | 0.4859 | 35.0 | 2240 | 0.3324 | 0.9201 | 0.9192 | 0.9309 |
88
+ | 0.4859 | 36.0 | 2304 | 0.3306 | 0.9178 | 0.9170 | 0.9309 |
89
+ | 0.4859 | 37.0 | 2368 | 0.3309 | 0.9178 | 0.9173 | 0.9314 |
90
+ | 0.4859 | 38.0 | 2432 | 0.3289 | 0.9178 | 0.9173 | 0.9314 |
91
+ | 0.4859 | 39.0 | 2496 | 0.3272 | 0.9201 | 0.9195 | 0.9314 |
92
+ | 0.4434 | 40.0 | 2560 | 0.3259 | 0.9178 | 0.9173 | 0.9314 |
93
+ | 0.4434 | 41.0 | 2624 | 0.3240 | 0.9201 | 0.9193 | 0.9314 |
94
+ | 0.4434 | 42.0 | 2688 | 0.3228 | 0.9224 | 0.9216 | 0.9326 |
95
+ | 0.4434 | 43.0 | 2752 | 0.3243 | 0.9178 | 0.9173 | 0.9320 |
96
+ | 0.4434 | 44.0 | 2816 | 0.3248 | 0.9201 | 0.9195 | 0.9314 |
97
+ | 0.4434 | 45.0 | 2880 | 0.3218 | 0.9224 | 0.9216 | 0.9320 |
98
+ | 0.4434 | 46.0 | 2944 | 0.3213 | 0.9224 | 0.9216 | 0.9320 |
99
+ | 0.4221 | 47.0 | 3008 | 0.3205 | 0.9224 | 0.9216 | 0.9320 |
100
+ | 0.4221 | 48.0 | 3072 | 0.3195 | 0.9224 | 0.9216 | 0.9320 |
101
+ | 0.4221 | 49.0 | 3136 | 0.3196 | 0.9224 | 0.9216 | 0.9320 |
102
+ | 0.4221 | 50.0 | 3200 | 0.3194 | 0.9224 | 0.9216 | 0.9320 |
103
+
104
+
105
+ ### Framework versions
106
+
107
+ - Transformers 4.53.2
108
+ - Pytorch 2.6.0+cu124
109
+ - Datasets 4.0.0
110
+ - Tokenizers 0.21.2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config.json CHANGED
@@ -7,11 +7,53 @@
7
  "dim": 768,
8
  "dropout": 0.1,
9
  "hidden_dim": 3072,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  "initializer_range": 0.02,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  "max_position_embeddings": 512,
12
  "model_type": "distilbert",
13
  "n_heads": 12,
14
  "n_layers": 6,
 
 
15
  "pad_token_id": 0,
16
  "qa_dropout": 0.1,
17
  "seq_classif_dropout": 0.2,
 
7
  "dim": 768,
8
  "dropout": 0.1,
9
  "hidden_dim": 3072,
10
+ "id2label": [
11
+ "bye",
12
+ "cancel",
13
+ "greeting",
14
+ "negative_reply",
15
+ "oos",
16
+ "positive_reply",
17
+ "query_avail",
18
+ "reschedule",
19
+ "schedule"
20
+ ],
21
+ "id2label_ner": [
22
+ "O",
23
+ "B-appointment_id",
24
+ "I-appointment_id",
25
+ "B-appointment_type",
26
+ "I-appointment_type",
27
+ "B-practitioner_name",
28
+ "I-practitioner_name"
29
+ ],
30
  "initializer_range": 0.02,
31
+ "label2id": {
32
+ "bye": 0,
33
+ "cancel": 1,
34
+ "greeting": 2,
35
+ "negative_reply": 3,
36
+ "oos": 4,
37
+ "positive_reply": 5,
38
+ "query_avail": 6,
39
+ "reschedule": 7,
40
+ "schedule": 8
41
+ },
42
+ "label2id_ner": {
43
+ "B-appointment_id": 1,
44
+ "B-appointment_type": 3,
45
+ "B-practitioner_name": 5,
46
+ "I-appointment_id": 2,
47
+ "I-appointment_type": 4,
48
+ "I-practitioner_name": 6,
49
+ "O": 0
50
+ },
51
  "max_position_embeddings": 512,
52
  "model_type": "distilbert",
53
  "n_heads": 12,
54
  "n_layers": 6,
55
+ "num_intent_labels": 9,
56
+ "num_ner_labels": 7,
57
  "pad_token_id": 0,
58
  "qa_dropout": 0.1,
59
  "seq_classif_dropout": 0.2,
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:771362ffd2649dfac75137c8fb23415627356fd9ed2deab53c4b2d41215db76e
3
  size 267851552
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2ae2a3c417ae03007fca71c860470d2c13b8543d3a7aea9c9e8c646b4cc9fcd5
3
  size 267851552
runs/Jul17_14-34-55_e305321a40a7/events.out.tfevents.1752762895.e305321a40a7.745.1 ADDED
Binary file (29 kB). View file
 
training_args.bin CHANGED
Binary files a/training_args.bin and b/training_args.bin differ