m-ric HF staff commited on
Commit
7dc5ad4
β€’
1 Parent(s): 4f6e1c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -59,8 +59,11 @@ def generate_and_visualize(prompt, num_tokens=10):
59
  max_logits, max_indices = torch.max(output_logits[0, -1, :], dim=-1)
60
 
61
  max_logits.backward(max_logits)
62
- relevance = input_embeds.grad.float().sum(-1).cpu()[0]
63
- all_relevances.append(relevance)
 
 
 
64
 
65
  next_token = max_indices.unsqueeze(0)
66
  generated_tokens_ids.append(next_token.item())
 
59
  max_logits, max_indices = torch.max(output_logits[0, -1, :], dim=-1)
60
 
61
  max_logits.backward(max_logits)
62
+ try:
63
+ relevance = input_embeds.grad.float().sum(-1).cpu()[0]
64
+ all_relevances.append(relevance)
65
+ except:
66
+ all_relevances.append(0)
67
 
68
  next_token = max_indices.unsqueeze(0)
69
  generated_tokens_ids.append(next_token.item())