Datasets:
Tasks:
Text Classification
Modalities:
Text
Formats:
parquet
Languages:
English
Size:
10K - 100K
Tags:
long context
Commit
•
fe89f60
1
Parent(s):
93a8b11
Delete loading script
Browse files- arxiv-classification.py +0 -112
arxiv-classification.py
DELETED
@@ -1,112 +0,0 @@
|
|
1 |
-
import json
|
2 |
-
import os
|
3 |
-
|
4 |
-
import datasets
|
5 |
-
from datasets.tasks import TextClassification
|
6 |
-
|
7 |
-
_CITATION = None
|
8 |
-
|
9 |
-
|
10 |
-
_DESCRIPTION = """
|
11 |
-
Arxiv Classification Dataset: a classification of Arxiv Papers (11 classes).
|
12 |
-
It contains 11 slightly unbalanced classes, 33k Arxiv Papers divided into 3 splits: train (23k), val (5k) and test (5k).
|
13 |
-
Copied from "Long Document Classification From Local Word Glimpses via Recurrent Attention Learning" by JUN HE LIQUN WANG LIU LIU, JIAO FENG AND HAO WU
|
14 |
-
See: https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=8675939
|
15 |
-
See: https://github.com/LiqunW/Long-document-dataset
|
16 |
-
"""
|
17 |
-
|
18 |
-
_LABELS = [
|
19 |
-
"math.AC",
|
20 |
-
"cs.CV",
|
21 |
-
"cs.AI",
|
22 |
-
"cs.SY",
|
23 |
-
"math.GR",
|
24 |
-
"cs.CE",
|
25 |
-
"cs.PL",
|
26 |
-
"cs.IT",
|
27 |
-
"cs.DS",
|
28 |
-
"cs.NE",
|
29 |
-
"math.ST"
|
30 |
-
]
|
31 |
-
|
32 |
-
|
33 |
-
class ArxivClassificationConfig(datasets.BuilderConfig):
|
34 |
-
"""BuilderConfig for ArxivClassification."""
|
35 |
-
|
36 |
-
def __init__(self, **kwargs):
|
37 |
-
"""BuilderConfig for ArxivClassification.
|
38 |
-
Args:
|
39 |
-
**kwargs: keyword arguments forwarded to super.
|
40 |
-
"""
|
41 |
-
super(ArxivClassificationConfig, self).__init__(**kwargs)
|
42 |
-
|
43 |
-
|
44 |
-
class ArxivClassificationDataset(datasets.GeneratorBasedBuilder):
|
45 |
-
"""ArxivClassification Dataset: classification of Arxiv Papers (11 classes)."""
|
46 |
-
|
47 |
-
_DOWNLOAD_URL = "https://huggingface.co/datasets/ccdv/arxiv-classification/resolve/main/"
|
48 |
-
_TRAIN_FILE = "train_data.txt"
|
49 |
-
_VAL_FILE = "val_data.txt"
|
50 |
-
_TEST_FILE = "test_data.txt"
|
51 |
-
_LABELS_DICT = {label: i for i, label in enumerate(_LABELS)}
|
52 |
-
|
53 |
-
BUILDER_CONFIGS = [
|
54 |
-
ArxivClassificationConfig(
|
55 |
-
name="default",
|
56 |
-
version=datasets.Version("1.0.0"),
|
57 |
-
description="Arxiv Classification Dataset: A classification task of Arxiv Papers (11 classes)",
|
58 |
-
),
|
59 |
-
ArxivClassificationConfig(
|
60 |
-
name="no_ref",
|
61 |
-
version=datasets.Version("1.0.0"),
|
62 |
-
description="Arxiv Classification Dataset: A classification task of Arxiv Papers (11 classes)",
|
63 |
-
),
|
64 |
-
]
|
65 |
-
|
66 |
-
DEFAULT_CONFIG_NAME = "default"
|
67 |
-
|
68 |
-
def _info(self):
|
69 |
-
return datasets.DatasetInfo(
|
70 |
-
description=_DESCRIPTION,
|
71 |
-
features=datasets.Features(
|
72 |
-
{
|
73 |
-
"text": datasets.Value("string"),
|
74 |
-
"label": datasets.features.ClassLabel(names=_LABELS),
|
75 |
-
}
|
76 |
-
),
|
77 |
-
supervised_keys=None,
|
78 |
-
citation=_CITATION,
|
79 |
-
task_templates=[TextClassification(
|
80 |
-
text_column="text", label_column="label")],
|
81 |
-
)
|
82 |
-
|
83 |
-
def _split_generators(self, dl_manager):
|
84 |
-
train_path = dl_manager.download_and_extract(self._TRAIN_FILE)
|
85 |
-
val_path = dl_manager.download_and_extract(self._VAL_FILE)
|
86 |
-
test_path = dl_manager.download_and_extract(self._TEST_FILE)
|
87 |
-
|
88 |
-
return [
|
89 |
-
datasets.SplitGenerator(
|
90 |
-
name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}
|
91 |
-
),
|
92 |
-
datasets.SplitGenerator(
|
93 |
-
name=datasets.Split.VALIDATION, gen_kwargs={"filepath": val_path}
|
94 |
-
),
|
95 |
-
datasets.SplitGenerator(
|
96 |
-
name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}
|
97 |
-
),
|
98 |
-
]
|
99 |
-
|
100 |
-
def _generate_examples(self, filepath):
|
101 |
-
"""Generate ArxivClassification examples."""
|
102 |
-
with open(filepath, encoding="utf-8") as f:
|
103 |
-
for id_, row in enumerate(f):
|
104 |
-
data = json.loads(row)
|
105 |
-
label = self._LABELS_DICT[data["label"]]
|
106 |
-
text = data["text"]
|
107 |
-
|
108 |
-
if self.config.name == "no_ref":
|
109 |
-
for _ in _LABELS:
|
110 |
-
text = text.replace(_, "")
|
111 |
-
|
112 |
-
yield id_, {"text": text, "label": label}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|