This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix use of scalar tensors in ConllCorefScores (#1604)
* Added test for #1545, fixed test, and improved documentation * pylint * mypy
- Loading branch information
1 parent
982cedd
commit 4eaeff7
Showing
2 changed files
with
65 additions
and
12 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
allennlp/tests/training/metrics/conll_coref_scores_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# pylint: disable=no-self-use,invalid-name,protected-access | ||
import torch | ||
|
||
from allennlp.common.testing import AllenNlpTestCase | ||
from allennlp.training.metrics import ConllCorefScores | ||
|
||
class ConllCorefScoresTest(AllenNlpTestCase): | ||
def test_get_predicted_clusters(self): | ||
top_spans = torch.Tensor([[0, 1], [4, 6], [8, 9]]).long() | ||
antecedent_indices = torch.Tensor([[-1, -1, -1], | ||
[0, -1, -1], | ||
[0, 1, -1]]).long() | ||
predicted_antecedents = torch.Tensor([-1, -1, 1]).long() | ||
clusters, mention_to_cluster = ConllCorefScores.get_predicted_clusters(top_spans, | ||
antecedent_indices, | ||
predicted_antecedents) | ||
assert len(clusters) == 1 | ||
assert set(clusters[0]) == {(4, 6), (8, 9)} | ||
assert mention_to_cluster == {(4, 6): clusters[0], (8, 9): clusters[0]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters