Datasets:
Tasks:
Text Classification
Modalities:
Text
Formats:
parquet
Languages:
Arabic
Size:
10K - 100K
Tags:
poetry-classification
License:
Delete loading script
Browse files
metrec.py
DELETED
@@ -1,124 +0,0 @@
|
|
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 dataset."""
|
18 |
-
|
19 |
-
|
20 |
-
import os
|
21 |
-
|
22 |
-
import datasets
|
23 |
-
from datasets.tasks import TextClassification
|
24 |
-
|
25 |
-
|
26 |
-
_DESCRIPTION = """\
|
27 |
-
Arabic Poetry Metric Classification.
|
28 |
-
The dataset contains the verses and their corresponding meter classes.\
|
29 |
-
Meter classes are represented as numbers from 0 to 13. \
|
30 |
-
The dataset can be highly useful for further research in order to improve the field of Arabic poems’ meter classification.\
|
31 |
-
The train dataset contains 47,124 records and the test dataset contains 8316 records.
|
32 |
-
"""
|
33 |
-
|
34 |
-
_CITATION = """\
|
35 |
-
@article{metrec2020,
|
36 |
-
title={MetRec: A dataset for meter classification of arabic poetry},
|
37 |
-
author={Al-shaibani, Maged S and Alyafeai, Zaid and Ahmad, Irfan},
|
38 |
-
journal={Data in Brief},
|
39 |
-
year={2020},
|
40 |
-
publisher={Elsevier}
|
41 |
-
}
|
42 |
-
"""
|
43 |
-
|
44 |
-
_DOWNLOAD_URL = "https://raw.githubusercontent.com/zaidalyafeai/MetRec/master/baits.zip"
|
45 |
-
|
46 |
-
|
47 |
-
class MetRecConfig(datasets.BuilderConfig):
|
48 |
-
"""BuilderConfig for MetRec."""
|
49 |
-
|
50 |
-
def __init__(self, **kwargs):
|
51 |
-
"""BuilderConfig for MetRec.
|
52 |
-
|
53 |
-
Args:
|
54 |
-
**kwargs: keyword arguments forwarded to super.
|
55 |
-
"""
|
56 |
-
super(MetRecConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
|
57 |
-
|
58 |
-
|
59 |
-
class Metrec(datasets.GeneratorBasedBuilder):
|
60 |
-
"""Metrec dataset."""
|
61 |
-
|
62 |
-
BUILDER_CONFIGS = [
|
63 |
-
MetRecConfig(
|
64 |
-
name="plain_text",
|
65 |
-
description="Plain text",
|
66 |
-
)
|
67 |
-
]
|
68 |
-
|
69 |
-
def _info(self):
|
70 |
-
return datasets.DatasetInfo(
|
71 |
-
description=_DESCRIPTION,
|
72 |
-
features=datasets.Features(
|
73 |
-
{
|
74 |
-
"text": datasets.Value("string"),
|
75 |
-
"label": datasets.features.ClassLabel(
|
76 |
-
names=[
|
77 |
-
"saree",
|
78 |
-
"kamel",
|
79 |
-
"mutakareb",
|
80 |
-
"mutadarak",
|
81 |
-
"munsareh",
|
82 |
-
"madeed",
|
83 |
-
"mujtath",
|
84 |
-
"ramal",
|
85 |
-
"baseet",
|
86 |
-
"khafeef",
|
87 |
-
"taweel",
|
88 |
-
"wafer",
|
89 |
-
"hazaj",
|
90 |
-
"rajaz",
|
91 |
-
]
|
92 |
-
),
|
93 |
-
}
|
94 |
-
),
|
95 |
-
supervised_keys=None,
|
96 |
-
homepage="https://github.com/zaidalyafeai/MetRec",
|
97 |
-
citation=_CITATION,
|
98 |
-
task_templates=[TextClassification(text_column="text", label_column="label")],
|
99 |
-
)
|
100 |
-
|
101 |
-
def _vocab_text_gen(self, archive):
|
102 |
-
for _, ex in self._generate_examples(archive, os.path.join("final_baits", "train.txt")):
|
103 |
-
yield ex["text"]
|
104 |
-
|
105 |
-
def _split_generators(self, dl_manager):
|
106 |
-
arch_path = dl_manager.download_and_extract(_DOWNLOAD_URL)
|
107 |
-
data_dir = os.path.join(arch_path, "final_baits")
|
108 |
-
return [
|
109 |
-
datasets.SplitGenerator(
|
110 |
-
name=datasets.Split.TRAIN, gen_kwargs={"directory": os.path.join(data_dir, "train.txt")}
|
111 |
-
),
|
112 |
-
datasets.SplitGenerator(
|
113 |
-
name=datasets.Split.TEST, gen_kwargs={"directory": os.path.join(data_dir, "test.txt")}
|
114 |
-
),
|
115 |
-
]
|
116 |
-
|
117 |
-
def _generate_examples(self, directory, labeled=True):
|
118 |
-
"""Generate examples."""
|
119 |
-
# For labeled examples, extract the label from the path.
|
120 |
-
|
121 |
-
with open(directory, encoding="UTF-8") as f:
|
122 |
-
for id_, record in enumerate(f.read().splitlines()):
|
123 |
-
label, bait = record.split(" ", 1)
|
124 |
-
yield str(id_), {"text": bait, "label": int(label)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|