tweet_generation / process /tweet_corpus.py
asahi417's picture
init
db30823
raw
history blame contribute delete
912 Bytes
"""
2018: 10,732,804
2019: 9,725,094
2020: 31,449,608
2021: 37,282,461
2022: 74,024,575
"""
import json
import os
files = [
"dataset/tweets/2018.jsonline",
"dataset/tweets/2019.jsonline",
"dataset/tweets/2020.jsonline",
"dataset/tweets/2021.jsonline",
"dataset/tweets/2022.jsonline"
]
n_shard = 10000
root_dir = "dataset/tweets_sharded"
os.makedirs(root_dir, exist_ok=True)
counter = 0
file_id = 0
f_writer = open(f"{root_dir}/{file_id}.jsonl")
for i in files:
with open(i) as f:
for line in f:
tmp = json.loads(line)
tmp = {"id": tmp["id"], "text": tmp["text"], "date": tmp["created_at"]}
f_writer.write(json.dumps(tmp) + '\n')
counter += 1
if counter > n_shard:
file_id += 1
counter = 0
f_writer.close()
f_writer = open(f"{root_dir}/{file_id}.jsonl")