"""本课独立实验；在仓库根目录执行 .venv/bin/python lessons/05/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)

x = torch.arange(12, dtype=torch.float32).view(2, 3, 2)
w = torch.tensor([[1.0, 0.0, 2.0, 1.0], [0.0, 1.0, 1.0, 2.0]])
show('输入 [批,字,特征]', list(x.shape))
show('变换 [入,出]', list(w.shape))
show('输出尺寸', list((x @ w).shape))
show('第一首第一个字的输出', (x @ w)[0, 0].tolist())
