class_docstr: Subclass of TextEncoder which also provides methods to handle CTC blank token.
  
  add_blank and insert_blank can be used to add <blank> special token to the encoder
  state.
  
  >>> from speechbrain.dataio.encoder import CTCTextEncoder
  >>> chars = ["a", "b", "c", "d"]
  >>> encoder = CTCTextEncoder()
  >>> encoder.update_from_iterable(chars)
  >>> encoder.add_blank()
  >>> encoder.expect_len(5)
  >>> encoder.encode_sequence(chars)
  [0, 1, 2, 3]
  >>> encoder.get_blank_index()
  4
  >>> encoder.decode_ndim([0, 1, 2, 3, 4])
  ['a', 'b', 'c', 'd', '<blank>']
  
  collapse_labels and collapse_indices_ndim can be used to apply CTC collapsing
  rules:
  >>> encoder.collapse_labels(["a", "a", "b", "c", "d"])
  ['a', 'b', 'c', 'd']
  >>> encoder.collapse_indices_ndim([4, 4, 0, 1, 2, 3, 4, 4]) # 4 is <blank>
  [0, 1, 2, 3]
class_docstr_tok: ["Subclass","of","TextEncoder","which","also","provides","methods","to","handle","CTC","blank","token",".","add_blank","and","insert_blank","can","be","used","to","add","<","blank",">","special","token","to","the","encoder","state",".",">",">",">","from","speechbrain.dataio.encoder","import","CTCTextEncoder",">",">",">","chars","=","[","``","a","''",",","``","b","''",",","``","c","''",",","``","d","''","]",">",">",">","encoder","=","CTCTextEncoder","(",")",">",">",">","encoder.update_from_iterable","(","chars",")",">",">",">","encoder.add_blank","(",")",">",">",">","encoder.expect_len","(","5",")",">",">",">","encoder.encode_sequence","(","chars",")","[","0",",","1",",","2",",","3","]",">",">",">","encoder.get_blank_index","(",")","4",">",">",">","encoder.decode_ndim","(","[","0",",","1",",","2",",","3",",","4","]",")","[","'","a","'",",","'","b","'",",","'","c","'",",","'d","'",",","'","<","blank",">","'","]","collapse_labels","and","collapse_indices_ndim","can","be","used","to","apply","CTC","collapsing","rules",":",">",">",">","encoder.collapse_labels","(","[","``","a","''",",","``","a","''",",","``","b","''",",","``","c","''",",","``","d","''","]",")","[","'","a","'",",","'","b","'",",","'","c","'",",","'d","'","]",">",">",">","encoder.collapse_indices_ndim","(","[","4",",","4",",","0",",","1",",","2",",","3",",","4",",","4","]",")","#","4","is","<","blank",">","[","0",",","1",",","2",",","3","]"]
docstr: Applies the CTC collapsing rules on arbitrarily label sequence.
  
  Arguments
  ---------
  x : iterable
      Label sequence on which to operate.
  merge_repeats : bool
      Whether to merge repeated labels before removing blanks.
      In the basic CTC label topology, repeated labels are merged.
      However, in RNN-T, they are not.
  
  Returns
  -------
  list
      List of labels with collapsing rules applied.
docstr_tok: ["Applies","the","CTC","collapsing","rules","on","arbitrarily","label","sequence",".","Arguments","--","--","--","--","-","x",":","iterable","Label","sequence","on","which","to","operate",".","merge_repeats",":","bool","Whether","to","merge","repeated","labels","before","removing","blanks",".","In","the","basic","CTC","label","topology",",","repeated","labels","are","merged",".","However",",","in","RNN-T",",","they","are","not",".","Returns","--","--","--","-","list","List","of","labels","with","collapsing","rules","applied","."]
code: def collapse_indices_ndim(self, x, merge_repeats=True):
      """Applies the CTC collapsing rules on arbitrarily label sequence.
  
      Arguments
      ---------
      x : iterable
          Label sequence on which to operate.
      merge_repeats : bool
          Whether to merge repeated labels before removing blanks.
          In the basic CTC label topology, repeated labels are merged.
          However, in RNN-T, they are not.
  
      Returns
      -------
      list
          List of labels with collapsing rules applied.
      """
      if not hasattr(self, "blank_label"):
          raise KeyError("Blank label has not been added")
      # Recursively operates on the different dimensions.
      collapsed = []
      for subtensor in x:
          try:
              collapsed.append(
                  self.collapse_indices_ndim(subtensor, merge_repeats)
              )
          except TypeError:  # Not an iterable at next level!
              # So we should rather operate on this dimension.
              break
      else:  # For-else: only enter else if NO break.
          return collapsed
      # We get here if we DID break:
      blank_index = self.lab2ind[self.blank_label]
      if merge_repeats:
          return [
              index
              for i, index in enumerate(x)
              if (i == 0 or index != x[i - 1]) and index != blank_index
          ]
      else:
          return [index for index in x if index != blank_index]
  
imports: import ast
  import torch
  import collections
  import itertools
  import logging
  import warnings
  import speechbrain
  from speechbrain.utils.checkpoints import mark_as_saver, mark_as_loader, register_checkpoint_hooks
label_desc: Use image node_id 6 for calling the CTCTextEncoder obj's underlying member method code with example usage: obj.collapse_indices_ndim(x, merge_repeats) and returns: collapsed, unknown, unknown