File size: 1,841 Bytes
ac33b75
 
 
 
 
 
7e822b5
 
 
e15e542
7e822b5
 
ac33b75
7e822b5
 
e15e542
7e822b5
 
 
 
 
0acac13
b6df865
ac33b75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b6df865
ac33b75
 
 
 
b6df865
ac33b75
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import datasets
import csv
import os
import sys
csv.field_size_limit(sys.maxsize)

_DESCRIPTION = """
persian_news_dataset is a collection of 5 million news articles. 
News articles have been gathered from more than 10 news agencies for the last 12 years. 
The dataset is provided by Rohan AI lab for research purposes.
for more information refer to this link:
"""
_PROJECT_URL = """"""


_CITATION = """
https://saied71.github.io/RohanAiLab/,
  author={Saied Alimoradi},
  year={2021}
}
"""

_URL = "persian_news_dataset.zip"



class Persian_news(datasets.GeneratorBasedBuilder):

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "text": datasets.Value("string"),
                    "title": datasets.Value("string"),
                    "category": 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_news_dataset.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[0],
                    "title": row[2],
                    "category": row[1],
                }