class_docstr: Shuffle words by no more than k positions.
class_docstr_tok: ["Shuffle","words","by","no","more","than","k","positions","."]
code: def noising(self, x, lengths, max_shuffle_distance=None):
      if max_shuffle_distance is None:
          max_shuffle_distance = self.default_max_shuffle_distance
      # x: (T x B), lengths: B
      if max_shuffle_distance == 0:
          return x, lengths
  
      # max_shuffle_distance < 1 will return the same sequence
      assert max_shuffle_distance > 1
  
      # define noise word scores
      noise = np.random.uniform(
          0,
          max_shuffle_distance,
          size=(x.size(0), x.size(1)),
      )
      noise[0] = -1  # do not move start sentence symbol
      # be sure to shuffle entire words
      word_idx = self.get_word_idx(x)
      x2 = x.clone()
      for i in range(lengths.size(0)):
          length_no_eos = lengths[i]
          if x[lengths[i] - 1, i] == self.dictionary.eos():
              length_no_eos = lengths[i] - 1
          # generate a random permutation
          scores = (
              word_idx[:length_no_eos, i]
              + noise[word_idx[:length_no_eos, i], i]
          )
          # ensure no reordering inside a word
          scores += 1e-6 * np.arange(length_no_eos.item())
          permutation = scores.argsort()
          # shuffle words
          x2[:length_no_eos, i].copy_(
              x2[:length_no_eos, i][torch.from_numpy(permutation)]
          )
      return x2, lengths
  
imports: import numpy
  import torch
  from fairseq.data import data_utils
label_desc: Use image node_id 2 for calling the WordShuffle obj's underlying member method code with example usage: obj.noising(x, lengths, max_shuffle_distance) and returns: x2,  lengths, x,  lengths