Download evaluate.py from Kat-AI/Kat: direct link, hf CLI and curl.
- Browser
- Download file 1.86 kB
-
https://huggingface.co/Kat-AI/Kat/resolve/main/evaluate.py
- Command line
-
hf download hf://Kat-AI/Kat/evaluate.py
-
curl -L -o evaluate.py https://huggingface.co/Kat-AI/Kat/resolve/main/evaluate.py
1.86 kB
| """Fixed probe prompts + val perplexity, so runs are comparable by eye. | |
| .venv/bin/python evaluate.py | |
| """ | |
| import math | |
| import sys | |
| import numpy as np | |
| import torch | |
| from chat import KatChat | |
| from config import DATA_DIR, ModelConfig, TrainConfig | |
| from train import estimate_loss, load_split | |
| PROBES = [ | |
| "hi", "hello, how are you?", "what's your name?", "what do you do?", | |
| "where do you live?", "do you like music?", "what time is it?", | |
| "i'm hungry", "can you help me?", "thank you", "see you later", | |
| "the weather is nice today", "i had a bad day", "do you have any hobbies?", | |
| "how much does it cost?", | |
| ] | |
| def main() -> None: | |
| kat = KatChat() | |
| print(f"checkpoint: step {kat.step}, val loss {kat.val_loss:.4f}, " | |
| f"perplexity {math.exp(kat.val_loss):.1f}\n") | |
| # Recompute val loss over more batches than training used, for a tighter number. | |
| tcfg = TrainConfig() | |
| tcfg.eval_batches = 200 | |
| torch.manual_seed(0) | |
| gen = torch.Generator().manual_seed(0) | |
| val_loss = estimate_loss(kat.model, load_split("val"), kat.cfg, tcfg, gen) | |
| print(f"val loss over {tcfg.eval_batches} batches: {val_loss:.4f} " | |
| f"(perplexity {math.exp(val_loss):.1f})\n") | |
| for temperature in (0.7, 0.9): | |
| print(f"--- temperature {temperature} " + "-" * 40) | |
| kat.temperature = temperature | |
| for probe in PROBES: | |
| kat.reset() | |
| print(f" you> {probe}\n kat> {kat.say(probe)}") | |
| print() | |
| # Multi-turn: does it stay coherent across a few exchanges? | |
| print("--- multi-turn (temperature 0.8) " + "-" * 27) | |
| kat.temperature, _ = 0.8, kat.reset() | |
| for turn in ["hi there", "what are you doing?", "that sounds fun", | |
| "do you want to come with me?"]: | |
| print(f" you> {turn}\n kat> {kat.say(turn)}") | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |