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

fix _all_scores_for_token in ViterbiDecoder #3455

Merged
merged 5 commits into from
Jun 30, 2024
Merged
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
6 changes: 3 additions & 3 deletions flair/models/sequence_tagger_utils/viterbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,16 @@ def decode(
)

if probabilities_for_all_classes:
all_tags = self._all_scores_for_token(scores.cpu(), tag_seq, lengths, sentences)
all_tags = self._all_scores_for_token(scores.cpu(), decoded.cpu(), lengths, sentences)

return tags, all_tags

def _all_scores_for_token(
self, scores: torch.Tensor, tag_seq: torch.IntTensor, lengths: torch.IntTensor, sentences: List[Sentence]
self, scores: torch.Tensor, tag_sequences: torch.Tensor, lengths: torch.IntTensor, sentences: List[Sentence]
):
"""Returns all scores for each tag in tag dictionary."""
scores = scores.numpy()
for i_batch, batch in enumerate(scores):
for i_batch, (batch, tag_seq) in enumerate(zip(scores, tag_sequences)):
for i, (tag_id, tag_scores) in enumerate(zip(tag_seq, batch)):
tag_id_int = tag_id if isinstance(tag_id, int) else int(tag_id.item())

Expand Down
Loading