code: def generate_instance(
      occupation,
      participant,
      answer,
      sentence,
      gender=Gender.UNKNOWN,
      someone=False,
  ):
      """Generate a Winogender example from a template row."""
      toks = sentence.split(" ")
      part_index = toks.index("$PARTICIPANT")
      if not someone:
          # we are using the instantiated participant,
          # e.g. "client", "patient", "customer",...
          toks[part_index] = participant
      else:  # we are using the bleached NP "someone" for the other participant
          # first, remove the token that precedes $PARTICIPANT, i.e. "the"
          toks = toks[: part_index - 1] + toks[part_index:]
          # recompute participant index (it should be part_index - 1)
          part_index = toks.index("$PARTICIPANT")
          toks[part_index] = "Someone" if part_index == 0 else "someone"
  
      # Make sure we do this /after/ substituting "someone",
      # since that may change indices.
      occ_index = toks.index("$OCCUPATION")
      # This should always pass on the regular Winogender dataset.
      assert " " not in occupation, "Occupation must be single-token."
      toks[occ_index] = occupation
  
      pronoun_idx = None
      gendered_toks = []
      for i, t in enumerate(toks):
          sub = PRONOUN_MAP[gender].get(t, t)
          if sub != t:
              pronoun_idx = i
          gendered_toks.append(sub)
  
      # NOM, POSS, ACC
      pronoun_type = toks[pronoun_idx][1:].replace("_PRONOUN", "")
  
      # Process text for fluency
      text = " ".join(gendered_toks)
      text = text.replace("they was", "they were")
      text = text.replace("They was", "They were")
  
      record = {"text": text, "tokens": text.split()}
      t0 = EdgeLabel(
          span1=(occ_index, occ_index + 1),
          span2=(pronoun_idx, pronoun_idx + 1),
          label=int(1 if answer == 0 else 0),
      )
      t1 = EdgeLabel(
          span1=(part_index, part_index + 1),
          span2=(pronoun_idx, pronoun_idx + 1),
          label=int(1 if answer == 1 else 0),
      )
      record["coref"] = [t0, t1]
      record.update(
          {
              "occupation": occupation,
              "participant": participant,
              "answer": ANSWER_VOCAB[answer],
              "someone": str(someone),
              "pronouns": PRONOUNS_BY_GENDER[gender],
              "pronoun_type": pronoun_type,
              "gender": gender.name,
          }
      )
      return record
  
file_path: lit/lit_nlp/examples/coref/datasets/winogender.py
imports: import enum
  import os
  from typing import Optional
  from absl import logging
  from lit_nlp.api import dataset
  from lit_nlp.api import dtypes
  from lit_nlp.api import types
  from lit_nlp.lib import file_cache
  import pandas
label_desc: Use image node_id 2 for calling a global function with example usage: generate_instance(occupation, participant, answer, sentence, gender, someone) and returns: record