Improve language tag (#1)
Browse files- Improve language tag (c0190e04ac085313d7e8840542ac21024cf79e74)
Co-authored-by: Loïck BOURDOIS <[email protected]>
README.md
CHANGED
@@ -1,86 +1,98 @@
|
|
1 |
-
---
|
2 |
-
datasets:
|
3 |
-
- id4thomas/emotion-prediction-comet-atomic-2020
|
4 |
-
language:
|
5 |
-
-
|
6 |
-
|
7 |
-
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
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 |
```
|
|
|
1 |
+
---
|
2 |
+
datasets:
|
3 |
+
- id4thomas/emotion-prediction-comet-atomic-2020
|
4 |
+
language:
|
5 |
+
- zho
|
6 |
+
- eng
|
7 |
+
- fra
|
8 |
+
- spa
|
9 |
+
- por
|
10 |
+
- deu
|
11 |
+
- ita
|
12 |
+
- rus
|
13 |
+
- jpn
|
14 |
+
- kor
|
15 |
+
- vie
|
16 |
+
- tha
|
17 |
+
- ara
|
18 |
+
base_model:
|
19 |
+
- Qwen/Qwen2.5-3B-Instruct
|
20 |
+
---
|
21 |
+
# emotion-predictor-Qwen2.5-3B-Instruct
|
22 |
+
LLM trained to predict a character's emotional response in the given situation
|
23 |
+
* Trained to predict in a structured output format.
|
24 |
+
|
25 |
+
Prediction Performance:
|
26 |
+
| Setting | Performance by Emotion|
|
27 |
+
| --- | --- |
|
28 |
+
| Pretrained | <img src="./assets/qwen2_5-3b-baseline_perf.png" alt="baseline_perf" width="100%" /> |
|
29 |
+
| Tuned | <img src="./assets/finetuned_perf.png" alt="trained_perf" width="100%" /> |
|
30 |
+
|
31 |
+
|
32 |
+
## Quickstart
|
33 |
+
The model is trained to predict in the following schema
|
34 |
+
```
|
35 |
+
from enum import Enum
|
36 |
+
from pydantic import BaseModel
|
37 |
+
|
38 |
+
class RelationshipStatus(str, Enum):
|
39 |
+
na = "na"
|
40 |
+
low = "low"
|
41 |
+
medium = "medium"
|
42 |
+
high = "high"
|
43 |
+
|
44 |
+
class EmotionLabel(BaseModel):
|
45 |
+
joy: RelationshipStatus
|
46 |
+
trust: RelationshipStatus
|
47 |
+
fear: RelationshipStatus
|
48 |
+
surprise: RelationshipStatus
|
49 |
+
sadness: RelationshipStatus
|
50 |
+
disgust: RelationshipStatus
|
51 |
+
anger: RelationshipStatus
|
52 |
+
anticipation: RelationshipStatus
|
53 |
+
|
54 |
+
class EntryResult(BaseModel):
|
55 |
+
emotion: EmotionLabel
|
56 |
+
reason: str
|
57 |
+
```
|
58 |
+
|
59 |
+
Using `outlines` package to generate structured predictions
|
60 |
+
* system prompt & user template is provided [here](./assets/inference_prompt.yaml)
|
61 |
+
```
|
62 |
+
import outlines
|
63 |
+
from outlines import models
|
64 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
65 |
+
|
66 |
+
model = AutoModelForCausalLM.from_pretrained("id4thomas/emotion-predictor-Qwen2.5-3B-Instruct")
|
67 |
+
tokenizer = AutoTokenizer.from_pretrained("id4thomas/emotion-predictor-Qwen2.5-3B-Instruct")
|
68 |
+
|
69 |
+
# Initalize outlines generator
|
70 |
+
outlines_model = models.Transformers(model, tokenizer)
|
71 |
+
generator = outlines.generate.json(outlines_model, EntryResult)
|
72 |
+
|
73 |
+
# Generate
|
74 |
+
messages = [
|
75 |
+
{"role": "system", "content": system_message},
|
76 |
+
{"role": "user", "content": user_message}
|
77 |
+
]
|
78 |
+
input_text = tokenizer.apply_chat_template(
|
79 |
+
messages,
|
80 |
+
tokenize=False,
|
81 |
+
add_generation_prompt=True,
|
82 |
+
)
|
83 |
+
prediction = generator(input_text)
|
84 |
+
>>> EntryResult(emotion=EmotionLabel(joy=<RelationshipStatus.na: 'na'>, ...)
|
85 |
+
```
|
86 |
+
|
87 |
+
Using endpoint loaded with vllm & OpenAI client package
|
88 |
+
* example of using vllm container is provided [here](./assets/run_vllm.sh)
|
89 |
+
```
|
90 |
+
client = OpenAI(...)
|
91 |
+
json_schema = EntryResult.model_json_schema()
|
92 |
+
completion = client.chat.completions.create(
|
93 |
+
model="id4thomas/emotion-predictor-Qwen2.5-3B-Instruct",
|
94 |
+
messages=messages,
|
95 |
+
extra_body={"guided_json": json_schema},
|
96 |
+
)
|
97 |
+
print(completion.choices[0].message.content)
|
98 |
```
|