asdf98 commited on
Commit
83c7453
·
verified ·
1 Parent(s): c1d2a73

Add dataset options and replacement loader cell

Browse files
Files changed (1) hide show
  1. DATASET_OPTIONS.md +163 -0
DATASET_OPTIONS.md ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dataset Options for the Fine-Tuning Notebooks
2
+
3
+ Use these values in the config cell:
4
+
5
+ ```python
6
+ DATASET_CHOICE = "cybersecurity"
7
+ # DATASET_CHOICE = "code_corpus"
8
+ # DATASET_CHOICE = "ultrachat"
9
+ # DATASET_CHOICE = "openhermes"
10
+ # DATASET_CHOICE = "sharegpt_en"
11
+ # DATASET_CHOICE = "sharegpt_de"
12
+ # DATASET_CHOICE = "sharegpt_hi"
13
+ # DATASET_CHOICE = "custom_mix"
14
+ ```
15
+
16
+ ## Recommended choices
17
+
18
+ | Choice | Dataset | Best for |
19
+ |---|---|---|
20
+ | `cybersecurity` | `AlicanKiraz0/Cybersecurity-Dataset-Fenrir-v2.1` + `Trendyol/Trendyol-Cybersecurity-Instruction-Tuning-Dataset` | ethical hacking / cyber defense |
21
+ | `code_corpus` | `krystv/code-corpus-llm-training` | code explanation, completion, refactoring |
22
+ | `ultrachat` | `HuggingFaceH4/ultrachat_200k` | general assistant chat |
23
+ | `openhermes` | `teknium/OpenHermes-2.5` | reasoning, coding, general instruction |
24
+ | `sharegpt_en` | `deepmage121/ShareGPT_multilingual`, English split | English multi-turn dialogue |
25
+ | `sharegpt_de` | `deepmage121/ShareGPT_multilingual`, German translated split | German dialogue |
26
+ | `sharegpt_hi` | `deepmage121/ShareGPT_multilingual`, Hindi translated split | Hindi dialogue |
27
+ | `custom_mix` | mix any supported datasets | hybrid assistant |
28
+
29
+ ## Full replacement dataset cell
30
+
31
+ If a notebook does not yet show all choices, replace its dataset-loading cell with this one:
32
+
33
+ ```python
34
+ from datasets import load_dataset, concatenate_datasets
35
+
36
+ SYSTEM_SAFE = "You are a cybersecurity education assistant. Provide defensive, ethical, and authorized security guidance only. Refuse harmful or unauthorized requests."
37
+
38
+ # Uncomment one in config cell:
39
+ # DATASET_CHOICE = "cybersecurity"
40
+ # DATASET_CHOICE = "code_corpus"
41
+ # DATASET_CHOICE = "ultrachat"
42
+ # DATASET_CHOICE = "openhermes"
43
+ # DATASET_CHOICE = "sharegpt_en"
44
+ # DATASET_CHOICE = "sharegpt_de"
45
+ # DATASET_CHOICE = "sharegpt_hi"
46
+ # DATASET_CHOICE = "custom_mix"
47
+
48
+ CUSTOM_DATASETS = [
49
+ # (dataset_id, split, n_rows, format_type)
50
+ # format_type: cyber_sua | ultrachat | conversations | code
51
+ ("AlicanKiraz0/Cybersecurity-Dataset-Fenrir-v2.1", "train", 5000, "cyber_sua"),
52
+ ("Trendyol/Trendyol-Cybersecurity-Instruction-Tuning-Dataset", "train", 5000, "cyber_sua"),
53
+ ("teknium/OpenHermes-2.5", "train", 10000, "conversations"),
54
+ ("krystv/code-corpus-llm-training", "train", 10000, "code"),
55
+ ]
56
+
57
+ def convert_sua(example):
58
+ return {"messages": [
59
+ {"role": "system", "content": example.get("system") or SYSTEM_SAFE},
60
+ {"role": "user", "content": example["user"]},
61
+ {"role": "assistant", "content": example["assistant"]},
62
+ ]}
63
+
64
+ def convert_ultrachat(example):
65
+ return {"messages": example["messages"]}
66
+
67
+ def convert_conversations(example):
68
+ msgs = []
69
+ sys_prompt = example.get("system_prompt", "") or example.get("system", "")
70
+ if sys_prompt:
71
+ msgs.append({"role": "system", "content": sys_prompt})
72
+ for turn in example["conversations"]:
73
+ role = "user" if turn.get("from") in ("human", "user") else "assistant"
74
+ content = turn.get("value", "")
75
+ if content:
76
+ msgs.append({"role": role, "content": content})
77
+ return {"messages": msgs}
78
+
79
+ def convert_code(example):
80
+ code_text = example.get("text", "")
81
+ lang = example.get("language", "")
82
+ repo = example.get("repo", "unknown")
83
+ prompt = f"Explain, review, and improve this {lang} code snippet from repo {repo}. Focus on correctness, security, performance, and clarity."
84
+ return {"messages": [
85
+ {"role": "system", "content": "You are a careful coding assistant focused on secure, correct, maintainable code."},
86
+ {"role": "user", "content": prompt},
87
+ {"role": "assistant", "content": code_text},
88
+ ]}
89
+
90
+ def apply_converter(ds, fmt):
91
+ if fmt == "cyber_sua":
92
+ return ds.map(convert_sua, remove_columns=ds.column_names)
93
+ if fmt == "ultrachat":
94
+ return ds.map(convert_ultrachat, remove_columns=ds.column_names)
95
+ if fmt == "conversations":
96
+ return ds.map(convert_conversations, remove_columns=ds.column_names)
97
+ if fmt == "code":
98
+ return ds.map(convert_code, remove_columns=ds.column_names)
99
+ raise ValueError(f"Unknown format_type: {fmt}")
100
+
101
+ all_datasets = []
102
+
103
+ if DATASET_CHOICE == "cybersecurity":
104
+ ds1 = load_dataset("AlicanKiraz0/Cybersecurity-Dataset-Fenrir-v2.1", split="train")
105
+ ds2 = load_dataset("Trendyol/Trendyol-Cybersecurity-Instruction-Tuning-Dataset", split="train")
106
+ all_datasets = [apply_converter(ds1, "cyber_sua"), apply_converter(ds2, "cyber_sua")]
107
+
108
+ elif DATASET_CHOICE == "code_corpus":
109
+ ds = load_dataset("krystv/code-corpus-llm-training", split="train")
110
+ all_datasets = [apply_converter(ds, "code")]
111
+
112
+ elif DATASET_CHOICE == "ultrachat":
113
+ ds = load_dataset("HuggingFaceH4/ultrachat_200k", split="train_sft")
114
+ all_datasets = [apply_converter(ds, "ultrachat")]
115
+
116
+ elif DATASET_CHOICE == "openhermes":
117
+ ds = load_dataset("teknium/OpenHermes-2.5", split="train")
118
+ all_datasets = [apply_converter(ds, "conversations")]
119
+
120
+ elif DATASET_CHOICE.startswith("sharegpt_"):
121
+ split_map = {
122
+ "sharegpt_en": "english",
123
+ "sharegpt_de": "german_4b_translated",
124
+ "sharegpt_hi": "hindi_27b_translated",
125
+ }
126
+ ds = load_dataset("deepmage121/ShareGPT_multilingual", split=split_map[DATASET_CHOICE])
127
+ all_datasets = [apply_converter(ds, "conversations")]
128
+
129
+ elif DATASET_CHOICE == "custom_mix":
130
+ for ds_id, split, n_rows, fmt in CUSTOM_DATASETS:
131
+ print(f"Loading {ds_id} split={split} rows={n_rows} format={fmt}")
132
+ ds = load_dataset(ds_id, split=split)
133
+ if n_rows and len(ds) > n_rows:
134
+ ds = ds.shuffle(seed=SEED).select(range(n_rows))
135
+ all_datasets.append(apply_converter(ds, fmt))
136
+
137
+ else:
138
+ raise ValueError(f"Unknown DATASET_CHOICE: {DATASET_CHOICE}")
139
+
140
+ dataset = concatenate_datasets(all_datasets) if len(all_datasets) > 1 else all_datasets[0]
141
+ print(f"Rows before sampling: {len(dataset):,}")
142
+
143
+ if SAMPLE_SIZE and len(dataset) > SAMPLE_SIZE:
144
+ dataset = dataset.shuffle(seed=SEED).select(range(SAMPLE_SIZE))
145
+ print(f"Rows after sampling: {len(dataset):,}")
146
+
147
+ print("Sample:")
148
+ for m in dataset[0]["messages"]:
149
+ print(m["role"], ":", m["content"][:160].replace("\n", " "))
150
+ ```
151
+
152
+ ## Notes
153
+
154
+ - For `code_corpus`, use lower `MAX_SEQ_LENGTH` at first because code files can be long:
155
+
156
+ ```python
157
+ MAX_SEQ_LENGTH = 2048
158
+ SAMPLE_SIZE = 10000
159
+ MAX_STEPS = 500
160
+ ```
161
+
162
+ - For `custom_mix`, keep each source smaller first to verify training starts.
163
+ - For Kaggle T4, LFM2.5 is still the safest model for all dataset options.