code: def sample_output_token(scores, do_sample, temperature, top_k, top_p):
      # TODO: Add beam search in here
      if do_sample:
          # Temperature (higher temperature => more likely to sample low probability tokens)
          if temperature != 1.0:
              scores = scores / temperature
          # Top-p/top-k filtering
          next_token_logscores = (
              transformers.generation_utils.top_k_top_p_filtering(
                  scores, top_k=top_k, top_p=top_p
              )
          )
          # Sample
          probs = F.softmax(next_token_logscores, dim=-1)
  
          prediction_id = torch.multinomial(probs, num_samples=1)
      else:
          # Greedy decoding
          prediction_id = torch.argmax(scores, dim=-1)
      prediction_id = prediction_id.squeeze()
      return prediction_id
  
imports: from collections import defaultdict
  import inspect
  import json
  import os
  import random
  import torch
  import transformers
  from transformers import BatchEncoding
  import ecco
  import numpy
  from IPython import display
  from torch.nn import functional
  from ecco.attribution import compute_primary_attributions_scores
  from ecco.output import OutputSeq
  from typing import Optional, Any, List, Tuple, Dict, Union
  from operator import attrgetter
  import re
  from ecco.util import is_partial_token, strip_tokenizer_prefix
  from packaging import version
label_desc: Use image node_id 1 for calling a global function with example usage: sample_output_token(scores, do_sample, temperature, top_k, top_p) and returns: prediction_id