class_docstr: Noise from BART.
class_docstr_tok: ["Noise","from","BART","."]
code: def permute_sentences(self, tokens, p=1.0):
      if len(tokens) == 1:
          return tokens
      sentence_lens = self._get_sentence_borders(tokens)
      n_sentences = sentence_lens.size
      if n_sentences == 1:
          return tokens
  
      n_to_permute = math.ceil((n_sentences * 2 * p) / 2.0)
  
      substitutions = np.random.permutation(n_sentences)[:n_to_permute]
      ordering = np.arange(0, n_sentences)
      ordering[substitutions] = substitutions[
          np.random.permutation(n_to_permute)
      ]
  
      result = [tok for tok in tokens]
      index = 0
      for i in ordering:
          sentence = tokens[
              (sentence_lens[i - 1] if i > 0 else 0) : sentence_lens[i]
          ]
          result[index : index + len(sentence)] = sentence
          index += len(sentence)
      assert len(result) == len(tokens), "Error when permute sentences."
      return result
  
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 5 for calling the BARTNoising obj's underlying member method code with example usage: obj.permute_sentences(tokens, p) and returns: result, tokens, tokens