some changes
Browse files- CoarseWSD-20.py +46 -36
CoarseWSD-20.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
# @title cwsd20 code
|
3 |
import json
|
4 |
import datasets
|
5 |
-
|
6 |
|
7 |
_CITATION = """\
|
8 |
@misc{loureiro2021analysis,
|
@@ -41,47 +41,57 @@ class CWSD20(datasets.GeneratorBasedBuilder):
|
|
41 |
BUILDER_CONFIGS = [datasets.BuilderConfig(name=word, description=_DESCRIPTION) for word in _WORDS]
|
42 |
|
43 |
def _info(self):
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
def _split_generators(self, dl_manager):
|
74 |
"""Returns SplitGenerators."""
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
80 |
|
81 |
return [datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
82 |
-
gen_kwargs={"ex":
|
|
|
|
|
83 |
|
84 |
-
def _generate_examples(self, ex):
|
85 |
"""Yields examples."""
|
86 |
with open(ex, encoding="utf-8") as exf:
|
87 |
for id_, exi in enumerate(exf):
|
|
|
2 |
# @title cwsd20 code
|
3 |
import json
|
4 |
import datasets
|
5 |
+
import os
|
6 |
|
7 |
_CITATION = """\
|
8 |
@misc{loureiro2021analysis,
|
|
|
41 |
BUILDER_CONFIGS = [datasets.BuilderConfig(name=word, description=_DESCRIPTION) for word in _WORDS]
|
42 |
|
43 |
def _info(self):
|
44 |
+
with open(os.path.join("data", self.config.name, "classes_map.txt")) as cmap_f:
|
45 |
+
cmap = json.load(cmap_f)
|
46 |
+
label_classes = [cmap[str(k)] for k in range(len(cmap))]
|
47 |
+
|
48 |
+
# Specifies the datasets.DatasetInfo object
|
49 |
+
return datasets.DatasetInfo(
|
50 |
+
# This is the description that will appear on the datasets page.
|
51 |
+
description=_DESCRIPTION,
|
52 |
+
# datasets.features.FeatureConnectors
|
53 |
+
features=datasets.Features(
|
54 |
+
{
|
55 |
+
"idx": datasets.Value("int32"),
|
56 |
+
"sentence": datasets.Value("string"),
|
57 |
+
"label": datasets.features.ClassLabel(names=label_classes)
|
58 |
+
# datasets.features.ClassLabel(names=self.config.label_classes)
|
59 |
+
# "label": datasets.Value("int32")
|
60 |
+
# "idx": datasets.Value("int32"),
|
61 |
+
# "word": datasets.Value("string"),
|
62 |
+
# "start1": datasets.Value("int32"),
|
63 |
+
# "start2": datasets.Value("int32"),
|
64 |
+
# "end1": datasets.Value("int32"),
|
65 |
+
# "end2": datasets.Value("int32"),
|
66 |
+
# "label": datasets.Value("int32")
|
67 |
+
}
|
68 |
+
),
|
69 |
+
# If there's a common (input, target) tuple from the features,
|
70 |
+
# specify them here. They'll be used if as_supervised=True in
|
71 |
+
# builder.as_dataset.
|
72 |
+
supervised_keys=None,
|
73 |
+
# Homepage of the dataset for documentation
|
74 |
+
homepage="https://github.com/google-research-datasets/boolean-questions",
|
75 |
+
citation=_CITATION,
|
76 |
+
)
|
77 |
|
78 |
def _split_generators(self, dl_manager):
|
79 |
"""Returns SplitGenerators."""
|
80 |
+
train_ex_path = os.path.join("data", self.config.name,
|
81 |
+
"train.data.txt")
|
82 |
+
test_ex_path = os.path.join("data", self.config.name,
|
83 |
+
"test.data.txt")
|
84 |
+
train_lb_path = os.path.join("data", self.config.name,
|
85 |
+
"train.gold.txt")
|
86 |
+
test_lb_path = os.path.join("data", self.config.name,
|
87 |
+
"test.gold.txt")
|
88 |
|
89 |
return [datasets.SplitGenerator(name=datasets.Split.TRAIN,
|
90 |
+
gen_kwargs={"ex": train_ex_path, "lb":train_lb_path }),
|
91 |
+
datasets.SplitGenerator(name=datasets.Split.TEST,
|
92 |
+
gen_kwargs={"ex": test_ex_path, "lb":test_lb_path })]
|
93 |
|
94 |
+
def _generate_examples(self, ex, lb):
|
95 |
"""Yields examples."""
|
96 |
with open(ex, encoding="utf-8") as exf:
|
97 |
for id_, exi in enumerate(exf):
|