class_docstr: Calculates the loss for each sequence up to its length t.
class_docstr_tok: ["Calculates","the","loss","for","each","sequence","up","to","its","length","t","."]
docstr: Calculates the log-sum-exponent of a tensor's dimension in a numerically stable way.
  
  Args:
      tensor: tensor
      dim: dimension to calculate log-sum-exp of
  
  Returns: log-sum-exp
docstr_tok: ["Calculates","the","log-sum-exponent","of","a","tensor","'s","dimension","in","a","numerically","stable","way",".","Args",":","tensor",":","tensor","dim",":","dimension","to","calculate","log-sum-exp","of","Returns",":","log-sum-exp"]
code: def _log_sum_exp(tensor, dim):
      """Calculates the log-sum-exponent of a tensor's dimension in a numerically stable way.
  
      Args:
          tensor: tensor
          dim: dimension to calculate log-sum-exp of
  
      Returns: log-sum-exp
      """
      m, _ = torch.max(tensor, dim)
      m_expanded = m.unsqueeze(dim).expand_as(tensor)
      return m + torch.log(
          torch.sum(torch.exp(tensor - m_expanded), dim)
      )
  
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 ViterbiLoss obj's underlying member method code with example usage: obj._log_sum_exp(tensor, dim) and returns: unknown