Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import torch.nn.functional as F
|
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
import gradio as gr
|
5 |
import pandas as pd
|
|
|
6 |
|
7 |
# Load model and tokenizer
|
8 |
model_ids = {
|
@@ -52,7 +53,7 @@ def compare_models(text, top_k=5):
|
|
52 |
topk_ids = topk.indices.tolist()
|
53 |
topk_scores = topk.values.tolist()
|
54 |
topk_tokens = tokenizer.convert_ids_to_tokens(topk_ids)
|
55 |
-
topk_probs = [round(
|
56 |
pair_list = [f"{tok} ({prob})" for tok, prob in zip(topk_tokens, topk_probs)]
|
57 |
topk_list.append(", ".join(pair_list))
|
58 |
|
|
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
import gradio as gr
|
5 |
import pandas as pd
|
6 |
+
import math
|
7 |
|
8 |
# Load model and tokenizer
|
9 |
model_ids = {
|
|
|
53 |
topk_ids = topk.indices.tolist()
|
54 |
topk_scores = topk.values.tolist()
|
55 |
topk_tokens = tokenizer.convert_ids_to_tokens(topk_ids)
|
56 |
+
topk_probs = [round(math.exp(s), 4) for s in topk_scores]
|
57 |
pair_list = [f"{tok} ({prob})" for tok, prob in zip(topk_tokens, topk_probs)]
|
58 |
topk_list.append(", ".join(pair_list))
|
59 |
|