"""本课独立实验；在仓库根目录执行 .venv/bin/python lessons/19/experiment.py。"""
import sys, json, math
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
import torch
from torch import nn
from torch.nn import functional as F
from poetry_gpt.common import ROOT, DEFAULT_DATA, read_json, read_jsonl
from poetry_gpt.model import ModelConfig, PoetryGPT, CausalAttention, Block
from poetry_gpt.data import Tokenizer, SPECIAL, clean_record, keywords_for
from poetry_gpt.labs import show
torch.set_num_threads(2)
torch.manual_seed(26)

manifest = DEFAULT_DATA / 'manifest.json'
if manifest.exists():
    show('真实材料分卷', read_json(manifest)['split_counts'])
for train, val in [(7.2, 7.3), (5.1, 5.3), (3.2, 5.6)]:
    show('示意 学习/验证误差', [train, val])
print('最后一次学习误差下降而验证误差升高，应回看最佳验证版本；这三组数字是教学示意。')
