code: def generate_hamming_distance_payoff_distribution(
      max_sent_len, vocab_size, tau=1.0
  ):
      """compute the q distribution for Hamming Distance (substitution only) as in the RAML paper"""
      probs = dict()
      Z_qs = dict()
      for sent_len in range(1, max_sent_len + 1):
          counts = [1.0]  # e = 0, count = 1
          for e in range(1, sent_len + 1):
              # apply the rescaling trick as in https://gist.github.com/norouzi/8c4d244922fa052fa8ec18d8af52d366
              count = (
                  comb(sent_len, e)
                  * math.exp(-e / tau)
                  * ((vocab_size - 1) ** (e - e / tau))
              )
              counts.append(count)
  
          Z_qs[sent_len] = Z_q = sum(counts)
          prob = [count / Z_q for count in counts]
          probs[sent_len] = prob
  
          # print('sent_len=%d, %s' % (sent_len, prob))
  
      return probs, Z_qs
  
file_path: texar/examples/seq2seq_exposure_bias/utils/raml_samples_generation/process_samples.py
imports: from nltk.translate.bleu_score import sentence_bleu
  from nltk.translate.bleu_score import SmoothingFunction
  import sys
  import re
  import argparse
  import torch
  from util import read_corpus
  import numpy
  from scipy.misc import comb
  from vocab import Vocab, VocabEntry
  import math
  from rouge import Rouge
label_desc: Use image node_id 7 for calling a global function with example usage: generate_hamming_distance_payoff_distribution(max_sent_len, vocab_size, tau) and returns: probs,  Z_qs