class_docstr: Noise from BART.
class_docstr_tok: ["Noise","from","BART","."]
code: def insertion_noise(self, tokens, p=1.0):
      n_tokens = len(tokens)
      n_insert = math.ceil(n_tokens * p)
      if n_insert == 0:
          return tokens
      n_random = math.ceil(n_insert * self.random_ratio)
  
      noise_indices = np.random.permutation(n_tokens + n_insert)[
          :n_insert
      ]
      noise_mask = np.zeros(shape=(n_tokens + n_insert,), dtype=bool)
      noise_mask[noise_indices] = 1
  
      result = np.empty(shape=(n_tokens + n_insert,), dtype=object)
      result[noise_indices[n_random:]] = self.mask_tok
      if n_random > 0:
          result[noise_indices[:n_random]] = np.random.choice(
              self.vocab, size=n_random
          )
      result[~noise_mask] = tokens
  
      assert all(
          [item is not None for item in result]
      ), "Error when inserting noise."
      return result.tolist()
  
imports: import math
  import numpy
  import torch
  from typing import Sequence, Callable
  from onmt.constants import DefaultTokens, SubwordMarker
  from onmt.transforms import register_transform
  from .transform import Transform
label_desc: Use image node_id 7 for calling the BARTNoising obj's underlying member method code with example usage: obj.insertion_noise(tokens, p) and returns: result, tokens