Zaid commited on
Commit
2cfddac
·
1 Parent(s): 0cfa5de

Create metrecv2.py

Browse files
Files changed (1) hide show
  1. metrecv2.py +114 -0
metrecv2.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """Arabic Poetry Metric v2 dataset."""
18
+
19
+
20
+ import os
21
+
22
+ import datasets
23
+ from datasets.tasks import TextClassification
24
+
25
+
26
+ _DESCRIPTION = """\
27
+ """
28
+
29
+ _CITATION = """\
30
+ """
31
+
32
+ _DOWNLOAD_URL = "https://drive.google.com/uc?export=download&id=11iIHChBR7sVcUfGMnxfEAjbe7sSjzx5M"
33
+
34
+
35
+ class MetRecV2Config(datasets.BuilderConfig):
36
+ """BuilderConfig for MetRecV2."""
37
+
38
+ def __init__(self, **kwargs):
39
+ """BuilderConfig for MetRecV2.
40
+ Args:
41
+ **kwargs: keyword arguments forwarded to super.
42
+ """
43
+ super(MetRecV2Config, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
44
+
45
+
46
+ class MetRecV2(datasets.GeneratorBasedBuilder):
47
+ """Metrec dataset."""
48
+
49
+ BUILDER_CONFIGS = [
50
+ MetRecV2Config(
51
+ name="plain_text",
52
+ description="Plain text",
53
+ )
54
+ ]
55
+
56
+ def _info(self):
57
+ return datasets.DatasetInfo(
58
+ description=_DESCRIPTION,
59
+ features=datasets.Features(
60
+ {
61
+ "text": datasets.Value("string"),
62
+ "label": datasets.features.ClassLabel(
63
+ names=[
64
+ "saree",
65
+ "kamel",
66
+ "mutakareb",
67
+ "mutadarak",
68
+ "munsareh",
69
+ "madeed",
70
+ "mujtath",
71
+ "ramal",
72
+ "baseet",
73
+ "khafeef",
74
+ "taweel",
75
+ "wafer",
76
+ "hazaj",
77
+ "rajaz",
78
+ "mudhare",
79
+ "muqtadheb",
80
+ "prose"
81
+ ]
82
+ ),
83
+ }
84
+ ),
85
+ supervised_keys=None,
86
+ homepage="",
87
+ citation=_CITATION,
88
+ task_templates=[TextClassification(text_column="text", label_column="label")],
89
+ )
90
+
91
+ def _vocab_text_gen(self, archive):
92
+ for _, ex in self._generate_examples(archive, os.path.join("final_baits", "train.txt")):
93
+ yield ex["text"]
94
+
95
+ def _split_generators(self, dl_manager):
96
+ data_dir = dl_manager.download_and_extract(_DOWNLOAD_URL)
97
+ #data_dir = os.path.join(arch_path, "final_baits")
98
+ return [
99
+ datasets.SplitGenerator(
100
+ name=datasets.Split.TRAIN, gen_kwargs={"directory": os.path.join(data_dir, "train.txt")}
101
+ ),
102
+ datasets.SplitGenerator(
103
+ name=datasets.Split.TEST, gen_kwargs={"directory": os.path.join(data_dir, "test.txt")}
104
+ ),
105
+ ]
106
+
107
+ def _generate_examples(self, directory, labeled=True):
108
+ """Generate examples."""
109
+ # For labeled examples, extract the label from the path.
110
+
111
+ with open(directory, encoding="UTF-8") as f:
112
+ for id_, record in enumerate(f.read().splitlines()):
113
+ label, bait = record.split(" ", 1)
114
+ yield str(id_), {"text": bait, "label": int(label)}