class_docstr: Use Cloud Translate API as a Generator.
  
  In order to use this generator, you must have Cloud Translation set up
  through a Google Cloud project as described at
  https://cloud.google.com/translate/docs/setup and have downloaded your
  application credentials file locally and set the
  GOOGLE_APPLICATION_CREDENTIALS environment variable to point to that file.
class_docstr_tok: ["Use","Cloud","Translate","API","as","a","Generator",".","In","order","to","use","this","generator",",","you","must","have","Cloud","Translation","set","up","through","a","Google","Cloud","project","as","described","at","https",":","\/\/cloud.google.com\/translate\/docs\/setup","and","have","downloaded","your","application","credentials","file","locally","and","set","the","GOOGLE_APPLICATION_CREDENTIALS","environment","variable","to","point","to","that","file","."]
docstr: Run generation on a set of inputs.
  
  If more than one field is to be backtranslated, each field is independently
  backtranslated per example. For example, if there are two fields to be
  backtranslated, this method will generate two examples per pivot language.
  
  Use this batch API by default, so we can make parallel requests.
  Args:
    inputs: sequence of inputs, following dataset.spec()
    model: unused
    dataset: dataset, used to access dataset.spec()
    config: additional runtime options
  
  Returns:
    list of list of new generated inputs, following dataset.spec()
docstr_tok: ["Run","generation","on","a","set","of","inputs",".","If","more","than","one","field","is","to","be","backtranslated",",","each","field","is","independently","backtranslated","per","example",".","For","example",",","if","there","are","two","fields","to","be","backtranslated",",","this","method","will","generate","two","examples","per","pivot","language",".","Use","this","batch","API","by","default",",","so","we","can","make","parallel","requests",".","Args",":","inputs",":","sequence","of","inputs",",","following","dataset.spec","(",")","model",":","unused","dataset",":","dataset",",","used","to","access","dataset.spec","(",")","config",":","additional","runtime","options","Returns",":","list","of","list","of","new","generated","inputs",",","following","dataset.spec","(",")"]
code: def generate_all(
      self,
      inputs: list[_JsonDict],
      model: lit_model.Model,
      dataset: lit_dataset.Dataset,
      config: Optional[_JsonDict] = None,
  ) -> list[list[_JsonDict]]:
      """Run generation on a set of inputs.
  
      If more than one field is to be backtranslated, each field is independently
      backtranslated per example. For example, if there are two fields to be
      backtranslated, this method will generate two examples per pivot language.
  
      Use this batch API by default, so we can make parallel requests.
      Args:
        inputs: sequence of inputs, following dataset.spec()
        model: unused
        dataset: dataset, used to access dataset.spec()
        config: additional runtime options
  
      Returns:
        list of list of new generated inputs, following dataset.spec()
      """
      del model
      all_outputs: list[list[_JsonDict]] = [[] for _ in inputs]
      config: _JsonDict = config or {}
  
      # Find text fields.
      text_fields = utils.find_spec_keys(
          dataset.spec(), types.TextSegment
      )
      # If config key is missing, backtranslate all text fields.
      fields_to_backtranslate: Sequence[str] = list(
          config.get(FIELDS_TO_BACKTRANSLATE_KEY, text_fields)
      )
      candidates_by_field: dict[str, list[list[str]]] = {}
      for field_name in fields_to_backtranslate:
          texts = [ex[field_name] for ex in inputs]
          candidates_by_field[field_name] = self.generate_from_texts(
              texts
          )
      # Generate by substituting in each field.
      # TODO(lit-team): substitute on a combination of fields?
      for field_name, candidates in candidates_by_field.items():
          for i, (inp, cands) in enumerate(
              zip(inputs, candidates, strict=True)
          ):
              for cand in cands:
                  all_outputs[i].append(
                      utils.make_modified_input(
                          inp, {field_name: cand}, "Backtranslator"
                      )
                  )
      return all_outputs
  
file_path: lit/lit_nlp/components/backtranslator.py
imports: from collections.abc import Sequence
  from typing import Optional
  from absl import logging
  from google.cloud import translate_v2
  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
  import pandas
label_desc: Use image node_id 3 for calling the Backtranslator obj's underlying member method code with example usage: obj.generate_all(inputs, model, dataset, config) and returns: all_outputs