Skip to content

Instantly share code, notes, and snippets.

Last active November 14, 2021 23:13
What would you like to do?
convert Reuters dataset on kaggle to json file
import logging
import os
import sys
import json
from typing import Dict, Optional
from import tqdm
import timeit
import numpy as np
test = []
train = []
with open("cats.txt") as f:
content = f.readlines()
for line in tqdm(content):
line = line.replace("\n","")
line = line.split(" ")
file = line[0]
labels = line[1:]
with open(file, encoding="utf8", errors='ignore') as f:
data ='\n', '')
if 'test' in file:
test.append({"text" : data, "labels" : labels})
elif 'train' in file:
train.append({"text" : data, "labels" : labels})
print("invalid file ", file)
with open('test.json', 'w') as outFile:
for d in test:
with open('train.json', 'w') as outFile:
for d in train:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment