lindsey-chang
commited on
Commit
•
0e71eb1
1
Parent(s):
6e697dc
add readme
Browse files
README.md
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# Vehicle User Instructions Classification - BERT (Chinese)
|
3 |
+
|
4 |
+
This repository contains a fine-tuned BERT model for classifying vehicle user instructions in Chinese. The model is trained on a dataset of user instructions related to various vehicle control commands.
|
5 |
+
## Preface
|
6 |
+
This fine-tuned model is for Our team's UOW CSIT998 Professional Capstone Project.
|
7 |
+
## Dataset
|
8 |
+
|
9 |
+
The dataset used for training and evaluation consists of Chinese text instructions corresponding to different vehicle control commands. The distribution of the dataset is as follows:
|
10 |
+
|
11 |
+
- Training set: 4499 samples
|
12 |
+
- Validation set: 2249 samples
|
13 |
+
- Test set: 2250 samples
|
14 |
+
|
15 |
+
The instructions cover a range of vehicle control commands, including:
|
16 |
+
|
17 |
+
```
|
18 |
+
{'开车窗': 0, '关左车门': 1, '关右前车窗': 2, '关闭引擎': 3, '关左前车窗': 4, '开右前车窗': 5, '关左后车窗': 6, '开左后车窗': 7, '开后备箱': 8, '关车门': 9, '关车窗': 10, '开左前车窗': 11, '关右后车窗': 12, '开敞篷': 13, '开左侧车窗': 14, '关敞篷': 15, '喇叭': 16, '开右后车窗': 17, '开右车门': 18, '停车点1': 19, '关后备箱': 20, '关右车门': 21, '开左车门': 22, '停车点2': 23, '开车门': 24, '打开引擎': 25, '关左侧车窗': 26}
|
19 |
+
```
|
20 |
+
|
21 |
+
## Model
|
22 |
+
|
23 |
+
The model is based on the pre-trained Chinese BERT model (`bert-base-chinese`). It has been fine-tuned on the vehicle user instructions dataset using the following training arguments:
|
24 |
+
|
25 |
+
```python
|
26 |
+
training_args = TrainingArguments(
|
27 |
+
output_dir='',
|
28 |
+
do_train=True,
|
29 |
+
do_eval=True,
|
30 |
+
num_train_epochs=3,
|
31 |
+
per_device_train_batch_size=16,
|
32 |
+
per_device_eval_batch_size=32,
|
33 |
+
warmup_steps=100,
|
34 |
+
weight_decay=0.01,
|
35 |
+
logging_strategy='steps',
|
36 |
+
logging_dir='',
|
37 |
+
logging_steps=50,
|
38 |
+
evaluation_strategy="steps",
|
39 |
+
eval_steps=50,
|
40 |
+
save_strategy="steps",
|
41 |
+
save_steps=200,
|
42 |
+
fp16=True,
|
43 |
+
load_best_model_at_end=True
|
44 |
+
)
|
45 |
+
```
|
46 |
+
|
47 |
+
## Training Results
|
48 |
+
|
49 |
+
The model was trained for 3 epochs, and the training progress can be summarized as follows:
|
50 |
+
|
51 |
+
| Step | Training Loss | Validation Loss | Accuracy | F1 | Precision | Recall |
|
52 |
+
|------|---------------|-----------------|----------|--------|-----------|---------|
|
53 |
+
| 50 | 3.257000 | 2.964479 | 0.168519 | 0.089801 | 0.229036 | 0.126555 |
|
54 |
+
| 100 | 2.525000 | 1.711695 | 0.648288 | 0.532127 | 0.595545 | 0.590985 |
|
55 |
+
| 150 | 1.197200 | 0.628560 | 0.921298 | 0.888212 | 0.892879 | 0.890719 |
|
56 |
+
| ... | ... | ... | ... | ... | ... | ... |
|
57 |
+
| 8000 | 0.045900 | 0.136842 | 0.969320 | 0.969658 | 0.969638 | 0.970056 |
|
58 |
+
|
59 |
+
## Evaluation
|
60 |
+
|
61 |
+
The trained model was evaluated on the training, validation, and test sets, achieving the following performance:
|
62 |
+
|
63 |
+
| | eval_loss | eval_Accuracy | eval_F1 | eval_Precision | eval_Recall |
|
64 |
+
|-------|-----------|---------------|----------|----------------|-------------|
|
65 |
+
| train | 0.036020 | 0.991331 | 0.991048 | 0.991615 | 0.990673 |
|
66 |
+
| val | 0.136842 | 0.969320 | 0.969658 | 0.969638 | 0.970056 |
|
67 |
+
| test | 0.126695 | 0.974222 | 0.975473 | 0.975814 | 0.975435 |
|
68 |
+
|
69 |
+
The model achieves high accuracy, F1 score, precision, and recall on all three datasets, indicating its effectiveness in classifying vehicle user instructions.
|
70 |
+
|
71 |
+
## Usage
|
72 |
+
|
73 |
+
To use the fine-tuned model for inference, you can utilize the Hugging Face Inference API. Here's an example of how to make a request to the API using Python:
|
74 |
+
|
75 |
+
```python
|
76 |
+
import requests
|
77 |
+
|
78 |
+
API_URL = "https://api-inference.huggingface.co/models/lindsey-chang/vehicle-user-instructions-classification-bert-chinese"
|
79 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
80 |
+
|
81 |
+
def query(payload):
|
82 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
83 |
+
return response.json()
|
84 |
+
|
85 |
+
# Example usage
|
86 |
+
input_text = "请打开车窗"
|
87 |
+
output = query({"inputs": input_text})
|
88 |
+
print(output)
|
89 |
+
```
|
90 |
+
|
91 |
+
Replace `your-username` with your Hugging Face username and `API_TOKEN` with your personal API token, which you can create in your Hugging Face account settings.
|
92 |
+
|
93 |
+
The model will return the predicted class index for the input instruction. You can map the class index back to the corresponding vehicle control command using the provided class labels.
|
94 |
+
|