Spaces:
Running
Running
Download modules/generation.py from Ilaa-1505/llm-visualizer: direct link, hf CLI and curl.
- Browser
- Download file 392 Bytes
-
https://huggingface.co/spaces/Ilaa-1505/llm-visualizer/resolve/main/modules/generation.py
- Command line
-
hf download hf://spaces/Ilaa-1505/llm-visualizer/modules/generation.py
-
curl -L -o generation.py https://huggingface.co/spaces/Ilaa-1505/llm-visualizer/resolve/main/modules/generation.py
392 Bytes
| from modules.next_token import get_next_token_probs | |
| def get_next_token(text, model, tokenizer, temperature, rep_penalty): | |
| tokens, probs, entropy = get_next_token_probs( | |
| text, model, tokenizer, temperature, top_k=4, rep_penalty=rep_penalty | |
| ) | |
| high_prob = [tokens[0],probs[0]] | |
| alternatives = list(zip(tokens[1:], probs[1:])) | |
| return high_prob, alternatives, entropy | |