persian_daily_news / persian_daily_news.py
Ubuntu
add intial files
bbe1ca4
import datasets
import csv
import os
import sys
csv.field_size_limit(sys.maxsize)
_DESCRIPTION = """Persian Daily News dataset is a collection of 2 million news articles with the headline of each news article.
This dataset contains news articles and their summaries for the last 10 years.
This dataset is provided by Rohan AI lab for research purposes.
"""
_PROJECT_URL = """"""
_CITATION = """
https://saied71.github.io/RohanAiLab/,
author={Saied Alimoradi},
year={2021}
}
"""
_URL = "persian_daily.zip"
class Persian_news(datasets.GeneratorBasedBuilder):
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"text": datasets.Value("string"),
"summary": datasets.Value("string"),
}
),
homepage=_PROJECT_URL,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
dl_dir = dl_manager.download_and_extract(_URL)
data_dir = os.path.join(dl_dir, "persian_daily.csv")
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": data_dir,
},),]
def _generate_examples(self, filepath):
"""Yields examples."""
with open(filepath, encoding="utf-8") as f:
reader = csv.reader(f)
for id_, row in enumerate(reader):
if id_ == 0:
continue
yield id_, {
"text": row[1],
"summary": row[0]
}