Views
No views yet
| 属性 | 详情 |
|---|---|
| 参数量 | 15.65M |
| 架构 | nanoGPT(Decoder-only Transformer) |
| 词表大小 | 13113 |
| 上下文长度 | 512 tokens |
| 训练硬件 | Apple M4 Pro 48GB |
1import pickle
2import torch
3
4# 加载词表
5with open('meta.pkl', 'rb') as f:
6 meta = pickle.load(f)
7
8stoi = meta['stoi']
9itos = meta['itos']
10SPECIAL_TOKENS = ['<|user|>', '<|assistant|>', '<|end|>']
11
12def encode(text):
13 tokens = []
14 i = 0
15 while i < len(text):
16 matched = False
17 for special in SPECIAL_TOKENS:
18 if text[i:i+len(special)] == special:
19 tokens.append(stoi[special])
20 i += len(special)
21 matched = True
22 break
23 if not matched:
24 ch = text[i]
25 if ch in stoi:
26 tokens.append(stoi[ch])
27 i += 1
28 return tokens
29
30# 推理示例
31question = "什么是德州扑克中的位置优势?"
32prompt = f"<|user|>{question}<|end|><|assistant|>"