class_docstr: Scramble all words in an example to generate a new example.
class_docstr_tok: ["Scramble","all","words","in","an","example","to","generate","a","new","example","."]
docstr: Naively scramble all words in an example.
  
  Note: Even if more than one field is to be scrambled, only a single example
  will be produced, unlike other generators which will produce multiple
  examples, one per field.
  
  Args:
    example: the example used for basis of generated examples.
    model: the model.
    dataset: the dataset.
    config: user-provided config properties.
  
  Returns:
    examples: a list of generated examples.
docstr_tok: ["Naively","scramble","all","words","in","an","example",".","Note",":","Even","if","more","than","one","field","is","to","be","scrambled",",","only","a","single","example","will","be","produced",",","unlike","other","generators","which","will","produce","multiple","examples",",","one","per","field",".","Args",":","example",":","the","example","used","for","basis","of","generated","examples",".","model",":","the","model",".","dataset",":","the","dataset",".","config",":","user-provided","config","properties",".","Returns",":","examples",":","a","list","of","generated","examples","."]
code: def generate(
      self,
      example: JsonDict,
      model: lit_model.Model,
      dataset: lit_dataset.Dataset,
      config: Optional[JsonDict] = None,
  ) -> list[JsonDict]:
      """Naively scramble all words in an example.
  
      Note: Even if more than one field is to be scrambled, only a single example
      will be produced, unlike other generators which will produce multiple
      examples, one per field.
  
      Args:
        example: the example used for basis of generated examples.
        model: the model.
        dataset: the dataset.
        config: user-provided config properties.
  
      Returns:
        examples: a list of generated examples.
      """
      del model  # Unused.
  
      config = config or {}
  
      # If config key is missing, generate no examples.
      fields_to_scramble = list(config.get(FIELDS_TO_SCRAMBLE_KEY, []))
      if not fields_to_scramble:
          return []
  
      # TODO(lit-dev): move this to generate_all(), so we read the spec once
      # instead of on every example.
      text_keys = [
          key
          for key in utils.find_spec_keys(
              dataset.spec(), types.TextSegment
          )
          if key in fields_to_scramble
      ]
  
      if not text_keys:
          return []
  
      updates = {
          text_key: _scramble(example[text_key])
          for text_key in text_keys
      }
      new_example = utils.make_modified_input(
          example, updates, "Scrambler"
      )
      return [new_example]
  
file_path: lit/lit_nlp/components/scrambler.py
imports: import random
  from typing import Optional
  from lit_nlp.api import components
  from lit_nlp.api import dataset
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.lib import utils
label_desc: Use image node_id 3 for calling the Scrambler obj's underlying member method code with example usage: obj.generate(example, model, dataset, config) and returns: list, list, list