crodri commited on
Commit
f8290a3
1 Parent(s): 213275f

Upload wikicat_ca.py

Browse files
Files changed (1) hide show
  1. wikicat_ca.py +88 -0
wikicat_ca.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Loading script for the TeCla 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 Catalan dataset from the Viquipedia
13
+
14
+ """
15
+
16
+ _HOMEPAGE = """ """
17
+
18
+ # TODO: upload datasets to github
19
+ _URL = "https://huggingface.co/datasets/crodri/wikicat_ca/resolve/main/"
20
+ _TRAINING_FILE = "hftrain_ca.json"
21
+ _DEV_FILE = "hfeval_ca.json"
22
+ #_TEST_FILE = "test.json"
23
+
24
+
25
+ class teclaConfig(datasets.BuilderConfig):
26
+ """ Builder config for the Topicat dataset """
27
+
28
+ def __init__(self, **kwargs):
29
+ """BuilderConfig for TeCla.
30
+ Args:
31
+ **kwargs: keyword arguments forwarded to super.
32
+ """
33
+ super(teclaConfig, self).__init__(**kwargs)
34
+
35
+
36
+ class topicat(datasets.GeneratorBasedBuilder):
37
+ """ WikiCAT_ca Dataset """
38
+
39
+ BUILDER_CONFIGS = [
40
+ teclaConfig(
41
+ name="WikiCAT_ca",
42
+ version=datasets.Version("1.1.0"),
43
+ description="WikiCAT_ca",
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= ['Història', 'Tecnologia', 'Humanitats', 'Economia', 'Dret', 'Esport', 'Política', 'Govern', 'Entreteniment', 'Natura', 'Exèrcit', 'Salut_i_benestar_social', 'Matemàtiques', 'Filosofia', 'Ciència', 'Música', 'Enginyeria', 'Empresa', 'Religió']
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
+ acn_ca = json.load(f)
82
+ for id_, article in enumerate(acn_ca["data"]):
83
+ text = article["sentence"]
84
+ label = article["label"]
85
+ yield id_, {
86
+ "text": text,
87
+ "label": label,
88
+ }