code: def add_bos_eos(seq=None, encoder=None):
      """Adds BOS and EOS tokens to the sequence provided
  
      Arguments
      ---------
      seq: torch.Tensor
          the source sequence
      encoder: speechbrain.dataio.encoder.TextEncoder
          an encoder instance
  
  
      Returns
      -------
      seq_eos: torch.Tensor
          the sequence, with the EOS token added
      seq_bos: torch.Tensor
          the sequence, with the BOS token added
      """
      seq_bos = encoder.prepend_bos_index(seq)
      if not torch.is_tensor(seq_bos):
          seq_bos = torch.tensor(seq_bos)
      yield seq_bos.long()
      yield torch.tensor(len(seq_bos))
      seq_eos = encoder.append_eos_index(seq)
      if not torch.is_tensor(seq_eos):
          seq_eos = torch.tensor(seq_eos)
      yield seq_eos.long()
      yield torch.tensor(len(seq_eos))
  
imports: from functools import reduce
  from speechbrain.wordemb.util import expand_to_chars
  import speechbrain
  import torch
  import re
label_desc: Use image node_id 9 for calling a global function with example usage: add_bos_eos(seq, encoder) without return types