code: def get_vocabs(trees):
      label_vocab = Counter()
      word_vocab = Counter()
      for tree in trees:
          label_vocab.update([n.label for n in tree.nonterms()])
          word_vocab.update([l.label for l in tree.leaves()])
      words = ["_UNK_"] + [x for x, c in word_vocab.items() if c > 0]
      w2i = {w: i for i, w in enumerate(words)}
      return w2i, words
  
imports: import re
  import codecs
  import random
  from collections import Counter
label_desc: Use image node_id 2 for calling a global function with example usage: get_vocabs(trees) and returns: w2i,  words