Datasets:

Modalities:
Text
Libraries:
Datasets
Jon Gauthier commited on
Commit
452d201
·
1 Parent(s): e019438

extract metric code for SyntaxGym metric space

Browse files
Files changed (3) hide show
  1. prediction.py +0 -235
  2. syntaxgym.py +0 -184
  3. test.py +0 -515
prediction.py DELETED
@@ -1,235 +0,0 @@
1
- from typing import Union, Optional as TOptional, List as TList
2
-
3
-
4
- from pyparsing import *
5
- import numpy as np
6
-
7
- METRICS = {
8
- 'sum': sum,
9
- 'mean': np.mean,
10
- 'median': np.median,
11
- 'range': np.ptp,
12
- 'max': max,
13
- 'min': min
14
- }
15
-
16
-
17
- # Enable parser packrat (caching)
18
- ParserElement.enablePackrat()
19
-
20
- # Relative and absolute tolerance thresholds for surprisal equality
21
- EQUALITY_RTOL = 1e-5
22
- EQUALITY_ATOL = 1e-3
23
-
24
-
25
- #######
26
- # Define a grammar for prediction formulae.
27
-
28
- # References a surprisal region
29
- lpar = Suppress("(")
30
- rpar = Suppress(")")
31
- region = lpar + (Word(nums) | "*") + Suppress(";%") + Word(alphanums + "_-") + Suppress("%") + rpar
32
- literal_float = pyparsing_common.number
33
-
34
- class Region(object):
35
- def __init__(self, tokens):
36
- self.region_number = tokens[0]
37
- self.condition_name = tokens[1]
38
-
39
- def __str__(self):
40
- return "(%s;%%%s%%)" % (self.region_number, self.condition_name)
41
-
42
- def __repr__(self):
43
- return "Region(%s,%s)" % (self.condition_name, self.region_number)
44
-
45
- def __call__(self, surprisal_dict):
46
- if self.region_number == "*":
47
- return sum(value for (condition, region), value in surprisal_dict.items()
48
- if condition == self.condition_name)
49
-
50
- return surprisal_dict[self.condition_name, int(self.region_number)]
51
-
52
- class LiteralFloat(object):
53
- def __init__(self, tokens):
54
- self.value = float(tokens[0])
55
-
56
- def __str__(self):
57
- return "%f" % (self.value,)
58
-
59
- def __repr__(self):
60
- return "LiteralFloat(%f)" % (self.value,)
61
-
62
- def __call__(self, surprisal_dict):
63
- return self.value
64
-
65
- class BinaryOp(object):
66
- operators: TOptional[TList[str]]
67
-
68
- def __init__(self, tokens):
69
- self.operator = tokens[0][1]
70
- if self.operators is not None and self.operator not in self.operators:
71
- raise ValueError("Invalid %s operator %s" % (self.__class__.__name__,
72
- self.operator))
73
- self.operands = [tokens[0][0], tokens[0][2]]
74
-
75
- def __str__(self):
76
- return "(%s %s %s)" % (self.operands[0], self.operator, self.operands[1])
77
-
78
- def __repr__(self):
79
- return "%s(%s)(%s)" % (self.__class__.__name__, self.operator, ",".join(map(repr, self.operands)))
80
-
81
- def __call__(self, surprisal_dict):
82
- op_vals = [op(surprisal_dict) for op in self.operands]
83
- return self._evaluate(op_vals, surprisal_dict)
84
-
85
- def _evaluate(self, evaluated_operands, surprisal_dict):
86
- raise NotImplementedError()
87
-
88
- class BoolOp(BinaryOp):
89
- operators = ["&", "|"]
90
- def _evaluate(self, op_vals, surprisal_dict):
91
- if self.operator == "&":
92
- return op_vals[0] and op_vals[1]
93
- elif self.operator == "|":
94
- return op_vals[0] or op_vals[1]
95
-
96
- class FloatOp(BinaryOp):
97
- operators = ["-", "+"]
98
- def _evaluate(self, op_vals, surprisal_dict):
99
- if self.operator == "-":
100
- return op_vals[0] - op_vals[1]
101
- elif self.operator == "+":
102
- return op_vals[0] + op_vals[1]
103
-
104
- class ComparatorOp(BinaryOp):
105
- operators = ["<", ">", "="]
106
- def _evaluate(self, op_vals, surprisal_dict):
107
- if self.operator == "<":
108
- return op_vals[0] < op_vals[1]
109
- elif self.operator == ">":
110
- return op_vals[0] > op_vals[1]
111
- elif self.operator == "=":
112
- return np.isclose(op_vals[0], op_vals[1],
113
- rtol=EQUALITY_RTOL,
114
- atol=EQUALITY_ATOL)
115
-
116
- def Chain(op_cls, left_assoc=True):
117
- def chainer(tokens):
118
- """
119
- Create a binary tree of BinaryOps from the given repeated application
120
- of the op.
121
- """
122
- operators = tokens[0][1::2]
123
- args = tokens[0][0::2]
124
- if not left_assoc:
125
- raise NotImplementedError
126
-
127
- arg1 = args.pop(0)
128
- while len(args) > 0:
129
- operator = operators.pop(0)
130
- arg2 = args.pop(0)
131
- arg1 = op_cls([[arg1, operator, arg2]])
132
-
133
- return arg1
134
-
135
- return chainer
136
-
137
- atom = region.setParseAction(Region) | literal_float.setParseAction(LiteralFloat)
138
-
139
- prediction_expr = infixNotation(
140
- atom,
141
- [
142
- (oneOf("- +"), 2, opAssoc.LEFT, Chain(FloatOp)),
143
- (oneOf("< > ="), 2, opAssoc.LEFT, ComparatorOp),
144
- (oneOf("& |"), 2, opAssoc.LEFT, Chain(BoolOp)),
145
- ],
146
- lpar=lpar, rpar=rpar
147
- )
148
-
149
-
150
- class Prediction(object):
151
- """
152
- Predictions state expected relations between language model surprisal
153
- measures in different regions and conditions of a test suite. For more
154
- information, see :ref:`architecture`.
155
- """
156
-
157
- def __init__(self, idx: int, formula: Union[str, BinaryOp], metric: str):
158
- """
159
- Args:
160
- idx: A unique prediction ID. This is only relevant for
161
- serialization.
162
- formula: A string representation of the prediction formula, or an
163
- already parsed formula. For more information, see
164
- :ref:`architecture`.
165
- metric: Metric for aggregating surprisals within regions.
166
- """
167
- if isinstance(formula, str):
168
- try:
169
- formula = prediction_expr.parseString(formula, parseAll=True)[0]
170
- except ParseException as e:
171
- raise ValueError("Invalid formula expression %r" % (formula,)) from e
172
-
173
- self.idx = idx
174
- self.formula = formula
175
-
176
- if metric not in METRICS.keys():
177
- raise ValueError("Unknown metric %s. Supported metrics: %s" %
178
- (metric, " ".join(METRICS.keys())))
179
- self.metric = metric
180
-
181
- def __call__(self, item):
182
- """
183
- Evaluate the prediction on the given item dict representation. For more
184
- information on item representations, see :ref:`suite_json`.
185
- """
186
- # Prepare relevant surprisal dict
187
- surps = {(c["condition_name"], r["region_number"]): r["metric_value"][self.metric]
188
- for c in item["conditions"]
189
- for r in c["regions"]}
190
- return self.formula(surps)
191
-
192
- @classmethod
193
- def from_dict(cls, pred_dict, idx: int, metric: str):
194
- """
195
- Parse from a prediction dictionary representation (see
196
- :ref:`suite_json`).
197
- """
198
- if not pred_dict["type"] == "formula":
199
- raise ValueError("Unknown prediction type %s" % (pred_dict["type"],))
200
-
201
- return cls(formula=pred_dict["formula"], idx=idx, metric=metric)
202
-
203
- @property
204
- def referenced_regions(self):
205
- """
206
- Get a set of the regions referenced by this formula.
207
- Each item is a tuple of the form ``(condition_name, region_number)``.
208
- """
209
- def traverse(x, acc):
210
- if isinstance(x, BinaryOp):
211
- for val in x.operands:
212
- traverse(val, acc)
213
- elif isinstance(x, Region):
214
- acc.add((x.condition_name, int(x.region_number)))
215
-
216
- return acc
217
-
218
- return traverse(self.formula, set())
219
-
220
- def as_dict(self):
221
- """
222
- Serialize as a prediction dictionary representation (see
223
- :ref:`suite_json`).
224
- """
225
- return dict(type="formula", formula=str(self.formula))
226
-
227
- def __str__(self):
228
- return "Prediction(%s)" % (self.formula,)
229
- __repr__ = __str__
230
-
231
- def __hash__(self):
232
- return hash(self.formula)
233
-
234
- def __eq__(self, other):
235
- return isinstance(other, Prediction) and hash(self) == hash(other)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
syntaxgym.py CHANGED
@@ -19,8 +19,6 @@ import numpy as np
19
  import torch
