Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
update conll (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshitaB authored Aug 31, 2021
1 parent 54de9d6 commit a8a3486
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added some additional `__init__()` parameters to the `T5` model in `allennlp_models.generation` for customizing
- Added some additional `__init__()` parameters to the `T5` model in `allennlp_models.generation` for customizing.
beam search and other options.
- Added a configuration file for fine-tuning `t5-11b` on CCN-DM (requires at least 8 GPUs).
- Added a configuration to train on the PIQA dataset with AllenNLP Tango.
Expand All @@ -18,8 +18,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fixed tests for Spacy versions greater than 3.1
- Fixed the last step decoding when training CopyNet
- Fixed tests for Spacy versions greater than 3.1.
- Fixed the last step decoding when training CopyNet.
- Allow singleton clusters in `ConllCorefScores`.

### Changed

Expand Down
11 changes: 8 additions & 3 deletions allennlp_models/coref/metrics/conll_coref_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class ConllCorefScores(Metric):

supports_distributed = True

def __init__(self) -> None:
def __init__(self, allow_singletons=False) -> None:
self.scorers = [Scorer(m) for m in (Scorer.muc, Scorer.b_cubed, Scorer.ceafe)]
self.allow_singletons = allow_singletons

@overrides
def __call__(
Expand Down Expand Up @@ -56,7 +57,7 @@ def __call__(
for i, metadata in enumerate(metadata_list):
gold_clusters, mention_to_gold = self.get_gold_clusters(metadata["clusters"])
predicted_clusters, mention_to_predicted = self.get_predicted_clusters(
top_spans[i], antecedent_indices[i], predicted_antecedents[i]
top_spans[i], antecedent_indices[i], predicted_antecedents[i], self.allow_singletons
)
for scorer in self.scorers:
scorer.update(
Expand Down Expand Up @@ -91,6 +92,7 @@ def get_predicted_clusters(
top_spans: torch.Tensor, # (num_spans, 2)
antecedent_indices: torch.Tensor, # (num_spans, num_antecedents)
predicted_antecedents: torch.Tensor, # (num_spans,)
allow_singletons: bool,
) -> Tuple[
List[Tuple[Tuple[int, int], ...]], Dict[Tuple[int, int], Tuple[Tuple[int, int], ...]]
]:
Expand All @@ -104,7 +106,10 @@ def get_predicted_clusters(
# Find predicted index in the antecedent spans.
predicted_index = antecedent_indices[i, predicted_antecedent]
# Must be a previous span.
assert i > predicted_index
if allow_singletons:
assert i >= predicted_index
else:
assert i > predicted_index
antecedent_span: Tuple[int, int] = tuple( # type: ignore
top_spans[predicted_index].tolist()
)
Expand Down
2 changes: 1 addition & 1 deletion tests/coref/metrics/conll_coref_scores_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_get_predicted_clusters(self, device: str):
antecedent_indices = torch.tensor([[-1, -1, -1], [0, -1, -1], [0, 1, -1]], device=device)
predicted_antecedents = torch.tensor([-1, -1, 1], device=device)
clusters, mention_to_cluster = ConllCorefScores.get_predicted_clusters(
top_spans, antecedent_indices, predicted_antecedents
top_spans, antecedent_indices, predicted_antecedents, allow_singletons=False
)
assert len(clusters) == 1
assert set(clusters[0]) == {(4, 6), (8, 9)}
Expand Down

0 comments on commit a8a3486

Please sign in to comment.