gsarti commited on
Commit
fbd70bc
β€’
1 Parent(s): 686cbc9

Initial commit

Browse files
Files changed (3) hide show
  1. README.md +3 -3
  2. app.py +39 -0
  3. requirements.txt +1 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: Pecore
3
- emoji: 🐒
4
- colorFrom: red
5
- colorTo: red
6
  sdk: gradio
7
  sdk_version: 4.15.0
8
  app_file: app.py
 
1
  ---
2
  title: Pecore
3
+ emoji: πŸ‘ πŸ‘
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: gradio
7
  sdk_version: 4.15.0
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from inseq.commands.attribute_context.attribute_context import (
4
+ AttributeContextArgs,
5
+ attribute_context,
6
+ visualize_attribute_context,
7
+ )
8
+
9
+
10
+ def run_pecore(input_current_text, input_context_text):
11
+ lm_rag_prompting_example = AttributeContextArgs(
12
+ model_name_or_path="gsarti/cora_mgen",
13
+ input_context_text=input_context_text,
14
+ input_current_text=f"query: {input_current_text}",
15
+ output_template="{current}",
16
+ input_template="{current} passage: {context} answer:",
17
+ attributed_fn="contrast_prob_diff",
18
+ show_viz=False,
19
+ context_sensitivity_std_threshold=0,
20
+ )
21
+ out = attribute_context(lm_rag_prompting_example)
22
+ html = visualize_attribute_context(out, return_html=True)
23
+ return html
24
+
25
+
26
+ demo = gr.Interface(
27
+ fn=run_pecore,
28
+ inputs=["text", "text"],
29
+ outputs="html",
30
+ title="πŸ‘ Plausibility Evaluation of Context Reliance (PECoRe) πŸ‘",
31
+ 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>.""",
32
+ examples=[
33
+ [
34
+ "When was Banff National Park established?",
35
+ "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.",
36
+ ]
37
+ ],
38
+ )
39
+ demo.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ git+https://github.com/inseq-team/inseq.git@main