class_docstr: Time synchronous beam search algorithm.
class_docstr_tok: ["Time","synchronous","beam","search","algorithm","."]
docstr: Retrieve decoder/LM scores which may be cached.
docstr_tok: ["Retrieve","decoder\/LM","scores","which","may","be","cached","."]
code: def cached_score(
      self,
      h: Tuple[int],
      cache: dict,
      scorer: ScorerInterface,
      recompute_cache: bool = False,
  ) -> Any:
      """Retrieve decoder/LM scores which may be cached."""
      root = h[:-1]  # prefix
  
      if (root in cache and root in self.block_set) or len(root) <= 1:
          logging.debug("not recomputing")
          root_scores = cache[root].scores
          root_state = cache[root].state
          root_log_sum = cache[root].log_sum
      else:  # run decoder fwd one step and update cache
          root_root = root[:-1]
          root_root_state = cache[root_root].state
          root_scores, root_state = scorer.score(
              torch.tensor(root, device=self.enc_output.device).long(),
              root_root_state,
              self.enc_output,
          )
          root_log_sum = cache[root_root].log_sum + float(
              cache[root_root].scores[root[-1]]
          )
          cache[root] = CacheItem(
              state=root_state, scores=root_scores, log_sum=root_log_sum
          )
      cand_score = float(root_scores[h[-1]])
      score = root_log_sum + cand_score
  
      logging.debug("cand score: " + str(cand_score))
      logging.debug("decoder score: " + str(score))
  
      self.block_set.add(root)
  
      return score
  
file_path: espnet/espnet/nets/beam_search_timesync_streaming.py
imports: import logging
  from collections import defaultdict
  from dataclasses import dataclass
  from typing import Any, Dict, List, Tuple
  import numpy
  import torch
  from espnet.nets.beam_search import Hypothesis
  from espnet.nets.scorer_interface import ScorerInterface
label_desc: Use image node_id 3 for calling the BeamSearchTimeSyncStreaming obj's underlying member method code with example usage: obj.cached_score(h, cache, scorer, recompute_cache) and returns: score