Eric Mitchell commited on
Commit
93798d6
1 Parent(s): e2893d0

Lots of changes.

Browse files
Files changed (1) hide show
  1. app.py +65 -8
app.py CHANGED
@@ -1,15 +1,72 @@
1
  from turtle import onclick
2
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  def reset():
5
- st.write("Reset clicked!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- memory = st.text_area(
8
- label="Edits applied",
9
- value="Who is the UK PM? Boris Johnson\nWhat team does Messi play for? PSG",
10
- help="The are the edits that have been applied to the original model.")
11
 
12
- reset = st.button("Reset edits", on_click=reset)
 
 
 
 
 
 
 
 
 
13
 
14
- edit_input = st.text_input("Edit input", placeholder="e.g., 'What is the tallest mountain on Earth?'")
15
- edit_label = st.text_input("Edit label", placeholder="e.g., 'Denali'", help="The desired output of the model for the edit input")
 
1
  from turtle import onclick
2
  import streamlit as st
3
+ import pandas as pd
4
+
5
+ EDIT_ALGS = [
6
+ "MEND: Model editor networks using gradient decomposition [Mitchell et al., 2021]",
7
+ "SERAC: Semi-parametric editing with a retrieval-augmented counterfactual model [Mitchell et al., 2022]",
8
+ "ENN: Editable Neural Networks [Sinitsin et al., 2020]",
9
+ "KE: KnowledgeEditor [De Cao et al., 2020]",
10
+ "Fine-tuning",
11
+ "Lookup Cache"
12
+ ]
13
+
14
+ st.title("Model editing demo")
15
+
16
+ # https://discuss.streamlit.io/t/simple-example-of-persistence-and-waiting-for-input/2111
17
+ @st.cache(allow_output_mutation=True)
18
+ def Edits():
19
+ return pd.DataFrame([], columns=["Edit input", "Edit label"])
20
+
21
+ @st.cache(allow_output_mutation=True)
22
+ def ModelOutput():
23
+ return pd.DataFrame([], columns=["Input", "Generation", "Edits applied"])
24
+
25
+ edits = Edits()
26
+ model_outputs = ModelOutput()
27
 
28
  def reset():
29
+ edits.drop(edits.index, inplace=True)
30
+ model_outputs.drop(edits.index, inplace=True)
31
+ current_edit_alg = str(alg_selector)
32
+ st.write(current_edit_alg)
33
+ ############# Need to reset the model here (and maybe show progress spinner?)
34
+
35
+ def apply_edit():
36
+ edits.loc[len(edits)] = [str(edit_input), str(edit_label)]
37
+
38
+ def sample_model():
39
+ model_outputs.loc[len(model_outputs)] = [str(test_input), "blah blah blah", len(edits)]
40
+
41
+ alg_selector = st.selectbox("Editing algorithm:", EDIT_ALGS, on_change=reset)
42
+
43
+ st.write("Edits applied so far:")
44
+ st.table(edits)
45
+ st.button("Reset model", on_click=reset)
46
+
47
+ st.markdown("***")
48
+
49
+ col1, col2, col3 = st.columns([3, 2, 1])
50
+ with col1:
51
+ edit_input = st.text_input("Edit input:", placeholder="e.g., 'What is the tallest mountain on Earth?'")
52
+ with col2:
53
+ edit_label = st.text_input("Edit target:", placeholder="e.g., 'Denali'", help="The desired output of the model for the edit input")
54
+ with col3:
55
+ st.markdown("##")
56
+ edit_button = st.button("Apply edit", on_click=apply_edit)
57
 
58
+ st.markdown("***")
 
 
 
59
 
60
+ col1, col2 = st.columns([5, 1])
61
+ with col1:
62
+ if len(edits) == 0:
63
+ title = "Input to sample from *unedited* model:"
64
+ else:
65
+ title = f"Input to sample from *edited* model:"
66
+ test_input = st.text_input(title, placeholder="e.g., 'What is the earth's tallest mountain?'")
67
+ with col2:
68
+ st.markdown("##")
69
+ generate_button = st.button("Generate", on_click=sample_model)
70
 
71
+ st.write("Model generation history:")
72
+ st.table(model_outputs)