class_docstr: Decodes a given sequence using the Viterbi algorithm.
class_docstr_tok: ["Decodes","a","given","sequence","using","the","Viterbi","algorithm","."]
docstr: Returns all scores for each tag in tag dictionary.
docstr_tok: ["Returns","all","scores","for","each","tag","in","tag","dictionary","."]
code: def _all_scores_for_token(
      self,
      scores: torch.Tensor,
      tag_seq: torch.IntTensor,
      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, (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())
              )
  
              if tag_id_int != np.argmax(tag_scores):
                  swap_index_score = int(np.argmax(tag_scores))
                  (
                      scores[i_batch][i][tag_id_int],
                      scores[i_batch][i][swap_index_score],
                  ) = (
                      scores[i_batch][i][swap_index_score],
                      scores[i_batch][i][tag_id_int],
                  )
      prob_tags_per_sentence = []
      for scores_sentence, length, sentence in zip(
          scores, lengths, sentences
      ):
          scores_sentence = scores_sentence[:length]
          prob_tags_per_sentence.append(
              [
                  [
                      Label(
                          token,
                          self.tag_dictionary.get_item_for_index(
                              score_id
                          ),
                          score,
                      )
                      for score_id, score in enumerate(score_dist)
                  ]
                  for score_dist, token in zip(
                      scores_sentence, sentence
                  )
              ]
          )
      return prob_tags_per_sentence
  
file_path: flair/flair/models/sequence_tagger_utils/viterbi.py
imports: from typing import Tuple
  import numpy
  import torch
  import torch.nn
  from torch.nn.functional import softmax
  from torch.nn.utils.rnn import pack_padded_sequence
  import flair
  from flair.data import Dictionary, Label, List, Sentence
label_desc: Use image node_id 3 for calling the ViterbiDecoder obj's underlying member method code with example usage: obj._all_scores_for_token(scores, tag_seq, lengths, sentences) and returns: prob_tags_per_sentence