File size: 665 Bytes
36889a1
 
 
b83b208
 
36889a1
 
b83b208
 
 
 
 
 
 
 
36889a1
 
b83b208
 
36889a1
 
 
b83b208
 
36889a1
 
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
from datasets import load_dataset


# +

def main():
    raw_dset = load_dataset("go_emotions", "simplified")
    labels = raw_dset["train"].features["labels"].feature
    
    def create_labels(row):
        labels_columns = {}
        for _label in labels.names:
            labels_columns.setdefault(_label, 0)
        labels_columns.update({labels.int2str(_l):1 for _l in row['labels']})
        return labels_columns

    for split, dset in raw_dset.items():
        dset = dset.map(lambda x: create_labels(x), num_proc=4)
        dset = dset.remove_columns(["id", "labels"])
        dset.to_json(f"{split}.jsonl")


# -

if __name__ == "__main__":
    main()