Untitled

 avatar
unknown
plain_text
a year ago
1.0 kB
4
Indexable
from datasets import load_dataset
import jsonlines

dataset = load_dataset('multi_news')
print(dataset)

def save_dataset_to_jsonl(dataset, filename):
    # Mở tệp JSONL để ghi
    with jsonlines.open(filename, mode='w') as writer:
        for split in dataset.keys():
            nums = 5
            if split == 'train':
                nums = 10
            i = 0
            for entry in dataset[split]:
                if i < nums:
                    # Tạo một đối tượng cho mỗi entry
                    data = {
                        'source_documents': entry['document'].split('\n \n'),
                        'summary': entry['summary'],
                        'label': split
                    }
                    # Ghi đối tượng vào tệp JSONL
                    writer.write(data)
                else:
                    break
                i += 1

# Lưu bộ dữ liệu vào tệp JSONL
save_dataset_to_jsonl(dataset, 'multinews.jsonl')
Editor is loading...
Leave a Comment