def eval_rouge(in_path): print "Using pythonrouge package for evaluation." rouge = PythonROUGE(ROUGE_dir, n_gram=2, ROUGE_SU4=False, ROUGE_L=True, stemming=True, stopwords=False, length_limit=True, length=100, word_level=True, use_cf=True, cf=95, ROUGE_W=False, ROUGE_W_Weight=1.2, scoring_formula="average", resampling=False, samples=1000, favor=False, p=0.5) # pdb.set_trace() num_samples = 0 summary, reference = [], [] with open(in_path, "r") as in_file: for l in in_file.readlines(): sys_start = l.find(sys_tag) + len(sys_tag) sys_end = l.find(ref_tag) sys_str = l[sys_start:sys_end].strip() ref_start = sys_end + len(ref_tag) ref_str = l[ref_start:].strip() sys_sent_list = sys_str.split(sentence_sep) ref_sent_list = ref_str.split(sentence_sep) summary.append([sys_sent_list]) reference.append([ref_sent_list]) num_samples += 1 start_time = time.time() # Evaluate ROUGE using pythonrouge package print rouge.evaluate(summary, reference) total_time = time.time() - start_time time_per_eval = total_time / num_samples print "Takes %f seconds to evaluate %d samples, avg %fs." % ( total_time, num_samples, time_per_eval)
def generate_thread(doc_summary_queue, output_queue): rouge = PythonROUGE(ROUGE_path, n_gram=2, ROUGE_SU4=False, ROUGE_L=False, stemming=True, stopwords=False, length_limit=False, length=75, word_level=False, use_cf=True, cf=95, ROUGE_W=False, scoring_formula="average", resampling=False, samples=1000, favor=False, p=0.5) count = 0 while not doc_summary_queue.empty(): url, doc_sents, ref_sents = doc_summary_queue.get() try: selected, score = greedy_selection(doc_sents, ref_sents, rouge) # print selected, score except Exception as e: print e continue result = DocSummary(url, doc_sents, ref_sents, selected, score) output_queue.put(result) count += 1 if count % 100 == 0: print "Processed %d documents." % count
"enc_layers, enc_num_hidden, emb_dim, pos_emb_dim," "doc_repr_dim, word_conv_k_sizes, word_conv_filter," "min_num_input_sents, min_num_words_sent," "max_grad_norm, decay_step, decay_rate," "trg_weight_norm, train_mode, mlp_num_hidden, rl_coef") rouge = PythonROUGE( ROUGE_dir, n_gram=2, ROUGE_SU4=False, ROUGE_L=True, stemming=True, stopwords=False, length_limit=False, length=75, word_level=False, use_cf=True, cf=95, ROUGE_W=False, ROUGE_W_Weight=1.2, scoring_formula="average", resampling=False, samples=1000, favor=False, p=0.5) def compute_rouge(item): system_sents = item[0] reference_sents = item[1]