code: def make_vocab(dataset, max_vocab_size=20000, min_freq=2):
      counts = collections.defaultdict(int)
      for tokens, _ in dataset:
          for token in tokens:
              counts[token] += 1
  
      vocab = {"<eos>": 0, "<unk>": 1}
      for w, c in sorted(counts.items(), key=lambda x: (-x[1], x[0])):
          if len(vocab) >= max_vocab_size or c < min_freq:
              break
          vocab[w] = len(vocab)
      return vocab
  
file_path: chainer/examples/text_classification/nlp_utils.py
imports: import collections
  import io
  import numpy
  import chainer
label_desc: Use image node_id 3 for calling a global function with example usage: make_vocab(dataset, max_vocab_size, min_freq) and returns: vocab