nazneen commited on
Commit
44a624a
·
1 Parent(s): 809c835

Create create_dataset.py

Browse files
Files changed (1) hide show
  1. create_dataset.py +38 -0
create_dataset.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ import hashlib
3
+
4
+ def main():
5
+ ds = load_dataset("GAIR/lima" ,split="train")
6
+ ds_test = load_dataset("GAIR/lima" ,split="test")
7
+
8
+ ds = ds.map(lambda x: {
9
+ "length": len(x['conversations'])
10
+ })
11
+
12
+ ds = ds.filter(lambda x: x['length'] == 2)
13
+
14
+ ds = ds.map(
15
+ lambda x: {
16
+ "prompt_id": hashlib.sha256(x['conversations'][0].encode("utf-8")).hexdigest(),
17
+ "prompt": x['conversations'][0],
18
+ "messages": [
19
+ {"role": "user", "content": x['conversations'][0]},
20
+ {"role": "assistant", "content": x['conversations'][1]}
21
+ ],
22
+ "meta": {"source": "lima", "category": x['source']}
23
+ })
24
+
25
+ ds_test = ds_test.map(lambda x: {
26
+ "prompt_id": hashlib.sha256(x['conversations'][0].encode("utf-8")).hexdigest(),
27
+ "prompt": x['conversations'][0],
28
+ "messages": [
29
+ {"role": "user", "content": x['conversations'][0]},
30
+ ],
31
+ "meta": {"source": "lima", "category": x['source']}
32
+ })
33
+
34
+ ds.push_to_hub("HuggingFaceH4/lima", split = "train_ift")
35
+ ds_test.push_to_hub("HuggingFaceH4/lima", split = "test_ift")
36
+
37
+ if __name__ == "__main__":
38
+ main()