code: def create_ngram_index(
      light_scenarios: List[LightScenario],
      n_values: List[int],
      tokenizer: LightTokenizer,
  ) -> NgramIndex:
      """Given a list of scenarios and n values, initialize ngram_index"""
      ngram_index: NgramIndex = {n: {} for n in n_values}
      for scenario in light_scenarios:
          hlog(
              f"Building ngram indexes for {scenario.light_scenario_key}"
          )
          for n in n_values:
              stats_key = ContaminationStatsKey(
                  metadata={
                      "light_scenario_key": scenario.light_scenario_key,
                      "N": n,
                  }
              )
              for i in range(len(scenario.light_instances)):
                  instance = scenario.light_instances[i]
                  input_tokens = tokenizer.tokenize(instance.input)
                  for input_ngram in ngrams(input_tokens, n):
                      if input_ngram not in ngram_index[n]:
                          ngram_index[n][input_ngram] = set()
                      ngram_index[n][input_ngram].add(
                          EntryContaminationKey(
                              stats_key=stats_key,
                              instance_id=i,
                              part=PART_INPUT,
                          )
                      )
  
                  # compute reference ngrams
                  for reference in instance.references:
                      reference_unigrams = tokenizer.tokenize(reference)
                      for reference_ngram in ngrams(
                          reference_unigrams, n
                      ):
                          if reference_ngram not in ngram_index[n]:
                              ngram_index[n][reference_ngram] = set()
                          ngram_index[n][reference_ngram].add(
                              EntryContaminationKey(
                                  stats_key=stats_key,
                                  instance_id=i,
                                  part=PART_REF,
                              )
                          )
      return ngram_index
  
imports: import json
  import argparse
  import os
  import glob
  from typing import List, Tuple, Set, Any, Optional
  from nltk import ngrams
  from typing import Dict
  from tqdm import tqdm
  from dataclasses import dataclass
  from helm.benchmark.contamination.light_scenario import LightInstance, LightScenario, LightScenarioKey
  from helm.benchmark.contamination.light_tokenizer import LightTokenizer, DefaultTokenizer
  from helm.benchmark.contamination.load_documents import get_document_iterator
  from helm.benchmark.contamination.contamination_stats import ContaminationStats, ContaminationStatsKey, PART_INPUT, PART_REF
  from helm.common.hierarchical_logger import hlog, htrack_block
  from helm.common.general import asdict_without_nones, write
  from helm.benchmark.scenarios.scenario import ScenarioSpec
label_desc: Use image node_id 2 for calling a global function with example usage: create_ngram_index(light_scenarios, n_values, tokenizer) and returns: ngram_index