code: def generate_reference_for_test_dialog(dataset, data_root):
      vocab = {}
      with open(os.path.join(data_root, "vocab.txt"), "r") as f:
          p = f.read().splitlines()
          for i, x in enumerate(p):
              vocab[x] = i
  
      dts_train = dataset["train"]
      dts_val = dataset["val"]
      dts_test = dataset["test"]
  
      vectorizer = TfidfVectorizer(
          tokenizer=WordPunctTokenizer().tokenize, vocabulary=vocab
      )
  
      saved = []
      meta = []
      data = []
      tidx = {}
      for i in range(len(dts_test)):
          topic, cct, source, target = dts_test.get(i)
          meta.append((topic, cct, target))
          data.append(source)
  
      for i in range(len(dts_train)):
          topic, cct, source, target = dts_train.get(i)
          saved.append((topic, cct, target))
          data.append(source)
  
          if topic not in tidx:
              tidx[topic] = []
          tidx[topic].append(i)
  
      result = vectorizer.fit_transform(data)
      x = result[: len(dts_test)]
      y = result[len(dts_test) :]
  
      from tqdm import tqdm
      from sklearn.preprocessing import normalize
  
      y = normalize(y)
      x = normalize(x)
  
      dts_test.refs = []
      for i in tqdm(range(len(dts_test))):
          c = tidx[meta[i][0]]
          p = (y * x[i].T).toarray().reshape(-1)[c]
          d = p.argsort()
  
          cnt = 0
          refs = []
          for a in d[::-1]:
              if saved[a][1] == meta[i][1]:
                  refs.append(
                      " ".join(
                          WordPunctTokenizer().tokenize(saved[a][2][1])
                      )
                  )
                  cnt += 1
                  if cnt == 10:
                      break
  
          dts_test.refs.append(refs)
  
file_path: texar/examples/hierarchical_dialog/sw_loader.py
imports: import os
  import json
  from json_lines import reader
  from nltk.tokenize import WordPunctTokenizer
  from sklearn.feature_extraction.text import TfidfVectorizer
  import texar.tf
  from config_data import data_root
label_desc: Use image node_id 2 for calling a global function with example usage: generate_reference_for_test_dialog(dataset, data_root) without return types