20
  from transformers import AutoModelForCausalLM, AutoTokenizer
21
 
22
- from .prediction import Prediction
23
-
24
 
25
  _CITATION = """
26
  @inproceedings{Hu:et-al:2020,
@@ -126,185 +124,3 @@ class SyntaxGym(datasets.GeneratorBasedBuilder):
126
 
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.
138
- """
139
-
140
- def _info(self):
141
- seq = datasets.Sequence
142
- features = datasets.Features({
143
- "suite": SUITE_DATASET_SPEC
144
- })
145
- return datasets.MetricInfo(
146
- description="TODO",
147
- citation=_CITATION,
148
- inputs_description="TODO",
149
- features=features,
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":
158
- device = "cuda"
159
- else:
160
- device = "cuda" if torch.cuda.is_available() else "cpu"
161
-
162
- model = AutoModelForCausalLM.from_pretrained(model_id)
163
- model = model.to(device)
164
- model.eval()
165
-
166
- tokenizer = AutoTokenizer.from_pretrained(model_id)
167
- # TODO copy from perplexity metric
168
- tokenizer.pad_token = tokenizer.eos_token
169
-
170
- results = {"prediction_results": [], "region_totals": []}
171
- # TODO batch all items together
172
- for item in logging.tqdm(suite):
173
- result_single = self._compute_single(item, tokenizer, model, device)
174
-
175
- for k in ["prediction_results", "region_totals"]:
176
- results[k].append(result_single[k])
177
-
178
- return results
179
-
180
-
181
- def _compute_single(self, item, tokenizer, model, device):
182
- tokenized = tokenizer(item["conditions"]["content"],
183
- padding=True,
184
- return_tensors="pt",
185
- return_offsets_mapping=True).to(device)
186
-
187
- # input_ids: B * T
188
- input_ids = tokenized["input_ids"]
189
- assert input_ids.ndim == 2
190
-
191
- # Compute sentence level surprisals.
192
- with torch.no_grad():
193
- # Pre-softmax predictive distribution B * T * V
194
- logits = model(input_ids).logits
195
- surprisals = -logits.log_softmax(dim=2) / np.log(2)
196
-
197
- # surprisals: B * T * V
198
- assert surprisals.ndim == 3
199
-
200
- # Get surprisals of expected words.
201
- surps_shifted = surprisals[:, :-1, :]
202
- expected_ids = input_ids[:, 1:]
203
-
204
- # TODO: check this logic
205
- tt = expected_ids.unsqueeze(2)
206
- # reindexed surprisals: B * (T - 1)
207
- surprisals = torch.gather(surps_shifted, 2, expected_ids.unsqueeze(2)) \
208
- .squeeze(2)
209
- # This is the original, which works but not with multiple axes in expected_ids
210
- # surprisals = surps_shifted[range(surps_shifted.shape[0]), expected_ids]
211
-
212
- # surprisals is now B * (T - 1)
213
-
214
- #### aggregate
215
- condition_names = item["conditions"]["condition_name"]
216
- region_totals = {condition_name: defaultdict(float)
217
- for condition_name in condition_names}
218
- region2tokens = self.compute_region_token_mapping(
219
- item, input_ids, tokenized["offset_mapping"])
220
-
221
- for i, (i_cond, i_inputs) in enumerate(zip(condition_names, input_ids)):
222
- for region_number, region_tokens in region2tokens[i_cond].items():
223
- for token in region_tokens:
224
- if token == 0:
225
- # surprisal not defined. pass.
226
- continue
227
- elif token <= surprisals.shape[1]:
228
- region_totals[i_cond][region_number] += surprisals[i, token - 1]
229
- else:
230
- # TODO don't think this is an issue, just should clean
231
- # up the aggregation output
232
- assert token == surprisals.shape[1], \
233
- "%s %s" % (token, surprisals.shape[1])
234
-
235
- region_totals = {(condition_name, region_number): float(total)
236
- for condition_name, totals in region_totals.items()
237
- for region_number, total in totals.items()}
238
-
239
- results = {
240
- "prediction_results": [
241
- Prediction(i, formula, "sum").formula(region_totals)
242
- for i, formula in enumerate(item["predictions"])
243
- ],
244
-
245
- "region_totals": region_totals
246
- }
247
- return results
248
-
249
- def get_region_edges(self, item, condition_idx):
250
- """
251
- Get left edge of each region as a character index.
252
- """
253
- # NB this is coupled with `condition_to_string` logic of course
254
-
255
- regions = item["conditions"]["regions"][condition_idx]
256
-
257
- idx = 0
258
- ret = []
259
- for r_idx, region_content in enumerate(regions["content"]):
260
- ret.append(idx)
261
-
262
- region_size = len(region_content)
263
- if region_content.strip() != "" and r_idx != 0 and not region_content.startswith(","):
264
- # Add joining space
265
- region_size += 1
266
-
267
- idx += region_size
268
-
269
- return ret
270
-
271
- def compute_region_token_mapping(self, item, input_ids: torch.LongTensor,
272
- offset_mapping: List[Tuple[int, int]]
273
- ) -> Dict[str, Dict[int, List[int]]]:
274
- # input_ids: B * T
275
- # offset_mapping: B * T * 2
276
- # assumes batch is sorted according to item's condition_name order
277
-
278
- condition_names = item["conditions"]["condition_name"]
279
- region2tokens = {cond: defaultdict(list) for cond in condition_names}
280
-
281
- max_long = torch.iinfo(torch.int64).max
282
-
283
- input_ids = input_ids.detach()
284
- for i_cond, (i_tokens, i_offsets) in enumerate(zip(input_ids, offset_mapping)):
285
- region_edges = self.get_region_edges(item, i_cond)
286
-
287
- t_cursor, r_cursor = 0, 0
288
- while t_cursor < i_tokens.shape[0]:
289
- # token = i_tokens[t_cursor]
290
- token_char_start, token_char_end = i_offsets[t_cursor]
291
-
292
- if token_char_start == token_char_end == 0:
293
- # This is a padding token. Skip.
294
- # TODO what about BOS/EOS? some models incorporate them
295
- t_cursor += 1
296
- continue
297
-
298
- region_start = region_edges[r_cursor]
299
- region_end = region_edges[r_cursor + 1] \
300
- if r_cursor + 1 < len(region_edges) else max_long
301
-
302
- # NB region boundaries are left edges, hence the >= here.
303
- if token_char_start >= region_end:
304
- r_cursor += 1
305
- continue
306
-
307
- region2tokens[condition_names[i_cond]][r_cursor + 1].append(t_cursor)
308
- t_cursor += 1
309
-
310
- return region2tokens
 
19
  import torch
20
  from transformers import AutoModelForCausalLM, AutoTokenizer
21
 
 
 
22
 
23
  _CITATION = """
24
  @inproceedings{Hu:et-al:2020,
 
124
 
125
  yield item["item_number"], item
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test.py DELETED
@@ -1,515 +0,0 @@
1
- from typing import List
2
-
3
- import datasets
4
- import numpy as np
5
-
6
- import pytest
7
-
8
-
9
- @pytest.fixture(scope="session")
10
- def syntaxgym_dataset():
11
- return datasets.load_dataset("syntaxgym", "subordination_src-src")
12
-
13
-
14
- @pytest.fixture(scope="session")
15
- def syntaxgym_metric():
16
- return datasets.load_metric("syntaxgym")
17
-
18
-
19
- @pytest.fixture(scope="session")
20
- def model_ref():
21
- # return "hf-internal-testing/tiny-random-gpt_neo"
22
- return "gpt2"
23
-
24
-
25
- # Reference region surprisals computed with syntaxgym-core.
26
- # See notebook in https://colab.research.google.com/drive/1qziyPcu65jffizSPi-ZGHKR0x7BaHFMS#scrollTo=RgtnScy6LLKi .
27
- GPT2_SUBORDINATION_SRC_REFERENCE = \
28
- [{('no-sub_matrix', 1): 13.151199615123803,
29
- ('no-sub_matrix', 2): 38.503222716703526,
30
- ('no-sub_matrix', 3): 27.623861034812286,
31
- ('no-sub_matrix', 4): 48.831672846038224,
32
- ('no-sub_matrix', 5): 38.08533699286694,
33
- ('no-sub_no-matrix', 1): 13.151199615123803,
34
- ('no-sub_no-matrix', 2): 38.503222716703526,
35
- ('no-sub_no-matrix', 3): 27.623861034812286,
36
- ('no-sub_no-matrix', 4): 48.831687980511504,
37
- ('no-sub_no-matrix', 5): 1.8096143510772873,
38
- ('sub_matrix', 1): 14.905592916748805,
39
- ('sub_matrix', 2): 39.06304309956175,
40
- ('sub_matrix', 3): 26.862648365854433,
41
- ('sub_matrix', 4): 50.56554401687938,
42
- ('sub_matrix', 5): 26.532245572980194,
43
- ('sub_no-matrix', 1): 14.905592916748805,
44
- ('sub_no-matrix', 2): 39.06304309956175,
45
- ('sub_no-matrix', 3): 26.862648365854433,
46
- ('sub_no-matrix', 4): 50.56553438585093,
47
- ('sub_no-matrix', 5): 7.470089829866611},
48
- {('no-sub_matrix', 1): 10.116093820255577,
49
- ('no-sub_matrix', 2): 20.96513246705127,
50
- ('no-sub_matrix', 3): 20.02959138986416,
51
- ('no-sub_matrix', 4): 23.779661397107446,
52
- ('no-sub_matrix', 5): 33.2560281692696,
53
- ('no-sub_no-matrix', 1): 10.116093820255577,
54
- ('no-sub_no-matrix', 2): 20.96513246705127,
55
- ('no-sub_no-matrix', 3): 20.02959138986416,
56
- ('no-sub_no-matrix', 4): 23.779661397107446,
57
- ('no-sub_no-matrix', 5): 1.9449125865631063,
58
- ('sub_matrix', 1): 13.545157521732826,
59
- ('sub_matrix', 2): 24.96048395897244,
60
- ('sub_matrix', 3): 18.609464944317324,
61
- ('sub_matrix', 4): 23.057566440062317,
62
- ('sub_matrix', 5): 26.424454285669032,
63
- ('sub_no-matrix', 1): 13.545157521732826,
64
- ('sub_no-matrix', 2): 24.96048395897244,
65
- ('sub_no-matrix', 3): 18.609464944317324,
66
- ('sub_no-matrix', 4): 23.057566440062317,
67
- ('sub_no-matrix', 5): 2.807467838359704},
68
- {('no-sub_matrix', 1): 11.992867568477442,
69
- ('no-sub_matrix', 2): 45.813114232935774,
70
- ('no-sub_matrix', 3): 24.57554828372551,
71
- ('no-sub_matrix', 4): 45.334025774062916,
72
- ('no-sub_matrix', 5): 26.208189541862073,
73
- ('no-sub_no-matrix', 1): 11.992867568477442,
74
- ('no-sub_no-matrix', 2): 45.813114232935774,
75
- ('no-sub_no-matrix', 3): 24.57554828372551,
76
- ('no-sub_no-matrix', 4): 45.33402766587207,
77
- ('no-sub_no-matrix', 5): 1.8284485151385752,
78
- ('sub_matrix', 1): 14.219887768799735,
79
- ('sub_matrix', 2): 46.25055434117979,
80
- ('sub_matrix', 3): 23.054221678472672,
81
- ('sub_matrix', 4): 47.08503858470256,
82
- ('sub_matrix', 5): 22.154772321452022,
83
- ('sub_no-matrix', 1): 14.219887768799735,
84
- ('sub_no-matrix', 2): 46.25055434117979,
85
- ('sub_no-matrix', 3): 23.054221678472672,
86
- ('sub_no-matrix', 4): 47.08503858470256,
87
- ('sub_no-matrix', 5): 3.0655133594366757},
88
- {('no-sub_matrix', 1): 10.55002943802296,
89
- ('no-sub_matrix', 2): 52.419810137608856,
90
- ('no-sub_matrix', 3): 23.30710475332303,
91
- ('no-sub_matrix', 4): 37.957905964008944,
92
- ('no-sub_matrix', 5): 29.259648135104936,
93
- ('no-sub_no-matrix', 1): 10.55002943802296,
94
- ('no-sub_no-matrix', 2): 52.419810137608856,
95
- ('no-sub_no-matrix', 3): 23.30710475332303,
96
- ('no-sub_no-matrix', 4): 37.957905964008944,
97
- ('no-sub_no-matrix', 5): 1.9632913405649093,
98
- ('sub_matrix', 1): 15.289384584900025,
99
- ('sub_matrix', 2): 53.93652737134243,
100
- ('sub_matrix', 3): 19.43915835312633,
101
- ('sub_matrix', 4): 36.459591551099386,
102
- ('sub_matrix', 5): 22.185742699245417,
103
- ('sub_no-matrix', 1): 15.289384584900025,
104
- ('sub_no-matrix', 2): 53.93652737134243,
105
- ('sub_no-matrix', 3): 19.43915835312633,
106
- ('sub_no-matrix', 4): 36.4595598203003,
107
- ('sub_no-matrix', 5): 5.707732355645454},
108
- {('no-sub_matrix', 1): 23.543723213902986,
109
- ('no-sub_matrix', 2): 31.967972102825854,
110
- ('no-sub_matrix', 3): 29.159572978411727,
111
- ('no-sub_matrix', 4): 36.61365345925747,
112
- ('no-sub_matrix', 5): 44.576591305970545,
113
- ('no-sub_no-matrix', 1): 23.543723213902986,
114
- ('no-sub_no-matrix', 2): 31.967972102825854,
115
- ('no-sub_no-matrix', 3): 29.159572978411727,
116
- ('no-sub_no-matrix', 4): 36.61365345925747,
117
- ('no-sub_no-matrix', 5): 3.2813457388593714,
118
- ('sub_matrix', 1): 27.118410129310597,
119
- ('sub_matrix', 2): 33.909617362987866,
120
- ('sub_matrix', 3): 28.791166362258743,
121
- ('sub_matrix', 4): 37.24960609010374,
122
- ('sub_matrix', 5): 31.660933798006262,
123
- ('sub_no-matrix', 1): 27.118410129310597,
124
- ('sub_no-matrix', 2): 33.909617362987866,
125
- ('sub_no-matrix', 3): 28.791166362258743,
126
- ('sub_no-matrix', 4): 37.24960609010374,
127
- ('sub_no-matrix', 5): 7.3613541428239015},
128
- {('no-sub_matrix', 1): 14.22171869610082,
129
- ('no-sub_matrix', 2): 30.270423022911977,
130
- ('no-sub_matrix', 3): 25.973276891204705,
131
- ('no-sub_matrix', 4): 28.43856735947716,
132
- ('no-sub_matrix', 5): 57.39887418731055,
133
- ('no-sub_no-matrix', 1): 14.22171869610082,
134
- ('no-sub_no-matrix', 2): 30.270423022911977,
135
- ('no-sub_no-matrix', 3): 25.973276891204705,
136
- ('no-sub_no-matrix', 4): 28.43856735947716,
137
- ('no-sub_no-matrix', 5): 1.7127059109344136,
138
- ('sub_matrix', 1): 16.39289784951447,
139
- ('sub_matrix', 2): 31.5671111565765,
140
- ('sub_matrix', 3): 24.54307828171008,
141
- ('sub_matrix', 4): 29.249645624130757,
142
- ('sub_matrix', 5): 53.59155769093577,
143
- ('sub_no-matrix', 1): 16.39289784951447,
144
- ('sub_no-matrix', 2): 31.5671111565765,
145
- ('sub_no-matrix', 3): 24.54307828171008,
146
- ('sub_no-matrix', 4): 29.249645624130757,
147
- ('sub_no-matrix', 5): 7.225276653947023},
148
- {('no-sub_matrix', 1): 13.729688714733188,
149
- ('no-sub_matrix', 2): 36.018118127225165,
150
- ('no-sub_matrix', 3): 28.232055923783275,
151
- ('no-sub_matrix', 4): 44.44634394296659,
152
- ('no-sub_matrix', 5): 38.277975147059344,
153
- ('no-sub_no-matrix', 1): 13.729688714733188,
154
- ('no-sub_no-matrix', 2): 36.018118127225165,
155
- ('no-sub_no-matrix', 3): 28.232055923783275,
156
- ('no-sub_no-matrix', 4): 44.44634394296659,
157
- ('no-sub_no-matrix', 5): 3.0318996942908414,
158
- ('sub_matrix', 1): 16.93528744674245,
159
- ('sub_matrix', 2): 36.545024814326574,
160
- ('sub_matrix', 3): 26.279603445823692,
161
- ('sub_matrix', 4): 46.501226364074995,
162
- ('sub_matrix', 5): 32.155418057793035,
163
- ('sub_no-matrix', 1): 16.93528744674245,
164
- ('sub_no-matrix', 2): 36.545024814326574,
165
- ('sub_no-matrix', 3): 26.279603445823692,
166
- ('sub_no-matrix', 4): 46.501226364074995,
167
- ('sub_no-matrix', 5): 4.4581122618864155},
168
- {('no-sub_matrix', 1): 15.598113737151568,
169
- ('no-sub_matrix', 2): 56.12543415244172,
170
- ('no-sub_matrix', 3): 29.755667770007285,
171
- ('no-sub_matrix', 4): 51.689282097269995,
172
- ('no-sub_matrix', 5): 45.575230324010775,
173
- ('no-sub_no-matrix', 1): 15.598113737151568,
174
- ('no-sub_no-matrix', 2): 56.12543415244172,
175
- ('no-sub_no-matrix', 3): 29.755667770007285,
176
- ('no-sub_no-matrix', 4): 51.68928424705313,
177
- ('no-sub_no-matrix', 5): 1.235207173694806,
178
- ('sub_matrix', 1): 18.909088991066888,
179
- ('sub_matrix', 2): 57.753410746636746,
180
- ('sub_matrix', 3): 28.677667873674363,
181
- ('sub_matrix', 4): 51.99410775929489,
182
- ('sub_matrix', 5): 35.754144966112236,
183
- ('sub_no-matrix', 1): 18.909088991066888,
184
- ('sub_no-matrix', 2): 57.753410746636746,
185
- ('sub_no-matrix', 3): 28.677667873674363,
186
- ('sub_no-matrix', 4): 51.9941480032352,
187
- ('sub_no-matrix', 5): 5.033266273930268},
188
- {('no-sub_matrix', 1): 14.859413855165633,
189
- ('no-sub_matrix', 2): 34.54519231993284,
190
- ('no-sub_matrix', 3): 24.26528519671309,
191
- ('no-sub_matrix', 4): 35.42343514121054,
192
- ('no-sub_matrix', 5): 55.85308623165151,
193
- ('no-sub_no-matrix', 1): 14.859413855165633,
194
- ('no-sub_no-matrix', 2): 34.54519231993284,
195
- ('no-sub_no-matrix', 3): 24.26528519671309,
196
- ('no-sub_no-matrix', 4): 35.42343514121054,
197
- ('no-sub_no-matrix', 5): 2.3309861205259734,
198
- ('sub_matrix', 1): 17.053809634549854,
199
- ('sub_matrix', 2): 33.66637542056656,
200
- ('sub_matrix', 3): 23.26181234829638,
201
- ('sub_matrix', 4): 35.61438567264568,
202
- ('sub_matrix', 5): 48.48551986050014,
203
- ('sub_no-matrix', 1): 17.053809634549854,
204
- ('sub_no-matrix', 2): 33.66637542056656,
205
- ('sub_no-matrix', 3): 23.26181234829638,
206
- ('sub_no-matrix', 4): 35.61438704850689,
207
- ('sub_no-matrix', 5): 2.969309360231736},
208
- {('no-sub_matrix', 1): 13.708973748402064,
209
- ('no-sub_matrix', 2): 31.147590264691182,
210
- ('no-sub_matrix', 3): 30.495597241955565,
211
- ('no-sub_matrix', 4): 34.65164493728535,
212
- ('no-sub_matrix', 5): 35.87510990950117,
213
- ('no-sub_no-matrix', 1): 13.708973748402064,
214
- ('no-sub_no-matrix', 2): 31.147590264691182,
215
- ('no-sub_no-matrix', 3): 30.495597241955565,
216
- ('no-sub_no-matrix', 4): 34.65164493728535,
217
- ('no-sub_no-matrix', 5): 3.232032121481573,
218
- ('sub_matrix', 1): 17.681722076468287,
219
- ('sub_matrix', 2): 33.77225997922327,
220
- ('sub_matrix', 3): 29.435808932487806,
221
- ('sub_matrix', 4): 34.354368969668016,
222
- ('sub_matrix', 5): 20.802733205442486,
223
- ('sub_no-matrix', 1): 17.681722076468287,
224
- ('sub_no-matrix', 2): 33.77225997922327,
225
- ('sub_no-matrix', 3): 29.435808932487806,
226
- ('sub_no-matrix', 4): 34.354368969668016,
227
- ('sub_no-matrix', 5): 3.7902066303710424},
228
- {('no-sub_matrix', 1): 15.72185319065555,
229
- ('no-sub_matrix', 2): 45.25539814380218,
230
- ('no-sub_matrix', 3): 24.94273362957689,
231
- ('no-sub_matrix', 4): 40.81704901026569,
232
- ('no-sub_matrix', 5): 42.898794519499596,
233
- ('no-sub_no-matrix', 1): 15.72185319065555,
234
- ('no-sub_no-matrix', 2): 45.25539814380218,
235
- ('no-sub_no-matrix', 3): 24.94273362957689,
236
- ('no-sub_no-matrix', 4): 40.81704901026569,
237
- ('no-sub_no-matrix', 5): 2.6826901255924644,
238
- ('sub_matrix', 1): 17.565795106862403,
239
- ('sub_matrix', 2): 46.9371803702329,
240
- ('sub_matrix', 3): 23.887805807796486,
241
- ('sub_matrix', 4): 39.058599411828766,
242
- ('sub_matrix', 5): 32.234453544910295,
243
- ('sub_no-matrix', 1): 17.565795106862403,
244
- ('sub_no-matrix', 2): 46.9371803702329,
245
- ('sub_no-matrix', 3): 23.887805807796486,
246
- ('sub_no-matrix', 4): 39.058599411828766,
247
- ('sub_no-matrix', 5): 4.214674259243127},
248
- {('no-sub_matrix', 1): 13.910878628792588,
249
- ('no-sub_matrix', 2): 33.45626834359109,
250
- ('no-sub_matrix', 3): 16.127584513594687,
251
- ('no-sub_matrix', 4): 32.59623120264939,
252
- ('no-sub_matrix', 5): 29.87568851789407,
253
- ('no-sub_no-matrix', 1): 13.910878628792588,
254
- ('no-sub_no-matrix', 2): 33.45626834359109,
255
- ('no-sub_no-matrix', 3): 16.127584513594687,
256
- ('no-sub_no-matrix', 4): 32.59623120264939,
257
- ('no-sub_no-matrix', 5): 2.3891779982892625,
258
- ('sub_matrix', 1): 17.18981661053988,
259
- ('sub_matrix', 2): 36.38883326650068,
260
- ('sub_matrix', 3): 13.081088737716442,
261
- ('sub_matrix', 4): 33.419732612590224,
262
- ('sub_matrix', 5): 22.665485632721676,
263
- ('sub_no-matrix', 1): 17.18981661053988,
264
- ('sub_no-matrix', 2): 36.38883326650068,
265
- ('sub_no-matrix', 3): 13.081088737716442,
266
- ('sub_no-matrix', 4): 33.419732612590224,
267
- ('sub_no-matrix', 5): 6.155199912348024},
268
- {('no-sub_matrix', 1): 18.196771699177763,
269
- ('no-sub_matrix', 2): 35.624058750852136,
270
- ('no-sub_matrix', 3): 23.746554392851053,
271
- ('no-sub_matrix', 4): 29.44669921790574,
272
- ('no-sub_matrix', 5): 39.72412918901379,
273
- ('no-sub_no-matrix', 1): 18.196771699177763,
274
- ('no-sub_no-matrix', 2): 35.624058750852136,
275
- ('no-sub_no-matrix', 3): 23.746554392851053,
276
- ('no-sub_no-matrix', 4): 29.44669921790574,
277
- ('no-sub_no-matrix', 5): 2.870123353843486,
278
- ('sub_matrix', 1): 20.38619930823735,
279
- ('sub_matrix', 2): 36.29781144853154,
280
- ('sub_matrix', 3): 22.13637404741934,
281
- ('sub_matrix', 4): 29.68729899086184,
282
- ('sub_matrix', 5): 36.993790238103884,
283
- ('sub_no-matrix', 1): 20.38619930823735,
284
- ('sub_no-matrix', 2): 36.29781144853154,
285
- ('sub_no-matrix', 3): 22.13637404741934,
286
- ('sub_no-matrix', 4): 29.68729899086184,
287
- ('sub_no-matrix', 5): 7.650303570399713},
288
- {('no-sub_matrix', 1): 11.992867568477442,
289
- ('no-sub_matrix', 2): 26.44083030170154,
290
- ('no-sub_matrix', 3): 27.574921221726136,
291
- ('no-sub_matrix', 4): 28.94213565689118,
292
- ('no-sub_matrix', 5): 46.973469397495556,
293
- ('no-sub_no-matrix', 1): 11.992867568477442,
294
- ('no-sub_no-matrix', 2): 26.44083030170154,
295
- ('no-sub_no-matrix', 3): 27.574921221726136,
296
- ('no-sub_no-matrix', 4): 28.94213565689118,
297
- ('no-sub_no-matrix', 5): 3.354326576753004,
298
- ('sub_matrix', 1): 14.434047100994839,
299
- ('sub_matrix', 2): 26.76571524620116,
300
- ('sub_matrix', 3): 25.83488399989926,
301
- ('sub_matrix', 4): 30.263621195061678,
302
- ('sub_matrix', 5): 36.822532494114455,
303
- ('sub_no-matrix', 1): 14.434047100994839,
304
- ('sub_no-matrix', 2): 26.76571524620116,
305
- ('sub_no-matrix', 3): 25.83488399989926,
306
- ('sub_no-matrix', 4): 30.263621195061678,
307
- ('sub_no-matrix', 5): 6.748976893757906},
308
- {('no-sub_matrix', 1): 16.27614914680276,
309
- ('no-sub_matrix', 2): 41.35282905624703,
310
- ('no-sub_matrix', 3): 25.173115913245226,
311
- ('no-sub_matrix', 4): 52.876981987369014,
312
- ('no-sub_matrix', 5): 49.49767321075167,
313
- ('no-sub_no-matrix', 1): 16.27614914680276,
314
- ('no-sub_no-matrix', 2): 41.35282905624703,
315
- ('no-sub_no-matrix', 3): 25.173115913245226,
316
- ('no-sub_no-matrix', 4): 52.876981987369014,
317
- ('no-sub_no-matrix', 5): 1.5962803636236758,
318
- ('sub_matrix', 1): 18.735912436641787,
319
- ('sub_matrix', 2): 43.36213985849511,
320
- ('sub_matrix', 3): 24.582800598631913,
321
- ('sub_matrix', 4): 53.1616607417586,
322
- ('sub_matrix', 5): 41.2664433745972,
323
- ('sub_no-matrix', 1): 18.735912436641787,
324
- ('sub_no-matrix', 2): 43.36213985849511,
325
- ('sub_no-matrix', 3): 24.582800598631913,
326
- ('sub_no-matrix', 4): 53.16165799003619,
327
- ('sub_no-matrix', 5): 6.4917878462822305},
328
- {('no-sub_matrix', 1): 14.036280122634507,
329
- ('no-sub_matrix', 2): 53.72802368862095,
330
- ('no-sub_matrix', 3): 18.940766131564004,
331
- ('no-sub_matrix', 4): 40.74964840745327,
332
- ('no-sub_matrix', 5): 39.57008490907742,
333
- ('no-sub_no-matrix', 1): 14.036280122634507,
334
- ('no-sub_no-matrix', 2): 53.72802368862095,
335
- ('no-sub_no-matrix', 3): 18.940766131564004,
336
- ('no-sub_no-matrix', 4): 40.74964840745327,
337
- ('no-sub_no-matrix', 5): 2.1275557540222967,
338
- ('sub_matrix', 1): 19.641722357026286,
339
- ('sub_matrix', 2): 52.709120728751486,
340
- ('sub_matrix', 3): 17.976257844509426,
341
- ('sub_matrix', 4): 42.51851542500959,
342
- ('sub_matrix', 5): 28.25018664655579,
343
- ('sub_no-matrix', 1): 19.641722357026286,
344
- ('sub_no-matrix', 2): 52.709120728751486,
345
- ('sub_no-matrix', 3): 17.976257844509426,
346
- ('sub_no-matrix', 4): 42.51851267328718,
347
- ('sub_no-matrix', 5): 5.409622788119386},
348
- {('no-sub_matrix', 1): 16.961927903326398,
349
- ('no-sub_matrix', 2): 38.5455951142925,
350
- ('no-sub_matrix', 3): 25.122316709729276,
351
- ('no-sub_matrix', 4): 35.90131439006518,
352
- ('no-sub_matrix', 5): 41.65886977570029,
353
- ('no-sub_no-matrix', 1): 16.961927903326398,
354
- ('no-sub_no-matrix', 2): 38.5455951142925,
355
- ('no-sub_no-matrix', 3): 25.122316709729276,
356
- ('no-sub_no-matrix', 4): 35.90131439006518,
357
- ('no-sub_no-matrix', 5): 3.2679255886472447,
358
- ('sub_matrix', 1): 20.247934372024154,
359
- ('sub_matrix', 2): 40.408716019775625,
360
- ('sub_matrix', 3): 23.782735071043668,
361
- ('sub_matrix', 4): 37.00513584758997,
362
- ('sub_matrix', 5): 29.22700479607527,
363
- ('sub_no-matrix', 1): 20.247934372024154,
364
- ('sub_no-matrix', 2): 40.408716019775625,
365
- ('sub_no-matrix', 3): 23.782735071043668,
366
- ('sub_no-matrix', 4): 37.00513584758997,
367
- ('sub_no-matrix', 5): 4.780011845541033},
368
- {('no-sub_matrix', 1): 12.109815771064152,
369
- ('no-sub_matrix', 2): 38.32406752938649,
370
- ('no-sub_matrix', 3): 25.987801084044044,
371
- ('no-sub_matrix', 4): 40.40950903177875,
372
- ('no-sub_matrix', 5): 52.86522525335603,
373
- ('no-sub_no-matrix', 1): 12.109815771064152,
374
- ('no-sub_no-matrix', 2): 38.32406752938649,
375
- ('no-sub_no-matrix', 3): 25.987801084044044,
376
- ('no-sub_no-matrix', 4): 40.40950903177875,
377
- ('no-sub_no-matrix', 5): 3.61917194787979,
378
- ('sub_matrix', 1): 15.130341564722832,
379
- ('sub_matrix', 2): 37.89719334728088,
380
- ('sub_matrix', 3): 24.65681032273433,
381
- ('sub_matrix', 4): 40.731610867030774,
382
- ('sub_matrix', 5): 37.566910985257906,
383
- ('sub_no-matrix', 1): 15.130341564722832,
384
- ('sub_no-matrix', 2): 37.89719334728088,
385
- ('sub_no-matrix', 3): 24.65681032273433,
386
- ('sub_no-matrix', 4): 40.731610867030774,
387
- ('sub_no-matrix', 5): 9.39736249989602},
388
- {('no-sub_matrix', 1): 16.25058564557851,
389
- ('no-sub_matrix', 2): 37.20405682898803,
390
- ('no-sub_matrix', 3): 30.5107090995129,
391
- ('no-sub_matrix', 4): 44.537084655292894,
392
- ('no-sub_matrix', 5): 46.50046620075818,
393
- ('no-sub_no-matrix', 1): 16.25058564557851,
394
- ('no-sub_no-matrix', 2): 37.20405682898803,
395
- ('no-sub_no-matrix', 3): 30.5107090995129,
396
- ('no-sub_no-matrix', 4): 44.537084655292894,
397
- ('no-sub_no-matrix', 5): 1.8752506698658238,
398
- ('sub_matrix', 1): 18.440281483079957,
399
- ('sub_matrix', 2): 38.54769605435544,
400
- ('sub_matrix', 3): 30.510800250317864,
401
- ('sub_matrix', 4): 44.99740645329493,
402
- ('sub_matrix', 5): 39.55738177603457,
403
- ('sub_no-matrix', 1): 18.440281483079957,
404
- ('sub_no-matrix', 2): 38.54769605435544,
405
- ('sub_no-matrix', 3): 30.510800250317864,
406
- ('sub_no-matrix', 4): 44.99740645329493,
407
- ('sub_no-matrix', 5): 2.6233048602148386},
408
- {('no-sub_matrix', 1): 16.324447378609865,
409
- ('no-sub_matrix', 2): 30.87308462806543,
410
- ('no-sub_matrix', 3): 22.765564836381643,
411
- ('no-sub_matrix', 4): 38.337445027901204,
412
- ('no-sub_matrix', 5): 40.98815076599078,
413
- ('no-sub_no-matrix', 1): 16.324447378609865,
414
- ('no-sub_no-matrix', 2): 30.87308462806543,
415
- ('no-sub_no-matrix', 3): 22.765564836381643,
416
- ('no-sub_no-matrix', 4): 38.337445027901204,
417
- ('no-sub_no-matrix', 5): 1.4796406979126138,
418
- ('sub_matrix', 1): 17.9623592385626,
419
- ('sub_matrix', 2): 32.36568198294609,
420
- ('sub_matrix', 3): 22.438215466486483,
421
- ('sub_matrix', 4): 40.900713840387546,
422
- ('sub_matrix', 5): 33.396627340011634,
423
- ('sub_no-matrix', 1): 17.9623592385626,
424
- ('sub_no-matrix', 2): 32.36568198294609,
425
- ('sub_no-matrix', 3): 22.438215466486483,
426
- ('sub_no-matrix', 4): 40.900713840387546,
427
- ('sub_no-matrix', 5): 6.609518913895668},
428
- {('no-sub_matrix', 1): 14.033258731424148,
429
- ('no-sub_matrix', 2): 28.37206528002418,
430
- ('no-sub_matrix', 3): 27.043658386061033,
431
- ('no-sub_matrix', 4): 36.167049513436204,
432
- ('no-sub_matrix', 5): 52.280797076864395,
433
- ('no-sub_no-matrix', 1): 14.033258731424148,
434
- ('no-sub_no-matrix', 2): 28.37206528002418,
435
- ('no-sub_no-matrix', 3): 27.043658386061033,
436
- ('no-sub_no-matrix', 4): 36.167049513436204,
437
- ('no-sub_no-matrix', 5): 1.9358795417918389,
438
- ('sub_matrix', 1): 16.606623097498794,
439
- ('sub_matrix', 2): 29.98729916366884,
440
- ('sub_matrix', 3): 24.737985875967603,
441
- ('sub_matrix', 4): 34.93154214402433,
442
- ('sub_matrix', 5): 42.35241303296243,
443
- ('sub_no-matrix', 1): 16.606623097498794,
444
- ('sub_no-matrix', 2): 29.98729916366884,
445
- ('sub_no-matrix', 3): 24.737985875967603,
446
- ('sub_no-matrix', 4): 34.931551775052775,
447
- ('sub_no-matrix', 5): 7.151971456773863},
448
- {('no-sub_matrix', 1): 10.482293039084738,
449
- ('no-sub_matrix', 2): 52.67861788579445,
450
- ('no-sub_matrix', 3): 21.665543335527666,
451
- ('no-sub_matrix', 4): 23.53727708917033,
452
- ('no-sub_matrix', 5): 32.2645584918966,
453
- ('no-sub_no-matrix', 1): 10.482293039084738,
454
- ('no-sub_no-matrix', 2): 52.67861788579445,
455
- ('no-sub_no-matrix', 3): 21.665543335527666,
456
- ('no-sub_no-matrix', 4): 23.53727708917033,
457
- ('no-sub_no-matrix', 5): 2.5207572809328243,
458
- ('sub_matrix', 1): 11.523882918360123,
459
- ('sub_matrix', 2): 57.336257883871156,
460
- ('sub_matrix', 3): 21.647716645835132,
461
- ('sub_matrix', 4): 23.491483569694733,
462
- ('sub_matrix', 5): 24.264706351480406,
463
- ('sub_no-matrix', 1): 11.523882918360123,
464
- ('sub_no-matrix', 2): 57.336257883871156,
465
- ('sub_no-matrix', 3): 21.647716645835132,
466
- ('sub_no-matrix', 4): 23.491462243846026,
467
- ('sub_no-matrix', 5): 9.714244661694366},
468
- {('no-sub_matrix', 1): 11.992867568477442,
469
- ('no-sub_matrix', 2): 28.861638231250264,
470
- ('no-sub_matrix', 3): 24.222607873884137,
471
- ('no-sub_matrix', 4): 41.28280460012173,
472
- ('no-sub_matrix', 5): 56.6084264455065,
473
- ('no-sub_no-matrix', 1): 11.992867568477442,
474
- ('no-sub_no-matrix', 2): 28.861638231250264,
475
- ('no-sub_no-matrix', 3): 24.222607873884137,
476
- ('no-sub_no-matrix', 4): 41.28280460012173,
477
- ('no-sub_no-matrix', 5): 2.4980576348107437,
478
- ('sub_matrix', 1): 14.531057698832324,
479
- ('sub_matrix', 2): 31.280393934821902,
480
- ('sub_matrix', 3): 20.756528260470358,
481
- ('sub_matrix', 4): 42.15937712589425,
482
- ('sub_matrix', 5): 52.45767194621365,
483
- ('sub_no-matrix', 1): 14.531057698832324,
484
- ('sub_no-matrix', 2): 31.280393934821902,
485
- ('sub_no-matrix', 3): 20.756528260470358,
486
- ('sub_no-matrix', 4): 42.15937712589425,
487
- ('sub_no-matrix', 5): 4.819862633503057}]
488
-
489
-
490
- def test_gpt_subordination_region_totals():
491
- """
492
- Check region-level surprisals against the original syntaxgym-core
493
- implementation, using the same underlying `gpt2` model.
494
- """
495
- reference = ... # TODO
496
-
497
- # TODO work out references
498
- dataset = datasets.load_dataset("./syntaxgym.py", "subordination_src-src")
499
- metric = datasets.load_metric("./syntaxgym.py")
500
- result = metric.compute(suite=dataset["test"], model_id="gpt2")
501
-
502
- from pprint import pprint
503
- pprint(result["region_totals"][0])
504
- pprint(GPT2_SUBORDINATION_SRC_REFERENCE[0])
505
-
506
- keys = result["region_totals"][0].keys()
507
- assert set(keys) == set(GPT2_SUBORDINATION_SRC_REFERENCE[0].keys())
508
-
509
- result_ndarray = np.concatenate([np.array([region_totals[key] for key in keys])
510
- for region_totals in result["region_totals"]])
511
- reference_ndarray = np.concatenate([np.array([region_totals[key] for key in keys])
512
- for region_totals in GPT2_SUBORDINATION_SRC_REFERENCE])
513
- pprint(sorted(zip(keys, np.abs(result_ndarray - reference_ndarray)),
514
- key=lambda x: -x[1]))
515
- np.testing.assert_allclose(result_ndarray, reference_ndarray, atol=1e-3)