forked from MakazhanAlpamys/Soup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreference.py
More file actions
47 lines (41 loc) · 1.67 KB
/
Copy pathpreference.py
File metadata and controls
47 lines (41 loc) · 1.67 KB
1
2
3
4
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
"""Preference data template for DPO/KTO/ORPO synthetic data generation."""
SYSTEM_PROMPT = (
"You are a preference training data generator. Generate examples with both "
"good (chosen) and bad (rejected) responses for preference learning."
)
def build_prompt(
count: int,
task: str = "dpo",
) -> str:
"""Build the generation prompt for preference data.
Args:
count: Number of examples to generate.
task: Target task format (dpo/kto/orpo).
Returns:
Complete generation prompt string.
"""
if task == "kto":
format_desc = (
'Each example must be a JSON object with keys: '
'"prompt" (the user question), '
'"completion" (the model response), '
'"label" (boolean: true for good, false for bad). '
'Generate roughly equal numbers of true and false labels.'
)
else:
# DPO / ORPO format
format_desc = (
'Each example must be a JSON object with keys: '
'"prompt" (the user question), '
'"chosen" (a good, helpful response), '
'"rejected" (a bad, unhelpful, or incorrect response). '
'The chosen response should be clearly better than the rejected one.'
)
return (
f"You are a training data generator. Generate exactly {count} diverse, "
f"high-quality preference training examples.\n\n"
f"Format: {format_desc}\n\n"
f"Cover diverse topics: math, science, coding, writing, reasoning.\n"
f"Make rejected responses subtly wrong (not obviously garbage).\n\n"
f"Return ONLY a JSON array of {count} examples. No markdown, no explanation."
)