code: def calc_reward(refs, hypo, unk_id, metric):
      """
      calculate the reward given hypo and refs and will return
      bleu score if metric is 'bleu' or return
      sum of (Rouge-1, Rouge-2, Rouge-L) if metric is 'rouge'
      """
      if len(hypo) == 0 or len(refs[0]) == 0:
          return 0.0
  
      for i in range(len(hypo)):
          assert isinstance(hypo[i], int)
          if hypo[i] == unk_id:
              hypo[i] = -1
  
      if metric == "bleu":
          return 0.01 * sentence_bleu(
              references=refs, hypothesis=hypo, smooth=True
          )
      else:
          ref_str = " ".join([str(word) for word in refs[0]])
          hypo_str = " ".join([str(word) for word in hypo])
          rouge_scores = rouge.get_scores(
              hyps=[hypo_str], refs=[ref_str], avg=True
          )
          return sum(
              [value["f"] for key, value in rouge_scores.items()]
          )
  
file_path: texar/examples/seq2seq_exposure_bias/interpolation_helper.py
imports: import tensorflow
  import numpy
  from tensorflow_probability import distributions
  from tensorflow.contrib.seq2seq import SampleEmbeddingHelper
  from texar.tf.evals.bleu import sentence_bleu
  from rouge import Rouge
label_desc: Use image node_id 1 for calling a global function with example usage: calc_reward(refs, hypo, unk_id, metric) and returns: int, unknown, sum