Datasets:

Modalities:
Text
Libraries:
Datasets
Jon Gauthier commited on
Commit
2b3c98b
·
1 Parent(s): 3dad049

type hint improvements

Browse files
Files changed (1) hide show
  1. syntaxgym.py +11 -3
syntaxgym.py CHANGED
@@ -10,7 +10,8 @@ from copy import deepcopy
10
  import json
11
  from pathlib import Path
12
  import re
13
- from typing import List, Tuple
 
14
 
15
  import datasets
16
  from datasets import logging
@@ -126,6 +127,11 @@ class SyntaxGym(datasets.GeneratorBasedBuilder):
126
  yield item["item_number"], item
127
 
128
 
 
 
 
 
 
129
  class SyntaxGymMetric(datasets.Metric):
130
  """
131
  SyntaxGym prediction evaluation metric.
@@ -144,7 +150,8 @@ class SyntaxGymMetric(datasets.Metric):
144
  )
145
 
146
  def _compute(self, suite, model_id, batch_size: int = 16,
147
- add_start_token=True, device=None):
 
148
  if device is not None:
149
  assert device in ["gpu", "cpu", "cuda"]
150
  if device == "gpu":
@@ -258,7 +265,8 @@ class SyntaxGymMetric(datasets.Metric):
258
  return ret
259
 
260
  def compute_region_token_mapping(self, item, input_ids: torch.LongTensor,
261
- offset_mapping: List[Tuple[int, int]]):
 
262
  # input_ids: B * T
263
  # offset_mapping: B * T * 2
264
  # assumes batch is sorted according to item's condition_name order
 
10
  import json
11
  from pathlib import Path
12
  import re
13
+ from typing import List, Dict, Tuple
14
+ from typing_extensions import TypedDict
15
 
16
  import datasets
17
  from datasets import logging
 
127
  yield item["item_number"], item
128
 
129
 
130
+ class SyntaxGymMetricResult(TypedDict):
131
+ prediction_results: List[List[bool]]
132
+ region_totals: List[Dict[Tuple[str, int], float]]
133
+
134
+
135
  class SyntaxGymMetric(datasets.Metric):
136
  """
137
  SyntaxGym prediction evaluation metric.
 
150
  )
151
 
152
  def _compute(self, suite, model_id, batch_size: int = 16,
153
+ add_start_token=True, device=None
154
+ ) -> SyntaxGymMetricResult:
155
  if device is not None:
156
  assert device in ["gpu", "cpu", "cuda"]
157
  if device == "gpu":
 
265
  return ret
266
 
267
  def compute_region_token_mapping(self, item, input_ids: torch.LongTensor,
268
+ offset_mapping: List[Tuple[int, int]]
269
+ ) -> Dict[str, Dict[int, List[int]]]:
270
  # input_ids: B * T
271
  # offset_mapping: B * T * 2
272
  # assumes batch is sorted according to item's condition_name order