Datasets:

Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
Libraries:
Datasets
Dask
License:
crodri commited on
Commit
ef0d673
1 Parent(s): 3659a68

Upload wikicat_en.py

Browse files
Files changed (1) hide show
  1. wikicat_en.py +88 -0
wikicat_en.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Loading script for the WikiCAT dataset.
2
+ import json
3
+ import datasets
4
+
5
+ logger = datasets.logging.get_logger(__name__)
6
+
7
+ _CITATION = """
8
+
9
+ """
10
+
11
+ _DESCRIPTION = """
12
+ WikiCAT: Text Classification English dataset from the Viquipedia
13
+
14
+ """
15
+
16
+ _HOMEPAGE = """ """
17
+
18
+ # TODO: upload datasets to github
19
+ _URL = "https://huggingface.co/datasets/crodri/wikicat_en/resolve/main/"
20
+ _TRAINING_FILE = "hftrain_en.json"
21
+ _DEV_FILE = "hfeval_en.json"
22
+ #_TEST_FILE = "test.json"
23
+
24
+
25
+ class wikicat_enConfig(datasets.BuilderConfig):
26
+ """ Builder config for the Topicat dataset """
27
+
28
+ def __init__(self, **kwargs):
29
+ """BuilderConfig for wikicat_en.
30
+ Args:
31
+ **kwargs: keyword arguments forwarded to super.
32
+ """
33
+ super(teclaConfig, self).__init__(**kwargs)
34
+
35
+
36
+ class wikicat_en(datasets.GeneratorBasedBuilder):
37
+ """ wikicat_en Dataset """
38
+
39
+ BUILDER_CONFIGS = [
40
+ wikicat_enConfig(
41
+ name="wikicat_en",
42
+ version=datasets.Version("1.1.0"),
43
+ description="wikicat_en",
44
+ ),
45
+ ]
46
+
47
+ def _info(self):
48
+ return datasets.DatasetInfo(
49
+ description=_DESCRIPTION,
50
+ features=datasets.Features(
51
+ {
52
+ "text": datasets.Value("string"),
53
+ "label": datasets.features.ClassLabel
54
+ (names= ['Health', 'Law', 'Entertainment', 'Religion', 'Business', 'Science', 'Engineering', 'Nature', 'Philosophy', 'Economy', 'Sports', 'Technology', 'Government', 'Mathematics', 'Military', 'Humanities', 'Music', 'Politics', 'History']
55
+ ),
56
+ }
57
+ ),
58
+ homepage=_HOMEPAGE,
59
+ citation=_CITATION,
60
+ )
61
+
62
+ def _split_generators(self, dl_manager):
63
+ """Returns SplitGenerators."""
64
+ urls_to_download = {
65
+ "train": f"{_URL}{_TRAINING_FILE}",
66
+ "dev": f"{_URL}{_DEV_FILE}",
67
+ # "test": f"{_URL}{_TEST_FILE}",
68
+ }
69
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
70
+
71
+ return [
72
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
73
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
74
+ # datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
75
+ ]
76
+
77
+ def _generate_examples(self, filepath):
78
+ """This function returns the examples in the raw (text) form."""
79
+ logger.info("generating examples from = %s", filepath)
80
+ with open(filepath, encoding="utf-8") as f:
81
+ wikicat_en = json.load(f)
82
+ for id_, article in enumerate(wikicat_en["data"]):
83
+ text = article["sentence"]
84
+ label = article["label"]
85
+ yield id_, {
86
+ "text": text,
87
+ "label": label,
88
+ }