Spaces:
Runtime error
Runtime error
Eric Mitchell
commited on
Commit
·
902d725
1
Parent(s):
b3740e7
Updated intro text.
Browse files
app.py
CHANGED
@@ -8,29 +8,10 @@ EDIT_ALGS = [
|
|
8 |
"SERAC: Semi-parametric editing with a retrieval-augmented counterfactual model",
|
9 |
"ENN: Editable neural networks",
|
10 |
"KE: KnowledgeEditor",
|
11 |
-
"Fine-tuning",
|
12 |
-
"Lookup Cache"
|
13 |
]
|
14 |
|
15 |
-
st.title("Language Model Editing")
|
16 |
-
st.write("Choose an editing algorithm, apply some edits, and sample from the model to see how its behavior changes. You can sample the model at any time to see the \"before and after\" of the edits you apply.")
|
17 |
-
st.markdown("***")
|
18 |
-
|
19 |
-
# https://discuss.streamlit.io/t/simple-example-of-persistence-and-waiting-for-input/2111
|
20 |
-
@st.cache(allow_output_mutation=True)
|
21 |
-
def Edits():
|
22 |
-
return
|
23 |
-
|
24 |
-
@st.cache(allow_output_mutation=True)
|
25 |
-
def ModelOutput():
|
26 |
-
return
|
27 |
-
|
28 |
-
if "init" not in st.session_state:
|
29 |
-
# Perform first-time initialization
|
30 |
-
st.session_state.edits = pd.DataFrame([], columns=["Edit input", "Edit label"])
|
31 |
-
st.session_state.model_outputs = pd.DataFrame([], columns=["Input", "Generation", "Edits applied"])
|
32 |
-
st.session_state.init = True
|
33 |
-
|
34 |
def reset():
|
35 |
st.session_state.edits.drop(st.session_state.edits.index, inplace=True)
|
36 |
st.session_state.model_outputs.drop(st.session_state.edits.index, inplace=True)
|
@@ -43,8 +24,35 @@ def reset():
|
|
43 |
def apply_edit():
|
44 |
st.session_state.edits.loc[len(st.session_state.edits)] = [str(edit_input), str(edit_label)]
|
45 |
|
|
|
|
|
46 |
def sample_model():
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
col1, col2 = st.columns([5,1])
|
50 |
with col1:
|
@@ -56,8 +64,6 @@ with col2:
|
|
56 |
st.write("Edits applied so far:")
|
57 |
st.table(st.session_state.edits)
|
58 |
|
59 |
-
st.markdown("***")
|
60 |
-
|
61 |
col1, col2, col3 = st.columns([3, 2, 1])
|
62 |
with col1:
|
63 |
edit_input = st.text_input("Edit input:", placeholder="e.g., 'What is the tallest mountain on Earth?'")
|
|
|
8 |
"SERAC: Semi-parametric editing with a retrieval-augmented counterfactual model",
|
9 |
"ENN: Editable neural networks",
|
10 |
"KE: KnowledgeEditor",
|
11 |
+
"FT: Fine-tuning",
|
12 |
+
"LU: Lookup Cache"
|
13 |
]
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def reset():
|
16 |
st.session_state.edits.drop(st.session_state.edits.index, inplace=True)
|
17 |
st.session_state.model_outputs.drop(st.session_state.edits.index, inplace=True)
|
|
|
24 |
def apply_edit():
|
25 |
st.session_state.edits.loc[len(st.session_state.edits)] = [str(edit_input), str(edit_label)]
|
26 |
|
27 |
+
############# Actually do the edit to the model
|
28 |
+
|
29 |
def sample_model():
|
30 |
+
input_str = str(test_input)
|
31 |
+
model_output = "blah blah blah" ############## Actually sample the model
|
32 |
+
n_edits = len(st.session_state.edits)
|
33 |
+
alg_name = st.session_state.alg_selector
|
34 |
+
alg_abbrv = alg_name[:alg_name.index(":")]
|
35 |
+
st.session_state.model_outputs.loc[len(st.session_state.model_outputs)] = [input_str, model_output, n_edits, alg_abbrv]
|
36 |
+
|
37 |
+
################################
|
38 |
+
#### Backend initialization ####
|
39 |
+
################################
|
40 |
+
if "init" not in st.session_state:
|
41 |
+
st.session_state.edits = pd.DataFrame([], columns=["Edit input", "Edit label"])
|
42 |
+
st.session_state.model_outputs = pd.DataFrame([], columns=["Input", "Output", "N edits", "Alg"])
|
43 |
+
st.session_state.init = True
|
44 |
+
st.session_state.model = None ##############
|
45 |
+
|
46 |
+
|
47 |
+
########################
|
48 |
+
#### Interface code ####
|
49 |
+
########################
|
50 |
+
|
51 |
+
st.title("Language Model Editing")
|
52 |
+
st.markdown("The goal of this demo is to give you a sense of the *abilities* and *limitations* of existing methods for **editing** pre-trained language models. **Model editing** algorithms use a single input-output pair to update a pre-trained model's behavior for that input (and ideally, related inputs).")
|
53 |
+
st.markdown("This demo uses a [T5-large](https://huggingface.co/google/t5-large-ssm-nq) model fine-tuned on [Natural Questions](https://arxiv.org/pdf/2002.08910.pdf) as the base pre-trained model.")
|
54 |
+
st.write("You can choose from a variety of algorithms for model editing in the dropdown below. At the bottom of the page, you can query the model for whatever input you want before/after editing.")
|
55 |
+
st.markdown("***")
|
56 |
|
57 |
col1, col2 = st.columns([5,1])
|
58 |
with col1:
|
|
|
64 |
st.write("Edits applied so far:")
|
65 |
st.table(st.session_state.edits)
|
66 |
|
|
|
|
|
67 |
col1, col2, col3 = st.columns([3, 2, 1])
|
68 |
with col1:
|
69 |
edit_input = st.text_input("Edit input:", placeholder="e.g., 'What is the tallest mountain on Earth?'")
|