tweets / tweets.py
qgyd2021's picture
first commit
0be65ae
raw
history blame
1.92 kB
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from glob import glob
import json
import os
from pathlib import Path
import datasets
_URLS = {
"tweets_with_emoji": "data/tweets_with_emoji.jsonl",
}
_CITATION = """\
@dataset{tweets,
author = {Xing Tian},
title = {tweets},
month = aug,
year = 2024,
publisher = {Xing Tian},
version = {1.0},
}
"""
class Tweets(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="tweets_with_emoji", version=VERSION, description="tweets_with_emoji"),
]
def _info(self):
features = datasets.Features(
{
"text": datasets.Value("string"),
"category": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
features=features,
supervised_keys=None,
homepage="",
license="",
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
url = _URLS[self.config.name]
dl_path = dl_manager.download(url)
archive_path = dl_path
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"archive_path": archive_path, "split": "train"},
),
]
def _generate_examples(self, archive_path, split):
archive_path = Path(archive_path)
idx = 0
with open(archive_path, "r", encoding="utf-8") as f:
for row in f:
row = json.loads(row)
text = row["text"]
category = row["category"]
yield idx, {
"text": text,
"category": category,
}
idx += 1
if __name__ == '__main__':
pass