import gradio as gr STYLE = """ @import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap'); * { padding: 0px; margin: 0px; box-sizing: border-box; font-size: 16px; } body { height: 100vh; width: 100vw; display: grid; align-items: center; font-family: 'Poppins', sans-serif; } .tree { width: 100%; height: auto; text-align: center; } .tree ul { padding-top: 20px; position: relative; transition: .5s; } .tree li { display: flex; flex-direction:row; text-align: center; list-style-type: none; position: relative; padding: 10px; transition: .5s; } .tree li::before, .tree li::after { content: ''; position: absolute; top: 0; right: 50%; border-top: 1px solid #ccc; width: 51%; height: 10px; } .tree li::after { right: auto; left: 50%; border-left: 1px solid #ccc; } .tree li:only-child::after, .tree li:only-child::before { display: none; } .tree li:only-child { padding-top: 0; } .tree li:first-child::before, .tree li:last-child::after { border: 0 none; } .tree li:last-child::before { border-right: 1px solid #ccc; border-radius: 0 5px 0 0; -webkit-border-radius: 0 5px 0 0; -moz-border-radius: 0 5px 0 0; } .tree li:first-child::after { border-radius: 5px 0 0 0; -webkit-border-radius: 5px 0 0 0; -moz-border-radius: 5px 0 0 0; } .tree ul ul::before { content: ''; position: absolute; top: 0; left: 50%; border-left: 1px solid #ccc; width: 0; height: 20px; } .tree li a { border: 1px solid #ccc; padding: 10px; display: inline-grid; border-radius: 5px; text-decoration-line: none; border-radius: 5px; transition: .5s; } .tree li a img { width: 50px; height: 50px; margin-bottom: 10px !important; border-radius: 100px; margin: auto; } .tree li a span { border: 1px solid #ccc; border-radius: 5px; color: #666; padding: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; font-weight: 500; } /*Hover-Section*/ .tree li a:hover, .tree li a:hover i, .tree li a:hover span, .tree li a:hover+ul li a { background: #c8e4f8; color: #000; border: 1px solid #94a0b4; } .tree li a:hover+ul li::after, .tree li a:hover+ul li::before, .tree li a:hover+ul::before, .tree li a:hover+ul ul::before { border-color: #94a0b4; } """ from transformers import GPT2Tokenizer, AutoModelForCausalLM import numpy as np tokenizer = GPT2Tokenizer.from_pretrained("gpt2") model = AutoModelForCausalLM.from_pretrained("gpt2") tokenizer.pad_token_id = tokenizer.eos_token_id def display_top_k_tokens(scores, sequences, beam_indices): display = "
Sequence {i}: {tokenizer.batch_decode(sequence)}
Token | Probability |
---|---|
Step {step} | ===== |
{tokenizer.decode([token_idx])} | {step_scores[current_beam, token_idx]} |
{tokenizer.decode([token_idx])} | {step_scores[current_beam, token_idx]} |
{token}
" html_content += node["table"] if node["table"] is not None else "" html_content += "" if len(node["children"].keys()) > 0: html_content += "Token | Probability |
---|---|
{token} | {scores[token_idx]} |