File size: 1,720 Bytes
fbd70bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
import gradio as gr

from inseq.commands.attribute_context.attribute_context import (
    AttributeContextArgs,
    attribute_context,
    visualize_attribute_context,
)


def run_pecore(input_current_text, input_context_text):
    lm_rag_prompting_example = AttributeContextArgs(
        model_name_or_path="gsarti/cora_mgen",
        input_context_text=input_context_text,
        input_current_text=f"query: {input_current_text}",
        output_template="{current}",
        input_template="{current} passage: {context} answer:",
        attributed_fn="contrast_prob_diff",
        show_viz=False,
        context_sensitivity_std_threshold=0,
    )
    out = attribute_context(lm_rag_prompting_example)
    html = visualize_attribute_context(out, return_html=True)
    return html


demo = gr.Interface(
    fn=run_pecore,
    inputs=["text", "text"],
    outputs="html",
    title="πŸ‘ Plausibility Evaluation of Context Reliance (PECoRe) πŸ‘",
    description="""Given a query and a context passed as inputs to a LM, PECoRe will identify which tokens in the generated response were dependant on context, and match them with context tokens contributing to their prediction. For more information, check out our <a href="https://openreview.net/forum?id=XTHfNGI3zT" target='_blank'>ICLR 2024 paper</a>.""",
    examples=[
        [
            "When was Banff National Park established?",
            "Banff National Park is Canada's oldest national park, established in 1885 as Rocky Mountains Park. Located in Alberta's Rocky Mountains, 110–180 kilometres (68–112 mi) west of Calgary, Banff encompasses 6,641 square kilometres (2,564 sq mi) of mountainous terrain.",
        ]
    ],
)
demo.launch(share=True)