Update mistral.py
Browse files- mistral.py +34 -20
mistral.py
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
"""
|
2 |
-
KTO strategies for
|
3 |
"""
|
|
|
4 |
# pylint: disable=duplicate-code
|
|
|
|
|
5 |
def argilla(
|
6 |
cfg,
|
7 |
**kwargs,
|
@@ -9,16 +12,19 @@ def argilla(
|
|
9 |
def transform_fn(sample):
|
10 |
if "system" in sample and sample["system"]:
|
11 |
sample["prompt"] = (
|
12 |
-
f"<s>[SYSTEM_PROMPT]{sample['system']}[/SYSTEM_PROMPT]
|
|
|
13 |
)
|
14 |
else:
|
15 |
sample["prompt"] = (
|
16 |
-
f"<s>[INST]{sample['instruction']}[/INST]"
|
17 |
)
|
18 |
-
sample["completion"] = f"{sample['completion']}</s>"
|
19 |
return sample
|
|
|
20 |
return transform_fn
|
21 |
|
|
|
22 |
def argilla_chat(
|
23 |
cfg,
|
24 |
**kwargs,
|
@@ -26,67 +32,75 @@ def argilla_chat(
|
|
26 |
"""
|
27 |
for argilla/kto-mix-15k conversations
|
28 |
"""
|
29 |
-
def transform_fn(sample):
|
30 |
-
# Assuming sample['completion'] is a list of dicts like [{"role": "user", "content": "..."}]
|
31 |
-
# This function is simplified, you might need more complex logic for multi-turn
|
32 |
-
user_message = next((msg['content'] for msg in sample['completion'] if msg.get('role') == 'user'), '')
|
33 |
-
assistant_response = next((msg['content'] for msg in sample['completion'] if msg.get('role') == 'assistant'), '')
|
34 |
|
|
|
35 |
sample["prompt"] = (
|
36 |
-
f"<s>[INST]{
|
37 |
)
|
38 |
-
sample["completion"] = f"{
|
39 |
return sample
|
|
|
40 |
return transform_fn
|
41 |
|
|
|
42 |
def intel(cfg, **kwargs): # pylint: disable=possibly-unused-variable,unused-argument
|
43 |
"""
|
44 |
For Intel Orca KTO
|
45 |
ex: argilla/distilabel-intel-orca-kto
|
46 |
"""
|
|
|
47 |
def transform_fn(sample):
|
48 |
if "system" in sample and sample["system"]:
|
49 |
sample["prompt"] = (
|
50 |
-
f"<s>[SYSTEM_PROMPT]{sample['system']}[/SYSTEM_PROMPT]
|
|
|
51 |
)
|
52 |
else:
|
53 |
sample["prompt"] = (
|
54 |
-
f"<s>[INST]{sample['question']}[/INST]"
|
55 |
)
|
56 |
-
sample["completion"] = f"{sample['completion']}</s>"
|
57 |
return sample
|
|
|
58 |
return transform_fn
|
59 |
|
|
|
60 |
def prompt_pairs(
|
61 |
cfg, **kwargs
|
62 |
): # pylint: disable=possibly-unused-variable,unused-argument
|
63 |
def transform_fn(sample):
|
64 |
if "system" in sample and sample["system"]:
|
65 |
sample["prompt"] = (
|
66 |
-
f"<s>[SYSTEM_PROMPT]{sample['system']}[/SYSTEM_PROMPT]
|
|
|
67 |
)
|
68 |
else:
|
69 |
sample["prompt"] = (
|
70 |
-
f"<s>[INST]{sample['prompt']}[/INST]"
|
71 |
)
|
72 |
-
sample["completion"] = f"{sample['completion']}</s>"
|
73 |
return sample
|
|
|
74 |
return transform_fn
|
75 |
|
|
|
76 |
def ultra(cfg, **kwargs): # pylint: disable=possibly-unused-variable,unused-argument
|
77 |
"""
|
78 |
for ultrafeedback binarized conversations
|
79 |
ex: argilla/ultrafeedback-binarized-preferences-cleaned-kto
|
80 |
"""
|
|
|
81 |
def transform_fn(sample):
|
82 |
if "system" in sample and sample["system"]:
|
83 |
sample["prompt"] = (
|
84 |
-
f"<s>[SYSTEM_PROMPT]{sample['system']}[/SYSTEM_PROMPT]
|
|
|
85 |
)
|
86 |
else:
|
87 |
sample["prompt"] = (
|
88 |
-
f"<s>[INST]{sample['prompt']}[/INST]"
|
89 |
)
|
90 |
-
sample["completion"] = f"{sample['completion']}</s>"
|
91 |
return sample
|
|
|
92 |
return transform_fn
|
|
|
1 |
"""
|
2 |
+
KTO strategies for mistral chat template
|
3 |
"""
|
4 |
+
|
5 |
# pylint: disable=duplicate-code
|
6 |
+
|
7 |
+
|
8 |
def argilla(
|
9 |
cfg,
|
10 |
**kwargs,
|
|
|
12 |
def transform_fn(sample):
|
13 |
if "system" in sample and sample["system"]:
|
14 |
sample["prompt"] = (
|
15 |
+
f"<s>[SYSTEM_PROMPT] {sample['system']}[/SYSTEM_PROMPT]"
|
16 |
+
f"[INST] {sample['instruction']}[/INST]"
|
17 |
)
|
18 |
else:
|
19 |
sample["prompt"] = (
|
20 |
+
f"<s>[INST] {sample['instruction']}[/INST]"
|
21 |
)
|
22 |
+
sample["completion"] = f" {sample['completion']}</s>"
|
23 |
return sample
|
24 |
+
|
25 |
return transform_fn
|
26 |
|
27 |
+
|
28 |
def argilla_chat(
|
29 |
cfg,
|
30 |
**kwargs,
|
|
|
32 |
"""
|
33 |
for argilla/kto-mix-15k conversations
|
34 |
"""
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
def transform_fn(sample):
|
37 |
sample["prompt"] = (
|
38 |
+
f"<s>[INST] {sample['completion'][0]['content']}[/INST]"
|
39 |
)
|
40 |
+
sample["completion"] = f" {sample['completion'][1]['content']}</s>"
|
41 |
return sample
|
42 |
+
|
43 |
return transform_fn
|
44 |
|
45 |
+
|
46 |
def intel(cfg, **kwargs): # pylint: disable=possibly-unused-variable,unused-argument
|
47 |
"""
|
48 |
For Intel Orca KTO
|
49 |
ex: argilla/distilabel-intel-orca-kto
|
50 |
"""
|
51 |
+
|
52 |
def transform_fn(sample):
|
53 |
if "system" in sample and sample["system"]:
|
54 |
sample["prompt"] = (
|
55 |
+
f"<s>[SYSTEM_PROMPT] {sample['system']}[/SYSTEM_PROMPT]"
|
56 |
+
f"[INST] {sample['question']}[/INST]"
|
57 |
)
|
58 |
else:
|
59 |
sample["prompt"] = (
|
60 |
+
f"<s>[INST] {sample['question']}[/INST]"
|
61 |
)
|
62 |
+
sample["completion"] = f" {sample['completion']}</s>"
|
63 |
return sample
|
64 |
+
|
65 |
return transform_fn
|
66 |
|
67 |
+
|
68 |
def prompt_pairs(
|
69 |
cfg, **kwargs
|
70 |
): # pylint: disable=possibly-unused-variable,unused-argument
|
71 |
def transform_fn(sample):
|
72 |
if "system" in sample and sample["system"]:
|
73 |
sample["prompt"] = (
|
74 |
+
f"<s>[SYSTEM_PROMPT] {sample['system']}[/SYSTEM_PROMPT]"
|
75 |
+
f"[INST] {sample['prompt']}[/INST] "
|
76 |
)
|
77 |
else:
|
78 |
sample["prompt"] = (
|
79 |
+
f"<s>[INST] {sample['prompt']}[/INST]"
|
80 |
)
|
81 |
+
sample["completion"] = f" {sample['completion']}</s>"
|
82 |
return sample
|
83 |
+
|
84 |
return transform_fn
|
85 |
|
86 |
+
|
87 |
def ultra(cfg, **kwargs): # pylint: disable=possibly-unused-variable,unused-argument
|
88 |
"""
|
89 |
for ultrafeedback binarized conversations
|
90 |
ex: argilla/ultrafeedback-binarized-preferences-cleaned-kto
|
91 |
"""
|
92 |
+
|
93 |
def transform_fn(sample):
|
94 |
if "system" in sample and sample["system"]:
|
95 |
sample["prompt"] = (
|
96 |
+
f"<s>[SYSTEM_PROMPT] {sample['system']}[/SYSTEM_PROMPT]"
|
97 |
+
f"[INST] {sample['prompt']}[/INST]"
|
98 |
)
|
99 |
else:
|
100 |
sample["prompt"] = (
|
101 |
+
f"<s>[INST] {sample['prompt']}[/INST]"
|
102 |
)
|
103 |
+
sample["completion"] = f" {sample['completion']}</s>"
|
104 |
return sample
|
105 |
+
|
106 |
return transform_fn
|