afoolishman commited on
Commit
248c85b
·
verified ·
1 Parent(s): e8c38e4

Upload MODEL_CARD.md

Browse files
Files changed (1) hide show
  1. MODEL_CARD.md +201 -0
MODEL_CARD.md ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: mit
5
+ library_name: pytorch
6
+ tags:
7
+ - transformers-from-scratch
8
+ - encoder-decoder
9
+ - seq2seq
10
+ - ablation
11
+ - bpe
12
+ - rope
13
+ - gqa
14
+ - rmsnorm
15
+ - blt
16
+ - anlp
17
+ - ciphertext-decryption
18
+ datasets:
19
+ - custom (brown_cipher / brown_plain, ANLP Assignment 1)
20
+ metrics:
21
+ - accuracy
22
+ - bleu
23
+ - rouge
24
+ - levenshtein
25
+ pipeline_tag: text2text-generation
26
+ ---
27
+
28
+ # ANLP Assignment 1 — Encoder–Decoder Ablations (C1–C5)
29
+
30
+ This hub entry hosts checkpoints from a controlled ablation: map encrypted binary sequences (`brown_cipher.txt`) to English plaintext (`brown_plain.txt`). Configuration **C1** is the base model; **C2–C5** each change exactly one component.
31
+
32
+ ---
33
+
34
+ ## Model variants
35
+
36
+ | Config | Single change vs C1 | Architecture class |
37
+ |--------|---------------------|--------------------|
38
+ | **C1** | — (base) | `Seq2SeqTransformer` |
39
+ | **C2** | RoPE instead of sinusoidal PE | `Seq2SeqTransformer` |
40
+ | **C3** | GQA (8 Q, 2 KV) instead of MHA | `Seq2SeqTransformer` |
41
+ | **C4** | RMSNorm instead of LayerNorm | `Seq2SeqTransformer` |
42
+ | **C5** | Entropy-patched BLT instead of BPE | `BLTSeq2Seq` |
43
+
44
+ ### Shared hyperparameters
45
+
46
+ | Hyperparameter | Value |
47
+ |----------------|-------|
48
+ | `d_model` | 256 |
49
+ | Heads | 8 (C3: 2 KV heads) |
50
+ | Encoder / decoder layers | 4 / 4 |
51
+ | `d_ff` | 1024 |
52
+ | Dropout | 0.15 |
53
+ | Optimizer | AdamW, lr 1e-3, wd 0.01, betas (0.9, 0.98) |
54
+ | LR schedule | cosine + 400 warmup steps |
55
+ | Batch size | 64 |
56
+ | Chunk size | 256 characters (aligned cipher/plain) |
57
+ | Max epochs | 100 (C5 early-stopped later; best @ epoch 146) |
58
+ | Early stopping | patience 10 on val CE |
59
+ | Seed | 42 |
60
+ | Precision | AMP (fp16) |
61
+
62
+ **Tokenization**
63
+
64
+ - **C1–C4:** from-scratch BPE, vocab 1024 per side. Cipher: pack 8 bits → byte, then learn merges. Plain: character BPE. Artifacts: `cipher_bpe.json`, `plain_bpe.json`.
65
+ - **C5:** no BPE. Packed bytes + entropy patches (len 1–8, mean ≈ 4.2), hashed 2/3/4-gram features. Artifacts: `entropy_ngram.json`, `entropy_patcher.json`.
66
+
67
+ ---
68
+
69
+ ## Intended use
70
+
71
+ - **Primary:** course ablation / reproducibility for ANLP Assignment 1.
72
+ - **Task:** greedy decode ciphertext chunks → plaintext chunks.
73
+ - **Not intended for:** production MT, open-domain generation, or claiming a general “decrypt any cipher” system. The mapping is specific to this homework dataset.
74
+
75
+ ---
76
+
77
+ ## How to load weights
78
+
79
+ Checkpoints are raw PyTorch state dicts (`pytorch_model.bin`) plus `config.json`. They are **not** Hugging Face `transformers.AutoModel` checkpoints—load with the assignment code.
80
+
81
+ ```python
82
+ import json
83
+ import torch
84
+ from pathlib import Path
85
+
86
+ # after cloning / downloading this repo's `src/` onto PYTHONPATH
87
+ from models.transformer import Seq2SeqTransformer
88
+ from models.blt import BLTSeq2Seq
89
+ from tokenizer import BPETokenizer, PAD
90
+
91
+ hf_dir = Path("path/to/downloaded/hf") # folder with config.json + pytorch_model.bin
92
+ cfg = json.loads((hf_dir / "config.json").read_text())
93
+
94
+ if cfg.get("blt"):
95
+ model = BLTSeq2Seq(
96
+ d_model=cfg["d_model"],
97
+ n_heads=cfg["n_heads"],
98
+ n_kv_heads=cfg["n_kv_heads"],
99
+ n_encoder_layers=cfg["n_encoder_layers"],
100
+ n_decoder_layers=cfg["n_decoder_layers"],
101
+ d_ff=cfg["d_ff"],
102
+ dropout=cfg["dropout"],
103
+ patch_size=cfg["patch_size"],
104
+ n_local_layers=cfg["n_local_layers"],
105
+ n_local_heads=cfg["n_local_heads"],
106
+ pad_id=PAD,
107
+ )
108
+ else:
109
+ model = Seq2SeqTransformer(
110
+ src_vocab=cfg["src_vocab"],
111
+ tgt_vocab=cfg["tgt_vocab"],
112
+ d_model=cfg["d_model"],
113
+ n_heads=cfg["n_heads"],
114
+ n_kv_heads=cfg["n_kv_heads"],
115
+ n_encoder_layers=cfg["n_encoder_layers"],
116
+ n_decoder_layers=cfg["n_decoder_layers"],
117
+ d_ff=cfg["d_ff"],
118
+ dropout=cfg["dropout"],
119
+ pos_encoding=cfg["pos_encoding"],
120
+ attn_kind=cfg["attn_kind"],
121
+ norm_kind=cfg["norm_kind"],
122
+ pad_id=PAD,
123
+ )
124
+
125
+ state = torch.load(hf_dir / "pytorch_model.bin", map_location="cpu")
126
+ model.load_state_dict(state)
127
+ model.eval()
128
+ ```
129
+
130
+ ---
131
+
132
+ ## Training data
133
+
134
+ - **Source:** assignment corpus `brown_cipher.txt` / `brown_plain.txt` (5000 line pairs).
135
+ - **Split:** document-level 80/10/10, seed 42, **then** aligned 256-character chunks (~11.5k / 1.4k / 1.4k train/val/test).
136
+ - **Property:** `len(cipher)/8 == len(plain)` so packed cipher byte `i` aligns with plaintext character `i`.
137
+
138
+ ---
139
+
140
+ ## Evaluation
141
+
142
+ Greedy decoding only. Test metrics (1389 chunks):
143
+
144
+ | Config | Params | Best val CE | Epochs | Bit acc. (%) | Seq. acc. (%) | Lev. | BLEU |
145
+ |--------|--------|-------------|--------|--------------|---------------|------|------|
146
+ | C1 | 8.15M | 0.0294 | 100 | 97.06 | 73.43 | 0.58 | 97.87 |
147
+ | C2 | 8.15M | 0.0188 | 82 | **99.01** | **85.89** | 0.81 | **98.75** |
148
+ | C3 | 6.97M | 0.0336 | 100 | 96.34 | 69.62 | 0.73 | 97.34 |
149
+ | C4 | 8.14M | 0.0283 | 94 | 97.15 | 73.79 | 0.54 | 97.86 |
150
+ | C5 | 11.70M | 0.0699 | 156 | 91.64 | 26.21 | 3.33 | n/a* |
151
+
152
+ \*BLEU/ROUGE are secondary for token-free C5; greedy C5 BLEU ≈ 89.3 if computed for reference.
153
+
154
+ **Ranking:** C2 > C1 ≈ C4 > C3 > C5.
155
+
156
+ **Note on C5:** bit accuracy stays relatively high while sequence (exact-match) accuracy is lower because errors are mostly scattered typos on long chunks (mean Lev ≈ 3.3). Parallel patch decoding and entropy cuts on predicted bytes amplify that gap.
157
+
158
+ ---
159
+
160
+
161
+ **C1–C4**
162
+
163
+ | File | Description |
164
+ |------|-------------|
165
+ | `pytorch_model.bin` | `state_dict` of `Seq2SeqTransformer` |
166
+ | `config.json` | Architecture + hparams |
167
+ | `cipher_bpe.json` | Source BPE |
168
+ | `plain_bpe.json` | Target BPE |
169
+ | `README.md` | This model card |
170
+
171
+ **C5**
172
+
173
+ | File | Description |
174
+ |------|-------------|
175
+ | `pytorch_model.bin` | `state_dict` of `BLTSeq2Seq` |
176
+ | `config.json` | Architecture + hparams + `entropy_threshold` |
177
+ | `entropy_ngram.json` | Smoothed byte n-gram entropy model |
178
+ | `entropy_patcher.json` | Threshold / target patch size |
179
+ | `README.md` | This model card |
180
+
181
+ ---
182
+
183
+ ## Limitations
184
+
185
+ - Single seed (42).
186
+ - C5 is not capacity-matched to C1 (extra byte/n-gram parameters).
187
+ - Results are specific to this index-aligned local cipher, not general MT.
188
+ - Not an `transformers` Auto* model; requires the course `src/` code to run.
189
+ - Do not treat published weights as a cryptanalysis tool beyond this homework setup.
190
+
191
+ ---
192
+
193
+ ### References
194
+
195
+ - Vaswani et al., Attention Is All You Need, NeurIPS 2017.
196
+ - Sennrich et al., Neural Machine Translation of Rare Words with Subword Units, ACL 2016.
197
+ - Su et al., RoFormer (RoPE), 2021.
198
+ - Ainslie et al., GQA, 2023.
199
+ - Zhang & Sennrich, RMSNorm, NeurIPS 2019.
200
+ - Pagnoni et al., Byte Latent Transformer, ACL 2025. https://aclanthology.org/2025.acl-long.453
201
+