File size: 868 Bytes
0fd18e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from datasets import load_dataset
import json
import os
from huggingface_hub import create_repo, upload_file

dataset = load_dataset("banking77")
id2label = dataset['train'].features['label'].names

repo_name = "banking77"
create_repo(repo_name, organization="mteb", repo_type="dataset")
for split in ['train', 'test']:
    savepath = f'{os.path.dirname(__file__)}/{split}.jsonl'
    with open(savepath, 'w') as fOut:
        rows = list(dataset[split])
        if split == 'test' and 'validation' in dataset:
            rows += list(dataset['validation'])
            
        for id, row in rows:
            fOut.write(json.dumps({'text': row['text'], 'label': row['label'], 'label_text': id2label[row['label']]})+"\n")
    
    upload_file(savepath, path_in_repo=f"{split}.jsonl", repo_id="mteb/" + repo_name, repo_type="dataset")
    os.system(f"rm {savepath}")