File size: 988 Bytes
804b9f6
 
ef64719
 
804b9f6
ef64719
 
 
84e0a22
 
ef64719
 
 
 
 
 
 
 
 
702b0a9
 
84e0a22
ef64719
84e0a22
804b9f6
 
 
 
 
9cb7743
84e0a22
 
804b9f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gradio as gr
import gem_metrics
from datasets import load_dataset
import random

random.seed(42)

raw_datasets = load_dataset("eli5")
validation_len = len(raw_datasets["validation_eli5"])
random_insts = [random.randint(0, validation_len) for _ in range(10)] 
questions = []
q2ref = {}
for inst in random_insts:
  question = raw_datasets["validation_eli5"][inst]["title"]
  ref = raw_datasets["validation_eli5"][inst]["answers"]["text"]
  questions.append(question)
  q2ref[question] = ref

def calc_rouge_score(og_question, pred):
    if pred is None:
       return {}
    preds = gem_metrics.texts.Predictions([pred])
    gold = q2ref[og_question]
    refs = gem_metrics.texts.References([gold])
    result = gem_metrics.compute(preds, refs, metrics_list=['bleu', 'rouge'])
    return result

iface = gr.Interface(
    fn=calc_rouge_score,
    inputs=[gr.Textbox(placeholder=questions[0]), "text"],
    outputs=["text"],
    examples=[[item] for item in questions])
iface.launch()