code: def sample_top(a=None, top_k=10):
      """Sample from ``top_k`` probabilities.
  
      Parameters
      ----------
      a : list of float
          List of probabilities.
      top_k : int
          Number of candidates to be considered.
  
      """
      if a is None:
          a = []
  
      idx = np.argpartition(a, -top_k)[-top_k:]
      probs = a[idx]
      # tl.logging.info("new %f" % probs)
      probs = probs / np.sum(probs)
      choice = np.random.choice(idx, p=probs)
      return choice
  
imports: import collections
  import os
  import random
  import re
  import subprocess
  import tempfile
  import warnings
  from collections import Counter
  import numpy
  import six
  import tensorflow
  from six.moves import urllib, xrange
  from tensorflow.python.platform import gfile
  import tensorlayer
  from tensorlayer.lazy_imports import LazyImport
label_desc: Use image node_id 5 for calling a global function with example usage: sample_top(a, top_k) and returns: choice