class_docstr: A utility class to help extract subsequences out of a batch
  of sequences
  
  Arguments
  ---------
  word_separator: int
      the index of the word separator (used in p_seq)
  word_separator_base int
      the index of word separators used in unprocessed
      targets (if different)
  
  Example
  -------
  >>> import torch
  >>> from speechbrain.lobes.models.g2p.homograph import SubsequenceExtractor
  >>> extractor = SubsequenceExtractor()
  >>> phns = torch.Tensor(
  ...     [[1, 2, 0, 1, 3, 0, 2, 1, 0],
  ...      [2, 1, 3, 0, 1, 2, 0, 3, 2]]
  ... )
  >>> phn_lens = torch.IntTensor([8, 9])
  >>> subsequence_phn_start = torch.IntTensor([3, 4])
  >>> subsequence_phn_end = torch.IntTensor([5, 7])
  >>> p_seq = torch.Tensor([
  ...     [[0., 1., 0., 0.],
  ...      [0., 0., 1., 0.],
  ...      [1., 0., 0., 0.],
  ...      [0., 1., 0., 0.],
  ...      [0., 0., 0., 1.],
  ...      [1., 0., 0., 0.],
  ...      [0., 0., 1., 0.],
  ...      [0., 1., 0., 0.],
  ...      [1., 0., 0., 0.]],
  ...     [[0., 0., 1., 0.],
  ...      [0., 1., 0., 0.],
  ...      [0., 0., 0., 1.],
  ...      [1., 0., 0., 0.],
  ...      [0., 1., 0., 0.],
  ...      [0., 0., 1., 0.],
  ...      [1., 0., 0., 0.],
  ...      [0., 0., 0., 1.],
  ...      [0., 0., 1., 0.]]
  ... ])
  >>> extractor.extract_seq(
  ...    phns,
  ...    phn_lens,
  ...    p_seq,
  ...    subsequence_phn_start,
  ...    subsequence_phn_end
  ... )
  (tensor([[[0., 1., 0., 0.],
           [0., 0., 0., 1.],
           [0., 0., 0., 0.]],
  <BLANKLINE>
          [[0., 1., 0., 0.],
           [0., 0., 1., 0.],
           [0., 0., 0., 0.]]]), tensor([[1., 3., 0.],
          [1., 2., 0.]]), tensor([0.6667, 1.0000]))
docstr: Extracts the subsequence from the complete sequence
  
  phns: torch.Tensor
      the phoneme tensor (batch x length)
  phn_lens: torch.Tensor
      the phoneme length tensor
  p_seq: torch.Tensor
      the output phoneme probability tensor
      (batch x length x phns)
  subsequence_phn_start: torch.Tensor
      the beginning of the target subsequence
      (i.e. the homograph)
  subsequence_phn_end: torch.Tensor
      the end of the target subsequence
      (i.e. the homograph)
  phns_base: torch.Tensor
      the phoneme tensor (not preprocessed)
  phn_base_lens: torch.Tensor
      the phoneme lengths (not preprocessed)
  
  Returns
  -------
  p_seq_subsequence: torch.Tensor
      the output subsequence (of probabilities)
  phns_subsequence: torch.Tensor
      the target subsequence
  subsequence_lengths: torch.Tensor
      subsequence lengths, expressed as a fraction
      of the tensor's last dimension
