code: def compute_scenario_document_contamination(
      document: str,
      ngram_index: NgramIndex,
      all_contamination_stats: AllContaminationStats,
      tokenizer: LightTokenizer,
      ngram_counter: Optional[NgramCounter] = None,
      max_contaminated_ngrams: int = 0,
  ):
      """
      Given a document, compute a contamination stats for each n and each scenario. The function
      writes to the contamination stats directly and does not return anything.
  
      ngram_index: The ngram index that maps from ngrams to contamination stats
  
      tokenizer: The tokenizer used to break the document into tokens
  
      all_contamination_stats: The contamination stats for each scenario and n. The variable to write to.
  
      ngram_counter: The ngrams that are overlapped between the training file and the scenario data
      and their counts.
      The outer dict maps from n to the inner dict, which maps from ngram to count.
      """
      document_tokens = tokenizer.tokenize(document)
      for n in ngram_index.keys():
          for document_ngram in ngrams(document_tokens, n):
              if document_ngram in ngram_index[n]:
                  for entry_contamination_key in ngram_index[n][
                      document_ngram
                  ]:
                      # update contamination_stats
                      stats: ContaminationStats = (
                          all_contamination_stats[
                              entry_contamination_key.stats_key
                          ]
                      )
                      stats.write_one_to_bit(
                          entry_contamination_key.instance_id,
                          entry_contamination_key.part,
                      )
                      # skip the rest if max_contaminated_ngrams is 0
                      if max_contaminated_ngrams != 0:
                          if ngram_counter is None:
                              raise ValueError(
                                  "ngram_counter must be not none when max_contaminated_ngrams != 0"
                              )
                          # update ngram_counter
                          if (
                              entry_contamination_key
                              not in ngram_counter
                          ):
                              ngram_counter[
                                  entry_contamination_key
                              ] = {}
                          if (
                              document_ngram
                              in ngram_counter[entry_contamination_key]
                          ):
                              ngram_counter[entry_contamination_key][
                                  document_ngram
                              ] += 1
                          elif (
                              max_contaminated_ngrams == -1
                              or len(
                                  ngram_counter[entry_contamination_key]
                              )
                              < max_contaminated_ngrams
                          ):
                              ngram_counter[entry_contamination_key][
                                  document_ngram
                              ] = 1
  
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 5 for calling a global function with example usage: compute_scenario_document_contamination(document, ngram_index, all_contamination_stats, tokenizer, ngram_counter, max_contaminated_ngrams) without return types