class_docstr: A `FinalSequenceScorer` which scores the sequences by the average log probability of the
  tokens in the sequence. It optionally includes a length penalty which promotes
  or demotes sequences based on their lengths. The final score for a sequence will
  be `(sequence_log_probability) / (sequence_length ** length_penalty)`. The sequence length
  here includes the end token.
  
  # Parameters
  
  length_penalty : `float`, optional (default = `1.0`)
      The length penalty to use. A value of 1.0 means no length penalty is used.
      A value > 1.0 favors longer sequences, and < 1.0 favors shorter sequences.
class_docstr_tok: ["A","`","FinalSequenceScorer","`","which","scores","the","sequences","by","the","average","log","probability","of","the","tokens","in","the","sequence",".","It","optionally","includes","a","length","penalty","which","promotes","or","demotes","sequences","based","on","their","lengths",".","The","final","score","for","a","sequence","will","be","`","(","sequence_log_probability",")","\/","(","sequence_length","*","*","length_penalty",")","`",".","The","sequence","length","here","includes","the","end","token",".","#","Parameters","length_penalty",":","`","float","`",",","optional","(","default","=","`","1.0","`",")","The","length","penalty","to","use",".","A","value","of","1.0","means","no","length","penalty","is","used",".","A","value",">","1.0","favors","longer","sequences",",","and","<","1.0","favors","shorter","sequences","."]
code: def score(
      self,
      predictions: torch.Tensor,
      log_probabilities: torch.Tensor,
      end_index: int,
  ) -> torch.Tensor:
      # shape: (batch_size, beam_size)
      lengths = (predictions != end_index).long().sum(dim=2)
  
      # If the sequence ended during beam search, the `log_probabilities` will include
      # the transition to the end token. Therefore, in such situations, `lengths` is
      # actually off by 1. This corrects for that.
      # shape: (batch_size, beam_size)
      is_end_token = predictions[:, :, -1] == end_index
      lengths += is_end_token.long()
  
      # shape: (batch_size, beam_size)
      average_log_probs = log_probabilities / (
          lengths**self.length_penalty
      )
      return average_log_probs
  
imports: from inspect import signature
  from typing import Any, List, Callable, Tuple, Dict, cast, TypeVar, Optional
  import copy
  import warnings
  import torch
  from allennlp.common import Lazy, Registrable
  from allennlp.common.checks import ConfigurationError
  from allennlp.data import Vocabulary
  from allennlp.nn.util import min_value_of_dtype
label_desc: Use image node_id 2 for calling the LengthNormalizedSequenceLogProbabilityScorer obj's underlying member method code with example usage: obj.score(predictions, log_probabilities, end_index) and returns: average_log_probs