Nova-school commited on
Commit
a6bf6e3
·
verified ·
1 Parent(s): ee5bc33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -10
app.py CHANGED
@@ -43,19 +43,12 @@ def Page():
43
  solara.Markdown(f'{spans1}')
44
  outputs = model.generate(tokens, max_new_tokens=1, output_scores=True, return_dict_in_generate=True, pad_token_id=tokenizer.eos_token_id)
45
  scores = F.softmax(outputs.scores[0], dim=-1)
46
- top_10 = torch.topk(scores, 10)
47
- bottom_10 = torch.topk(scores, 10, largest=False)
48
  df = pd.DataFrame()
49
- d2 = pd.DataFrame()
50
  df["probs"] = top_10.values[0]
51
- d2["probs"] = bottom_10.values[0]
52
  df["probs"] = [f"{value:.2%}" for value in df["probs"].values]
53
- d2["probs"] = [f"{value:.2%}" for value in d2["probs"].values]
54
- df["next token ID"] = [top_10.indices[0][i].numpy() for i in range(10)]
55
- d2["next token ID"] = [bottom_10.indices[0][i].numpy() for i in range(10)]
56
- df["predicted next token"] = [tokenizer.decode(top_10.indices[0][i]) for i in range(10)]
57
- d2["predicted next token"] = [tokenizer.decode(bottom_10.indices[0][i]) for i in range(10)]
58
  solara.Markdown("###Prediction")
59
  solara.DataFrame(df, items_per_page=10, cell_actions=cell_actions)
60
- solara.DataFrame(d2, items_per_page=10, cell_actions=cell_actions)
61
  Page()
 
43
  solara.Markdown(f'{spans1}')
44
  outputs = model.generate(tokens, max_new_tokens=1, output_scores=True, return_dict_in_generate=True, pad_token_id=tokenizer.eos_token_id)
45
  scores = F.softmax(outputs.scores[0], dim=-1)
46
+ top_10 = torch.topk(scores, 100)
 
47
  df = pd.DataFrame()
 
48
  df["probs"] = top_10.values[0]
 
49
  df["probs"] = [f"{value:.2%}" for value in df["probs"].values]
50
+ df["next token ID"] = [top_10.indices[0][i].numpy() for i in range(100)]
51
+ df["predicted next token"] = [tokenizer.decode(top_10.indices[0][i]) for i in range(100)]
 
 
 
52
  solara.Markdown("###Prediction")
53
  solara.DataFrame(df, items_per_page=10, cell_actions=cell_actions)
 
54
  Page()