code: def select_lm_state(
      lm_states: Union[List[Any], Dict[str, Any]],
      idx: int,
      lm_layers: int,
      is_wordlm: bool,
  ) -> Union[List[Any], Dict[str, Any]]:
      """Get ID state from LM hidden states.
  
      Args:
          lm_states: LM hidden states.
          idx: LM state ID to extract.
          lm_layers: Number of LM layers.
          is_wordlm: Whether provided LM is a word-level LM.
  
      Returns:
         idx_state: LM hidden state for given ID.
  
      """
      if is_wordlm:
          idx_state = lm_states[idx]
      else:
          idx_state = {}
  
          idx_state["c"] = [
              lm_states["c"][layer][idx] for layer in range(lm_layers)
          ]
          idx_state["h"] = [
              lm_states["h"][layer][idx] for layer in range(lm_layers)
          ]
  
      return idx_state
  
file_path: espnet/espnet/nets/pytorch_backend/transducer/utils.py
imports: import os
  from typing import Any, Dict, List, Optional, Union
  import numpy
  import torch
  from espnet.nets.pytorch_backend.nets_utils import pad_list
  from espnet.nets.transducer_decoder_interface import ExtendedHypothesis, Hypothesis
label_desc: Use image node_id 6 for calling a global function with example usage: select_lm_state(lm_states, idx, lm_layers, is_wordlm) and returns: idx_state