You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Use current, stable libraries (not deprecated APIs)
44
44
- Python 3.10+ style, type hints where helpful
45
45
- Imports shown explicitly (no hidden dependencies)
46
-
- Output shown inline after code blocks
46
+
- Output shown in a `<div class="code-output">` pane between `</pre>` and `<div class="code-caption">`. Every code block that calls `print()`, `.head()`, `display()`, or produces visible results MUST have an output pane showing representative output. See #40 Code Caption Agent for the full output pane specification.
47
47
48
48
### Import Justification Rule
49
49
Every `import` statement in a code block must be justified in the surrounding prose or
Copy file name to clipboardExpand all lines: agents/book-skills/agents/19-structural-architect.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -200,6 +200,7 @@ Every section HTML file AND appendix index.html MUST place recurring structural
200
200
2.**Prerequisites** (div.prerequisites) immediately after the epigraph
201
201
3.**Big Picture callout** (div.callout.big-picture) immediately after prerequisites. This is MANDATORY for every content page (sections AND appendices). It frames why this topic matters and how it connects to the broader book.
4.**Do not hotlink**: Download the image to the chapter's `images/` directory and reference locally
313
+
5.**Verify the image is redistributable**: Check the paper's license or documentation terms
314
+
6.**Alt text must describe what the diagram shows**, not just "Figure from paper X"
315
+
316
+
### Searching for Good Illustrations
317
+
Before generating a new illustration for a well-known concept, search for:
318
+
- The original paper's figures on arXiv (most ML papers are open access)
319
+
- Official library documentation diagrams
320
+
- High-quality open-source diagrams from survey papers
321
+
- Figures from blog posts with permissive licenses (e.g., Google AI Blog, Meta AI Blog)
322
+
323
+
### Figure Source CSS
324
+
The `.figure-source` class is defined in `styles/book.css`. If not yet present, it should render as smaller, gray text below the main caption.
325
+
291
326
## Cross-Referencing Requirement
292
327
293
328
When an illustration depicts a concept that connects to other chapters, mention this in the caption (e.g., "This concept reappears when we explore fine-tuning in Chapter 13").
Copy file name to clipboardExpand all lines: agents/book-skills/agents/37-controller.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,6 +62,7 @@ Read every HTML file in the target chapter (index.html + all section-*.html file
62
62
| Modality competition | Code, table, diagram appearing back-to-back with no interpretive prose between | Dr. Sana Okafor (#03, Teaching Flow Reviewer) |
63
63
| Transition sentences | Subsections ending abruptly with no bridge to next topic | Olivia March (#14, Narrative Continuity Editor) |
64
64
| Code captions | Code blocks without captions or text references | Kai Nakamura (#08, Code Pedagogy Engineer) |
65
+
| Code output panes | Code with print()/display() calls but no `.code-output` div | Kai Nakamura (#08, Code Pedagogy Engineer) |
65
66
| Research Frontier | Missing research-frontier callout, stale frontier content | Prof. Ingrid Holm (#18, Research Scientist and Frontier Mapper) |
66
67
| Labs | Missing hands-on labs, labs too shallow or too complex | Dex Huang (#27, Lab Designer) |
67
68
| Element ordering | Epigraph, prereqs, content, research frontier, what's next, bib out of order | Yara Sokolov (#19, Structural Architect) |
Copy file name to clipboardExpand all lines: agents/book-skills/agents/40-code-caption-agent.md
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -171,13 +171,45 @@ The caption must: (a) name the library, (b) state the line count, (c) describe w
171
171
-`.code-output` divs (these are output displays, not code fragments; they are part of the preceding code block's unit)
172
172
-**Chapter opener images** (`chapter-opener.png`): These decorative illustrations in chapter index files do NOT get code captions or figure captions. They are visual decoration, not instructional figures.
173
173
174
+
## Output Pane Rules
175
+
176
+
When a code block produces visible output (printed results, model predictions, loss values,
177
+
tensor shapes, tokenization results, etc.), the output MUST be shown in a separate
178
+
`<div class="code-output">` element between the `</pre>` and the `<div class="code-caption">`.
179
+
180
+
### Standard Element Order
181
+
```html
182
+
<pre><code>...code...</code></pre>
183
+
<divclass="code-output">
184
+
...output lines...
185
+
</div>
186
+
<divclass="code-caption"><strong>Code Fragment N:</strong> ...</div>
187
+
```
188
+
189
+
### Rules for Output Panes
190
+
1. Use `<div class="code-output">` (not `output-block`, not `console-output`, not bare `<pre>`)
191
+
2. The output pane sits BETWEEN the code block and the caption; never before the code or after the caption
192
+
3. Show only the meaningful output lines; omit progress bars, deprecation warnings, and download logs
193
+
4. For long outputs (more than 15 lines), truncate with `...` and show the most informative portion
194
+
5. Output text uses monospace font (styled by CSS); do not add extra formatting
195
+
6. Code blocks that produce NO visible output (e.g., class definitions, import-only blocks, configuration) do NOT get an output pane
196
+
7. When auditing, flag code blocks that contain `print()`, `display()`, `.head()`, or similar output calls but have no `.code-output` sibling
197
+
198
+
### When to Add Output Panes
199
+
- Code that prints results, metrics, or shapes: ALWAYS show output
200
+
- Code that trains a model and prints loss/accuracy: show representative epochs
201
+
- Code that demonstrates a transformation (tokenization, encoding): show before/after
202
+
- Code that queries an API and gets a response: show the response
203
+
- Interactive/REPL-style code: show the return values
204
+
174
205
## CRITICAL: Insertion Point Verification
175
206
176
207
After inserting or moving a caption, the agent MUST verify the final HTML structure matches
<divclass="code-caption"><strong>Code Fragment C.1.2:</strong> This snippet demonstrates this approach using PyTorch. Study the implementation to understand how each component contributes to the overall workflow.</div>
<divclass="code-caption"><strong>Code Fragment C.1.3:</strong> This snippet demonstrates this approach. Study the implementation to understand how each component contributes to the overall workflow.</div>
<divclass="code-caption"><strong>Code Fragment C.2.1:</strong> This snippet demonstrates this approach using <ahref="https://pytorch.org/" target="_blank" rel="noopener">PyTorch</a>. Study the implementation to understand how each component contributes to the overall workflow.</div>
<divclass="code-caption"><strong>Code Fragment C.2.2:</strong> This snippet demonstrates this approach using PyTorch. Study the implementation to understand how each component contributes to the overall workflow.</div>
64
65
<divclass="callout key-insight">
65
66
<divclass="callout-title">Key Insight: Why Conda for GPU Work?</div>
Copy file name to clipboardExpand all lines: appendices/appendix-c-python-for-llm/section-c.4.html
+4-1Lines changed: 4 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,7 @@ <h3>Pattern 1: Loading a Model with Automatic Device Mapping</h3>
41
41
device_map="auto", # spread across available GPUs
42
42
load_in_4bit=True, # 4-bit quantization to save memory
43
43
)</code></pre>
44
+
<divclass="code-caption"><strong>Code Fragment C.4.3:</strong> This snippet demonstrates the <code>tokenize_fn</code> function using PyTorch. The function encapsulates reusable logic that can be applied across different inputs.</div>
44
45
<h3>Pattern 2: Chat-Style Inference with Templates</h3>
45
46
46
47
<p>This snippet applies a chat template to a multi-turn conversation and generates a response from the model.</p>
@@ -122,9 +123,11 @@ <h3>Pattern 5: Saving and Loading Checkpoints</h3>
<divclass="code-caption"><strong>Code Fragment C.4.4:</strong> This snippet demonstrates the <code>call_with_retry</code> function using API integration. The function encapsulates reusable logic that can be applied across different inputs.</div>
125
-
<divclass="code-caption"><strong>Code Fragment C.4.3:</strong> This snippet demonstrates the <code>tokenize_fn</code> function using PyTorch. The function encapsulates reusable logic that can be applied across different inputs.</div>
<divclass="code-caption"><strong>Code Fragment C.4.2:</strong> This snippet demonstrates this approach. Study the implementation to understand how each component contributes to the overall workflow.</div>
<divclass="code-caption"><strong>Code Fragment C.4.1:</strong> This snippet demonstrates this approach using <ahref="https://pytorch.org/" target="_blank" rel="noopener">PyTorch</a>. Study the implementation to understand how each component contributes to the overall workflow.</div>
<divclass="code-caption"><strong>Code Fragment C.4.5:</strong> This snippet demonstrates this approach. Study the implementation to understand how each component contributes to the overall workflow.</div>
129
132
<divclass="callout fun-note">
130
133
<divclass="callout-title">Fun Fact: The Two-Line LLM</div>
<divclass="code-caption"><strong>Code Fragment D.3.2:</strong> This snippet demonstrates this approach using PyTorch. Study the implementation to understand how each component contributes to the overall workflow.</div>
39
40
<h3>Option B: venv + pip</h3>
40
41
41
42
<p>This snippet sets up a virtual environment using <code>venv</code> and installs packages with pip.</p>
@@ -47,7 +48,6 @@ <h3>Option B: venv + pip</h3>
47
48
# Install PyTorch (check pytorch.org for the correct command)
<divclass="code-caption"><strong>Code Fragment D.3.1:</strong> This snippet demonstrates this approach using <ahref="https://pytorch.org/" target="_blank" rel="noopener">PyTorch</a>. Study the implementation to understand how each component contributes to the overall workflow.</div>
50
-
<divclass="code-caption"><strong>Code Fragment D.3.2:</strong> This snippet demonstrates this approach using PyTorch. Study the implementation to understand how each component contributes to the overall workflow.</div>
Copy file name to clipboardExpand all lines: appendices/appendix-d-environment-setup/section-d.6.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -78,6 +78,7 @@ <h1>D.6 Verifying Your Setup</h1>
78
78
test_inference()
79
79
80
80
print("\n=== All checks complete! ===")</code></pre>
81
+
<divclass="code-caption"><strong>Code Fragment D.6.2:</strong> This snippet demonstrates this approach using PyTorch. Study the implementation to understand how each component contributes to the overall workflow.</div>
81
82
<p>Expected output on a properly configured machine with an <ahref="https://www.nvidia.com/" target="_blank" rel="noopener">NVIDIA</a> GPU:</p>
82
83
83
84
<pre><codeclass="language-text">
@@ -101,7 +102,6 @@ <h1>D.6 Verifying Your Setup</h1>
101
102
102
103
=== All checks complete!</code></pre>
103
104
<divclass="code-caption"><strong>Code Fragment D.6.1:</strong> This snippet demonstrates the <code>check_python</code> function using <ahref="https://pytorch.org/" target="_blank" rel="noopener">PyTorch</a>. The function encapsulates reusable logic that can be applied across different inputs.</div>
104
-
<divclass="code-caption"><strong>Code Fragment D.6.2:</strong> This snippet demonstrates this approach using PyTorch. Study the implementation to understand how each component contributes to the overall workflow.</div>
105
105
<divclass="callout fun-note">
106
106
<divclass="callout-title">Fun Fact: The Setup Tax</div>
107
107
<p>In a 2023 survey of ML practitioners, environment setup was ranked as the second most time-consuming part of starting a new project (after data cleaning). The good news: once you have a working environment, you can clone it, export it, and reuse it across projects. The initial investment pays dividends for months.</p>
0 commit comments