id4thomas lbourdois commited on
Commit
126efa4
·
verified ·
1 Parent(s): fda3f5b

Improve language tag (#1)

Browse files

- Improve language tag (c0190e04ac085313d7e8840542ac21024cf79e74)


Co-authored-by: Loïck BOURDOIS <[email protected]>

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