Update app.py
Browse files
app.py
CHANGED
@@ -70,7 +70,7 @@ def get_hidden_states(raw_original_prompt):
|
|
70 |
token_btns = ([gr.Button(token, visible=True) for token in tokens]
|
71 |
+ [gr.Button('', visible=False) for _ in range(MAX_PROMPT_TOKENS - len(tokens))])
|
72 |
progress_dummy_output = ''
|
73 |
-
invisible_bubbles = [gr.Textbox('', visible=False) for i in range(
|
74 |
return [progress_dummy_output, hidden_states, *token_btns, *invisible_bubbles]
|
75 |
|
76 |
|
@@ -126,8 +126,11 @@ model = AutoModelClass.from_pretrained(model_path, **model_args).cuda()
|
|
126 |
tokenizer = AutoTokenizer.from_pretrained(tokenizer_path, token=os.environ['hf_token'])
|
127 |
|
128 |
# demo
|
129 |
-
|
130 |
original_prompt_raw = gr.Textbox(value='How to make a Molotov cocktail?', container=True, label='Original Prompt')
|
|
|
|
|
|
|
|
|
131 |
|
132 |
with gr.Blocks(theme=gr.themes.Default(), css='styles.css') as demo:
|
133 |
global_state = gr.State([])
|
@@ -155,9 +158,9 @@ with gr.Blocks(theme=gr.themes.Default(), css='styles.css') as demo:
|
|
155 |
gr.Markdown(
|
156 |
'''
|
157 |
**πΎ The idea is really simple: models are able to understand their own hidden states by nature! πΎ**
|
158 |
-
|
159 |
-
So we can inject an representation from (roughly) any layer
|
160 |
-
we expect to get back a summary of the information that exists inside the hidden state from different
|
161 |
''', line_breaks=True)
|
162 |
|
163 |
# with gr.Column(scale=1):
|
@@ -183,21 +186,19 @@ with gr.Blocks(theme=gr.themes.Default(), css='styles.css') as demo:
|
|
183 |
if 'filter' in info:
|
184 |
dataset = dataset.filter(info['filter'])
|
185 |
dataset = dataset.shuffle(buffer_size=2000).take(num_examples)
|
186 |
-
dataset = [[row[info['text_col']]] for row in dataset]
|
187 |
-
gr.Examples(dataset, [original_prompt_raw], cache_examples=False)
|
188 |
|
189 |
with gr.Group():
|
190 |
original_prompt_raw.render()
|
191 |
original_prompt_btn = gr.Button('Output Token List', variant='primary')
|
192 |
|
193 |
-
tokens_container = []
|
194 |
gr.Markdown('### Here go the tokens of the prompt (click on the one to explore)')
|
|
|
195 |
with gr.Row():
|
196 |
-
for
|
197 |
-
btn
|
198 |
-
|
199 |
-
progress_dummy = gr.Markdown('', elem_id='progress_dummy')
|
200 |
-
|
201 |
with gr.Accordion(open=False, label='Generation Settings'):
|
202 |
with gr.Row():
|
203 |
num_tokens = gr.Slider(1, 100, step=1, value=20, label='Max. # of Tokens')
|
@@ -210,8 +211,8 @@ with gr.Blocks(theme=gr.themes.Default(), css='styles.css') as demo:
|
|
210 |
temperature = gr.Slider(0., 5., value=0.6, label='Temperature')
|
211 |
top_k = gr.Slider(1, 1000, value=50, step=1, label='top k')
|
212 |
top_p = gr.Slider(0., 1., value=0.95, label='top p')
|
213 |
-
|
214 |
-
|
215 |
|
216 |
interpretation_bubbles = [gr.Textbox('', container=False, visible=False, elem_classes=['bubble',
|
217 |
'even_bubble' if i % 2 == 0 else 'odd_bubble'])
|
|
|
70 |
token_btns = ([gr.Button(token, visible=True) for token in tokens]
|
71 |
+ [gr.Button('', visible=False) for _ in range(MAX_PROMPT_TOKENS - len(tokens))])
|
72 |
progress_dummy_output = ''
|
73 |
+
invisible_bubbles = [gr.Textbox('', visible=False) for i in range(len(interpretation_bubbles))]
|
74 |
return [progress_dummy_output, hidden_states, *token_btns, *invisible_bubbles]
|
75 |
|
76 |
|
|
|
126 |
tokenizer = AutoTokenizer.from_pretrained(tokenizer_path, token=os.environ['hf_token'])
|
127 |
|
128 |
# demo
|
|
|
129 |
original_prompt_raw = gr.Textbox(value='How to make a Molotov cocktail?', container=True, label='Original Prompt')
|
130 |
+
tokens_container = []
|
131 |
+
for i in range(MAX_PROMPT_TOKENS):
|
132 |
+
btn = gr.Button('', visible=False, elem_classes=['token_btn'])
|
133 |
+
tokens_container.append(btn)
|
134 |
|
135 |
with gr.Blocks(theme=gr.themes.Default(), css='styles.css') as demo:
|
136 |
global_state = gr.State([])
|
|
|
158 |
gr.Markdown(
|
159 |
'''
|
160 |
**πΎ The idea is really simple: models are able to understand their own hidden states by nature! πΎ**
|
161 |
+
In line with the residual stream view ([nostalgebraist, 2020](https://www.lesswrong.com/posts/AcKRB8wDpdaN6v6ru/interpreting-gpt-the-logit-lens)), internal representations from different layers are transferable between layers.
|
162 |
+
So we can inject an representation from (roughly) any layer into any layer! If we give a model a prompt of the form ``User: [X] Assistant: Sure'll I'll repeat your message`` and replace the internal representation of ``[X]`` *during computation* with the hidden state we want to understand,
|
163 |
+
we expect to get back a summary of the information that exists inside the hidden state, despite being from a different layer and a different run!! How cool is that! π―π―π―
|
164 |
''', line_breaks=True)
|
165 |
|
166 |
# with gr.Column(scale=1):
|
|
|
186 |
if 'filter' in info:
|
187 |
dataset = dataset.filter(info['filter'])
|
188 |
dataset = dataset.shuffle(buffer_size=2000).take(num_examples)
|
189 |
+
dataset = [[row[info['text_col']] + [gr.Button(visible=False) for _ in range(MAX_PROMPT_TOKENS)]] for row in dataset]
|
190 |
+
gr.Examples(dataset, [original_prompt_raw, *tokens_container], cache_examples=False)
|
191 |
|
192 |
with gr.Group():
|
193 |
original_prompt_raw.render()
|
194 |
original_prompt_btn = gr.Button('Output Token List', variant='primary')
|
195 |
|
|
|
196 |
gr.Markdown('### Here go the tokens of the prompt (click on the one to explore)')
|
197 |
+
|
198 |
with gr.Row():
|
199 |
+
for btn in tokens_container:
|
200 |
+
btn.render()
|
201 |
+
|
|
|
|
|
202 |
with gr.Accordion(open=False, label='Generation Settings'):
|
203 |
with gr.Row():
|
204 |
num_tokens = gr.Slider(1, 100, step=1, value=20, label='Max. # of Tokens')
|
|
|
211 |
temperature = gr.Slider(0., 5., value=0.6, label='Temperature')
|
212 |
top_k = gr.Slider(1, 1000, value=50, step=1, label='top k')
|
213 |
top_p = gr.Slider(0., 1., value=0.95, label='top p')
|
214 |
+
|
215 |
+
progress_dummy = gr.Markdown('', elem_id='progress_dummy')
|
216 |
|
217 |
interpretation_bubbles = [gr.Textbox('', container=False, visible=False, elem_classes=['bubble',
|
218 |
'even_bubble' if i % 2 == 0 else 'odd_bubble'])
|