Jon Gauthier commited on
Commit ·
9d3d980
1
Parent(s): 70f4226
Get prediction evaluation working
Browse files- syntaxgym.py +12 -1
- test.py +8 -0
syntaxgym.py
CHANGED
|
@@ -185,7 +185,18 @@ class SyntaxGymMetric(datasets.Metric):
|
|
| 185 |
# up the aggregation output
|
| 186 |
print("Warning: exceeded ", token)
|
| 187 |
|
| 188 |
-
region_totals = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
def get_region_edges(self, item_number, condition_name):
|
| 191 |
"""
|
|
|
|
| 185 |
# up the aggregation output
|
| 186 |
print("Warning: exceeded ", token)
|
| 187 |
|
| 188 |
+
region_totals = {(condition_name, region_number): float(total)
|
| 189 |
+
for condition_name, totals in region_totals.items()
|
| 190 |
+
for region_number, total in totals.items()}
|
| 191 |
+
|
| 192 |
+
results = {
|
| 193 |
+
"prediction_results": [
|
| 194 |
+
p.formula(region_totals) for p in self.predictions
|
| 195 |
+
],
|
| 196 |
+
|
| 197 |
+
"region_totals": region_totals
|
| 198 |
+
}
|
| 199 |
+
return results
|
| 200 |
|
| 201 |
def get_region_edges(self, item_number, condition_name):
|
| 202 |
"""
|
test.py
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import datasets
|
| 2 |
import numpy as np
|
| 3 |
import transformers
|
|
@@ -18,6 +21,11 @@ model = transformers.AutoModelForCausalLM.from_pretrained(model_ref)
|
|
| 18 |
model.eval()
|
| 19 |
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
for item in dataset["test"]:
|
| 22 |
# TODO full preprocessing setup
|
| 23 |
condition_names = item["conditions"]["condition_name"]
|
|
|
|
| 1 |
+
import itertools
|
| 2 |
+
from typing import List
|
| 3 |
+
|
| 4 |
import datasets
|
| 5 |
import numpy as np
|
| 6 |
import transformers
|
|
|
|
| 21 |
model.eval()
|
| 22 |
|
| 23 |
|
| 24 |
+
# all_sentences: List[List[str]] = [item["conditions"]["content"] for item in dataset["test"]]
|
| 25 |
+
# all_sentences_flat = list(itertools.chain.from_iterable(all_sentences))
|
| 26 |
+
|
| 27 |
+
tokenized = tokenizer(all_sentences_flat,
|
| 28 |
+
return_tensors="pt", padding=True, return_offsets_mapping=True)
|
| 29 |
for item in dataset["test"]:
|
| 30 |
# TODO full preprocessing setup
|
| 31 |
condition_names = item["conditions"]["condition_name"]
|