kiamehr74 commited on
Commit
8e27a89
·
1 Parent(s): d48a77a

some changes

Browse files
Files changed (1) hide show
  1. 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
- # Specifies the datasets.DatasetInfo object
45
- return datasets.DatasetInfo(
46
- # This is the description that will appear on the datasets page.
47
- description=_DESCRIPTION,
48
- # datasets.features.FeatureConnectors
49
- features=datasets.Features(
50
- {
51
- "idx": datasets.Value("int32"),
52
- "sentence": datasets.Value("string"),
53
- # datasets.features.ClassLabel(names=self.config.label_classes)
54
- # "label": datasets.Value("int32")
55
- # "idx": datasets.Value("int32"),
56
- # "word": datasets.Value("string"),
57
- # "start1": datasets.Value("int32"),
58
- # "start2": datasets.Value("int32"),
59
- # "end1": datasets.Value("int32"),
60
- # "end2": datasets.Value("int32"),
61
- # "label": datasets.Value("int32")
62
- }
63
- ),
64
- # If there's a common (input, target) tuple from the features,
65
- # specify them here. They'll be used if as_supervised=True in
66
- # builder.as_dataset.
67
- supervised_keys=None,
68
- # Homepage of the dataset for documentation
69
- homepage="https://github.com/google-research-datasets/boolean-questions",
70
- citation=_CITATION,
71
- )
 
 
 
 
 
72
 
73
  def _split_generators(self, dl_manager):
74
  """Returns SplitGenerators."""
75
- # TODO(WiCTSV): Downloads the data and defines the splits
76
- # dl_manager is a datasets.download.DownloadManager that can be used to
77
- # download and extract URLs
78
- # urls_to_download = _URLS
79
- dl = path
 
 
 
80
 
81
  return [datasets.SplitGenerator(name=datasets.Split.TRAIN,
82
- gen_kwargs={"ex": dl})]
 
 
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):