code: def get_pair_statistics(vocab):
      """Count frequency of all symbol pairs, and create index"""
  
      # data structure of pair frequencies
      stats = defaultdict(int)
  
      # index from pairs to words
      indices = defaultdict(lambda: defaultdict(int))
  
      for i, (word, freq) in enumerate(vocab):
          prev_char = word[0]
          for char in word[1:]:
              stats[prev_char, char] += freq
              indices[prev_char, char][i] += 1
              prev_char = char
  
      return stats, indices
  
file_path: OpenNMT-py/tools/learn_bpe.py
imports: from __future__ import unicode_literals
  import sys
  import codecs
  import re
  import copy
  import argparse
  from collections import defaultdict, Counter
  from io import open
label_desc: Use image node_id 4 for calling a global function with example usage: get_pair_statistics(vocab) and returns: stats,  indices