Datasets:
adding script
Browse files- persian_news_dataset.py +57 -0
persian_news_dataset.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
import csv
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
csv.field_size_limit(sys.maxsize)
|
6 |
+
|
7 |
+
_DESCRIPTION = """"""
|
8 |
+
_PROJECT_URL = """"""
|
9 |
+
_CITATION = """"""
|
10 |
+
# _URL = "https://drive.google.com/uc?export=download&id=1yrTpPZLdb1e6LHqKJfOT3RxRUQBBNEQn" ## SAMPLE
|
11 |
+
# _URL = "https://drive.google.com/uc?export=download&id=1-6oAYd6UQuuAkTAHEkToCg_Q5cJ2wXi-"
|
12 |
+
# _URL = "https://github.com/saied71/persian_news_dataset/blob/dev/sample_new.csv.zip?raw=true"
|
13 |
+
_URL = "persian_news_dataset.csv"
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
class Persian_news(datasets.GeneratorBasedBuilder):
|
18 |
+
|
19 |
+
def _info(self):
|
20 |
+
return datasets.DatasetInfo(
|
21 |
+
description=_DESCRIPTION,
|
22 |
+
features=datasets.Features(
|
23 |
+
{
|
24 |
+
"text": datasets.Value("string"),
|
25 |
+
"title": datasets.Value("string"),
|
26 |
+
"category": datasets.Value("string")
|
27 |
+
}
|
28 |
+
),
|
29 |
+
homepage=_PROJECT_URL,
|
30 |
+
citation=_CITATION,
|
31 |
+
)
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
def _split_generators(self, dl_manager):
|
36 |
+
"""Returns SplitGenerators."""
|
37 |
+
dl_dir = dl_manager.download_and_extract(_URL)
|
38 |
+
data_dir = os.path.join(dl_dir, "persian_news_dataset.csv")
|
39 |
+
return [
|
40 |
+
datasets.SplitGenerator(
|
41 |
+
name=datasets.Split.TRAIN,
|
42 |
+
gen_kwargs={
|
43 |
+
"filepath": data_dir,
|
44 |
+
},),]
|
45 |
+
|
46 |
+
def _generate_examples(self, filepath):
|
47 |
+
"""Yields examples."""
|
48 |
+
with open(filepath, encoding="utf-8") as f:
|
49 |
+
reader = csv.reader(f)
|
50 |
+
for id_, row in enumerate(reader):
|
51 |
+
if id_ == 0:
|
52 |
+
continue
|
53 |
+
yield id_, {
|
54 |
+
"text": row[0],
|
55 |
+
"title": row[2],
|
56 |
+
"category": row[1],
|
57 |
+
}
|