docstr_tok: ["Extracts","the","subsequence","from","the","complete","sequence","phns",":","torch.Tensor","the","phoneme","tensor","(","batch","x","length",")","phn_lens",":","torch.Tensor","the","phoneme","length","tensor","p_seq",":","torch.Tensor","the","output","phoneme","probability","tensor","(","batch","x","length","x","phns",")","subsequence_phn_start",":","torch.Tensor","the","beginning","of","the","target","subsequence","(","i.e",".","the","homograph",")","subsequence_phn_end",":","torch.Tensor","the","end","of","the","target","subsequence","(","i.e",".","the","homograph",")","phns_base",":","torch.Tensor","the","phoneme","tensor","(","not","preprocessed",")","phn_base_lens",":","torch.Tensor","the","phoneme","lengths","(","not","preprocessed",")","Returns","--","--","--","-","p_seq_subsequence",":","torch.Tensor","the","output","subsequence","(","of","probabilities",")","phns_subsequence",":","torch.Tensor","the","target","subsequence","subsequence_lengths",":","torch.Tensor","subsequence","lengths",",","expressed","as","a","fraction","of","the","tensor","'s","last","dimension"]
code: def extract_seq(
      self,
      phns,
      phn_lens,
      p_seq,
      subsequence_phn_start,
      subsequence_phn_end,
      phns_base=None,
      phn_base_lens=None,
  ):
      """
      Extracts the subsequence from the complete sequence
  
      phns: torch.Tensor
          the phoneme tensor (batch x length)
      phn_lens: torch.Tensor
          the phoneme length tensor
      p_seq: torch.Tensor
          the output phoneme probability tensor
          (batch x length x phns)
      subsequence_phn_start: torch.Tensor
          the beginning of the target subsequence
          (i.e. the homograph)
      subsequence_phn_end: torch.Tensor
          the end of the target subsequence
          (i.e. the homograph)
      phns_base: torch.Tensor
          the phoneme tensor (not preprocessed)
      phn_base_lens: torch.Tensor
          the phoneme lengths (not preprocessed)
  
      Returns
      -------
      p_seq_subsequence: torch.Tensor
          the output subsequence (of probabilities)
      phns_subsequence: torch.Tensor
          the target subsequence
      subsequence_lengths: torch.Tensor
          subsequence lengths, expressed as a fraction
          of the tensor's last dimension
  
      """
      has_base = False
      if phns_base is None and phn_base_lens is None:
          phns_base = phns
          phn_base_lens = phn_lens
      elif phns_base is None or phn_base_lens is None:
          raise ValueError(
              "phn_base and phn_lens_base, if provided, should be provided together"
          )
      else:
          has_base = True
  
      p_seq_edge = p_seq.size(1)
      phns_edge = (phns.size(1) * phn_lens).long().unsqueeze(-1)
  
      # Compute subsequence lengths and the longest length
      subsequence_lengths = subsequence_phn_end - subsequence_phn_start
      longest_subsequence = subsequence_lengths.max()
  
      # Pad the sequence axis to make sure the "distance" from the start of
      # each subsequence to the end of the sequence is at least as long
      # as the longest subsequence (e.g. subsequence = homograph)
      phns = self._pad_subsequence(phns, longest_subsequence)
      phns_base = self._pad_subsequence(phns_base, longest_subsequence)
      # p_seq_pad = (gap + longest_subsequence + 1).item()
      p_seq_pad = p_seq.size(1)
      p_seq = torch.nn.functional.pad(p_seq, (0, 0, 0, p_seq_pad))
  
      # Copy only the subsequences from the targets and inputs
      # into new tensors
      subsequence_phn_start_unsq = subsequence_phn_start.unsqueeze(-1)
      range_phns_base = torch.arange(
          phns_base.size(1), device=phns_base.device
      ).expand_as(phns_base)
      range_phns_subsequence = torch.arange(
          longest_subsequence, device=phns.device
      ).expand(phns.size(0), longest_subsequence)
      # Count the words in predictions
      target_word_indexes = self._get_target_word_indexes(
          phns_base,
          range_phns_base,
          subsequence_phn_start_unsq,
          self.word_separator_base,
          phn_lens=phn_base_lens,
      )
      if has_base:
          # Needed if tokenization or any other transformation was used
          (
              phns_subsequence,
              subsequence_lengths,
          ) = self._get_phns_subsequence(
              phns, target_word_indexes, longest_subsequence, phns_edge
          )
      else:
          # If phns and phns_base are the same, there is no need to re-detect word boundaries
          match = (range_phns_base >= subsequence_phn_start_unsq) & (
              range_phns_base
              < subsequence_phn_start_unsq + longest_subsequence
          )
          phns_subsequence = phns[match].reshape(
              range_phns_subsequence.shape
          )
  
          phns_subsequence[
              range_phns_subsequence
              >= subsequence_lengths.unsqueeze(-1)
          ] = 0.0
  
      p_seq_subsequence = self._get_p_seq_subsequence(
          p_seq, target_word_indexes, longest_subsequence, p_seq_edge
      )
  
      return (
          p_seq_subsequence,
          phns_subsequence,
          subsequence_lengths / longest_subsequence,
      )
  
imports: import torch
  from torch import nn
label_desc: Use image node_id 3 for calling the SubsequenceExtractor obj's underlying member method code with example usage: obj.extract_seq(phns, phn_lens, p_seq, subsequence_phn_start, subsequence_phn_end, phns_base, phn_base_lens) and returns: p_seq_subsequence,  phns_subsequence,  unknown