class_docstr: Adds utilities for computing interCTC loss from https://arxiv.org/abs/2102.03216.
  
  To use, make sure encoder accesses ``interctc['capture_layers']``
  property in the AccessMixin and registers ``interctc/layer_output_X`` and
  ``interctc/layer_length_X`` for all layers that we want to get loss from.
  Additionally, specify the following config parameters to set up loss::
  
      interctc:
          # can use different values
          loss_weights: [0.3]
          apply_at_layers: [8]
  
  Then call
  
      * ``self.setup_interctc(ctc_decoder_name, ctc_loss_name, ctc_wer_name)``
        in the init method
      * ``self.add_interctc_losses`` after computing regular loss.
      * ``self.finalize_interctc_metrics(metrics, outputs, prefix="val_")``
        in the `multi_validation_epoch_end` method.
      * ``self.finalize_interctc_metrics(metrics, outputs, prefix="test_")``
        in the `multi_test_epoch_end` method.
class_docstr_tok: ["Adds","utilities","for","computing","interCTC","loss","from","https",":","\/\/arxiv.org\/abs\/2102.03216",".","To","use",",","make","sure","encoder","accesses","``","interctc","[","'capture_layers","'","]","``","property","in","the","AccessMixin","and","registers","``","interctc\/layer_output_X","``","and","``","interctc\/layer_length_X","``","for","all","layers","that","we","want","to","get","loss","from",".","Additionally",",","specify","the","following","config","parameters","to","set","up","loss",":",":","interctc",":","#","can","use","different","values","loss_weights",":","[","0.3","]","apply_at_layers",":","[","8","]","Then","call","*","``","self.setup_interctc","(","ctc_decoder_name",",","ctc_loss_name",",","ctc_wer_name",")","``","in","the","init","method","*","``","self.add_interctc_losses","``","after","computing","regular","loss",".","*","``","self.finalize_interctc_metrics","(","metrics",",","outputs",",","prefix=","''","val_","''",")","``","in","the","`","multi_validation_epoch_end","`","method",".","*","``","self.finalize_interctc_metrics","(","metrics",",","outputs",",","prefix=","''","test_","''",")","``","in","the","`","multi_test_epoch_end","`","method","."]
docstr: Returns a list of captured tensors from encoder: tuples of (output, length).
  
  Will additionally apply ``ctc_decoder`` to the outputs.
docstr_tok: ["Returns","a","list","of","captured","tensors","from","encoder",":","tuples","of","(","output",",","length",")",".","Will","additionally","apply","``","ctc_decoder","``","to","the","outputs","."]
code: def get_captured_interctc_tensors(
      self,
  ) -> List[Tuple[torch.Tensor, torch.Tensor]]:
      """Returns a list of captured tensors from encoder: tuples of (output, length).
  
      Will additionally apply ``ctc_decoder`` to the outputs.
      """
      if not self.is_interctc_enabled():
          return []
  
      # note that we have a loop here, because tensors can be defined from
      # submodules of encoder (e.g., that's the case in Jasper)
      total_registry = {}
      for module_registry in AccessMixin.get_module_registry(
          self.encoder
      ).values():
          for key in module_registry:
              if key.startswith("interctc/") and key in total_registry:
                  raise RuntimeError(
                      f"layer {key} has been logged multiple times!"
                  )
          total_registry.update(module_registry)
      # if intermediate_loss_weights was set, the encoder has to register
      # interctc/layer_output_X and interctc/layer_length_X tensors.
      # We need to apply decoder to each of them and compute CTC loss.
      captured_tensors = []
      for layer_idx in self.get_interctc_param("apply_at_layers"):
          try:
              layer_outputs = total_registry[
                  f"interctc/layer_output_{layer_idx}"
              ]
              layer_lengths = total_registry[
                  f"interctc/layer_length_{layer_idx}"
              ]
          except KeyError:
              raise RuntimeError(
                  f"Intermediate layer {layer_idx} was not captured! "
                  "Check if length of model.encoder.captured_layer_outputs matches "
                  "length of model.intermediate_loss_weights properties."
              )
          if len(layer_outputs) > 1 or len(layer_lengths) > 1:
              raise RuntimeError(
                  "Make sure encoder.forward is called exactly one time before interCTC loss is computed."
              )
          captured_tensors.append(
              (
                  self.get_interctc_param("decoder")(
                      encoder_output=layer_outputs[0]
                  ),
                  layer_lengths[0],
              )
          )
      return captured_tensors
  
file_path: NeMo/nemo/collections/asr/parts/mixins/interctc_mixin.py
imports: from typing import Dict, List, Optional, Tuple
  import torch
  from nemo.core.classes.mixins import AccessMixin
label_desc: Use image node_id 9 for calling the InterCTCMixin obj's underlying member method code with example usage: obj.get_captured_interctc_tensors() and returns: captured_tensors, list