Jon Gauthier
commited on
Commit
·
abe5584
1
Parent(s):
6d4b2a0
fix surprisal indexing issues
Browse files- syntaxgym.py +6 -2
syntaxgym.py
CHANGED
@@ -203,6 +203,7 @@ class SyntaxGymMetric(datasets.Metric):
|
|
203 |
|
204 |
# TODO: check this logic
|
205 |
tt = expected_ids.unsqueeze(2)
|
|
|
206 |
surprisals = torch.gather(surps_shifted, 2, expected_ids.unsqueeze(2)) \
|
207 |
.squeeze(2)
|
208 |
# This is the original, which works but not with multiple axes in expected_ids
|
@@ -220,8 +221,11 @@ class SyntaxGymMetric(datasets.Metric):
|
|
220 |
for i, (i_cond, i_inputs) in enumerate(zip(condition_names, input_ids)):
|
221 |
for region_number, region_tokens in region2tokens[i_cond].items():
|
222 |
for token in region_tokens:
|
223 |
-
if token
|
224 |
-
|
|
|
|
|
|
|
225 |
else:
|
226 |
# TODO don't think this is an issue, just should clean
|
227 |
# up the aggregation output
|
|
|
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
|
|
|
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
|