File size: 1,860 Bytes
1fa4b25 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | """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())
|