Spaces:
Runtime error
Runtime error
taka-yamakoshi
commited on
Commit
·
3052d18
1
Parent(s):
2f141a3
debug
Browse files
app.py
CHANGED
@@ -132,7 +132,7 @@ def separate_options(option_locs):
|
|
132 |
assert np.sum(np.diff(option_locs)>1)==1
|
133 |
sep = list(np.diff(option_locs)>1).index(1)+1
|
134 |
option_1_locs, option_2_locs = option_locs[:sep], option_locs[sep:]
|
135 |
-
assert np.all(np.diff(option_1_locs)==1) and np.all(np.diff(
|
136 |
return option_1_locs, option_2_locs
|
137 |
|
138 |
def mask_out(input_ids,pron_locs,option_locs,mask_id):
|
@@ -215,14 +215,14 @@ if __name__=='__main__':
|
|
215 |
st.write(' '.join([tokenizer.decode([token]) for toke in token_ids]))
|
216 |
|
217 |
if st.session_state['page_status'] == 'finish_debug':
|
218 |
-
try:
|
219 |
-
assert len(input_ids_1) == len(input_ids_2)
|
220 |
-
except AssertionError:
|
221 |
-
show_instruction('Please make sure the number of tokens match between Sentence 1 and Sentence 2', fontsize=12)
|
222 |
-
input_ids = torch.tensor([*[input_ids_1 for _ in range(num_heads)],*[input_ids_2 for _ in range(num_heads)]])
|
223 |
interventions = create_interventions(16,'all',num_layers=num_layers,num_heads=num_heads)
|
224 |
-
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
|
228 |
preds_0 = [torch.multinomial(torch.exp(probs), num_samples=1).squeeze(dim=-1) for probs in logprobs[0][1:-1]]
|
|
|
132 |
assert np.sum(np.diff(option_locs)>1)==1
|
133 |
sep = list(np.diff(option_locs)>1).index(1)+1
|
134 |
option_1_locs, option_2_locs = option_locs[:sep], option_locs[sep:]
|
135 |
+
assert np.all(np.diff(option_1_locs)==1) and np.all(np.diff(option_2_locs)==1)
|
136 |
return option_1_locs, option_2_locs
|
137 |
|
138 |
def mask_out(input_ids,pron_locs,option_locs,mask_id):
|
|
|
215 |
st.write(' '.join([tokenizer.decode([token]) for toke in token_ids]))
|
216 |
|
217 |
if st.session_state['page_status'] == 'finish_debug':
|
|
|
|
|
|
|
|
|
|
|
218 |
interventions = create_interventions(16,'all',num_layers=num_layers,num_heads=num_heads)
|
219 |
+
for masked_ids in [masked_ids_option_1, masked_ids_option_2]:
|
220 |
+
input_ids = torch.tensor([
|
221 |
+
*[masked_ids['sent_1'] for _ in range(num_heads)],
|
222 |
+
*[masked_ids['sent_2'] for _ in range(num_heads)]
|
223 |
+
])
|
224 |
+
outputs = SkeletonAlbertForMaskedLM(model,input_ids,interventions=interventions)
|
225 |
+
logprobs = F.log_softmax(outputs['logits'], dim = -1)
|
226 |
|
227 |
|
228 |
preds_0 = [torch.multinomial(torch.exp(probs), num_samples=1).squeeze(dim=-1) for probs in logprobs[0][1:-1]]
|