code: def sample_from_hamming_distance_payoff_distribution(args):
      src_sents = read_corpus(args.src, "src")
      tgt_sents = read_corpus(
          args.tgt, "src"
      )  # do not read in <s> and </s>
      f_out = open(args.output, "w")
  
      vocab = torch.load(args.vocab)
      tgt_vocab = vocab.tgt
  
      payoff_prob, Z_qs = generate_hamming_distance_payoff_distribution(
          max(len(sent) for sent in tgt_sents),
          vocab_size=len(vocab.tgt),
          tau=args.temp,
      )
  
      for src_sent, tgt_sent in zip(src_sents, tgt_sents):
          tgt_samples = (
              []
          )  # make sure the ground truth y* is in the samples
          tgt_sent_len = (
              len(tgt_sent) - 3
          )  # remove <s> and </s> and ending period .
          tgt_ref_tokens = tgt_sent[1:-1]
          bleu_scores = []
  
          # sample an edit distances
          e_samples = np.random.choice(
              range(tgt_sent_len + 1),
              p=payoff_prob[tgt_sent_len],
              size=args.sample_size,
              replace=True,
          )
  
          for i, e in enumerate(e_samples):
              if e > 0:
                  # sample a new tgt_sent $y$
                  old_word_pos = np.random.choice(
                      range(1, tgt_sent_len + 1), size=e, replace=False
                  )
                  new_words = [
                      vocab.tgt.id2word[wid]
                      for wid in np.random.randint(
                          3, len(vocab.tgt), size=e
                      )
                  ]
                  new_tgt_sent = list(tgt_sent)
                  for pos, word in zip(old_word_pos, new_words):
                      new_tgt_sent[pos] = word
  
                  bleu_score = sentence_bleu(
                      [tgt_ref_tokens], new_tgt_sent[1:-1]
                  )
                  bleu_scores.append(bleu_score)
              else:
                  new_tgt_sent = list(tgt_sent)
                  bleu_scores.append(1.0)
  
              # print('y: %s' % ' '.join(new_tgt_sent))
              tgt_samples.append(new_tgt_sent)
  
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 6 for calling a global function with example usage: sample_from_hamming_distance_payoff_distribution(args) without return types