File size: 1,215 Bytes
44a624a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from datasets import load_dataset
import hashlib

def main():
    ds = load_dataset("GAIR/lima" ,split="train")
    ds_test = load_dataset("GAIR/lima" ,split="test")
    
    ds = ds.map(lambda x: {
        "length": len(x['conversations'])
        })
    
    ds = ds.filter(lambda x: x['length'] == 2)
    
    ds = ds.map(
        lambda x: {
        "prompt_id": hashlib.sha256(x['conversations'][0].encode("utf-8")).hexdigest(),
        "prompt": x['conversations'][0],
        "messages": [
            {"role": "user", "content": x['conversations'][0]},
            {"role": "assistant", "content": x['conversations'][1]}
        ],
        "meta": {"source": "lima", "category": x['source']}
    })
    
    ds_test = ds_test.map(lambda x: {
        "prompt_id": hashlib.sha256(x['conversations'][0].encode("utf-8")).hexdigest(),
        "prompt": x['conversations'][0],
        "messages": [
            {"role": "user", "content": x['conversations'][0]},
        ],
        "meta": {"source": "lima", "category": x['source']}
    })
    
    ds.push_to_hub("HuggingFaceH4/lima", split = "train_ift")
    ds_test.push_to_hub("HuggingFaceH4/lima", split = "test_ift")

if __name__ == "__main__":
    main()