patpizio commited on
Commit
e5edf10
·
1 Parent(s): 5cf0970

Remove .cpu() instances

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -9,8 +9,8 @@ def top_token_ids(outputs, threshold=-np.inf):
9
  "Returns the index of the tokens whose score exceeds a threshold, for each output step"
10
  indexes = []
11
  for tensor in outputs['scores']:
12
- candidates = np.argwhere(tensor.flatten().cpu() > threshold).numpy()[0]
13
- ordering_mask = np.argsort(tensor[0][candidates].cpu())
14
  candidates = candidates[ordering_mask]
15
  if not isinstance(candidates, np.ndarray):
16
  indexes.append(np.array([candidates]))
@@ -24,7 +24,7 @@ def plot_word_scores(top_token_ids, outputs, tokenizer, boolq=False, width=600):
24
  fig.append_trace(
25
  go.Bar(
26
  y=tokenizer.convert_ids_to_tokens(candidates),
27
- x=outputs['scores'][step][0][candidates].cpu(),
28
  orientation='h'
29
  ),
30
  row=step+1, col=1
 
9
  "Returns the index of the tokens whose score exceeds a threshold, for each output step"
10
  indexes = []
11
  for tensor in outputs['scores']:
12
+ candidates = np.argwhere(tensor.flatten() > threshold).numpy()[0]
13
+ ordering_mask = np.argsort(tensor[0][candidates])
14
  candidates = candidates[ordering_mask]
15
  if not isinstance(candidates, np.ndarray):
16
  indexes.append(np.array([candidates]))
 
24
  fig.append_trace(
25
  go.Bar(
26
  y=tokenizer.convert_ids_to_tokens(candidates),
27
+ x=outputs['scores'][step][0][candidates],
28
  orientation='h'
29
  ),
30
  row=step+1, col=1