Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adding Docker version of Prism #68

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gem_metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def metric_list_to_metric_dict(metric_list: List[str]) -> Dict[str, List]:
"sari": "SARI",
"nubia": "NUBIA",
"questeval": "QuestEval",
"prism": "Prism",
}

referenced_list, referenceless_list, sourced_and_referenced_list = [], [], []
Expand Down
32 changes: 32 additions & 0 deletions gem_metrics/prism.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

from repro.models.thompson2020 import Prism as _Prism

from .metric import ReferencedMetric


class Prism(ReferencedMetric):
def __init__(self, device: int, language: str = "en"):
self.prism = _Prism(device=device, language=language)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation in the GEM metrics library would wrap the one in Repro (here)


def compute(self, cache, predictions, references):
inputs = []
for pred, refs in zip(predictions.untokenized, references.untokenized):
inputs.append({
"candidate": pred,
"references": refs
})

# Example `micro` output for 3 inputs
# [{'prism': -1.1578280925750732}, {'prism': -1.3325390815734863}, {'prism': -2.730839729309082}]
_, micro = self.prism.predict_batch(inputs)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual implementation would reformat the input data to the format required by the metric, running predict_batch, and then reformatting the outputs to fit the GEM framework


# Write to cache if not None and collect outputs
id_to_scores = {}
for pred_id, score_dict in zip(predictions.ids, micro):
id_to_scores[pred_id] = score_dict
if cache is not None:
cache_key = (self.__class__.__name__, predictions.filename, pred_id)
cache[cache_key] = score_dict

return id_to_scores
1 change: 1 addition & 0 deletions requirements-heavy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ nubia-score
bert_score
git+https://github.com/google-research/bleurt.git
questeval==0.2.4
repro==0.1.2
17 changes: 17 additions & 0 deletions tests/test_prism.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest
import gem_metrics.prism
from tests.test_referenced import TestReferencedMetric


class TestPrism(TestReferencedMetric, unittest.TestCase):
def setUp(self):
super().setUp()
self.metric = gem_metrics.prism.Prism(device=-1)
self.true_results_basic = {"prism": -1.7404}
self.true_results_identical_pred_ref = {"prism": -0.229}
self.true_results_mismatched_pred_ref = {"prism": -6.62654}
self.true_results_empty_pred = {"prism": -9.90867}


if __name__ == "__main__":
unittest.main()