@mechane-ai/elements 0.47.0 → 0.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +288 -5
- package/bin/mechane-elements-catalog.mjs +104 -12
- package/dist/ai.js +5 -5
- package/dist/article-yyNPg6VU.js +1904 -0
- package/dist/article.js +1 -0
- package/dist/catalog.json +1691 -163
- package/dist/{categorical-values-DdfGIowV.js → categorical-values-DCznViFp.js} +1 -1
- package/dist/{cells--Bd1fQFR.js → cells-CNZE4us2.js} +2 -2
- package/dist/charts/cartesian.js +1 -1
- package/dist/charts/cells.js +1 -1
- package/dist/charts/comparison.js +1 -1
- package/dist/charts/distribution.js +1 -1
- package/dist/charts/figure.js +12 -12
- package/dist/charts/graph.js +1 -1
- package/dist/charts/hierarchy.js +1 -1
- package/dist/charts/image.js +1 -1
- package/dist/charts/matrix.js +3 -2
- package/dist/charts/plot.js +6 -6
- package/dist/charts/relationship.js +1 -1
- package/dist/charts/text.js +1 -1
- package/dist/charts/timeline.js +1 -1
- package/dist/charts/trend.js +1 -1
- package/dist/charts.js +2 -2
- package/dist/clock-DSm5lkNE.js +16 -0
- package/dist/{code-block-DioAM2bZ.js → code-block-BZsY2sh3.js} +1 -1
- package/dist/collections.js +1 -1
- package/dist/content/code.js +1 -1
- package/dist/content/diff.js +3 -3
- package/dist/content/link.js +1 -1
- package/dist/content/markdown.js +2 -2
- package/dist/content/tree.js +1 -1
- package/dist/{content-link-NWuHp5rC.js → content-link-PnpcnTCx.js} +1 -1
- package/dist/content.js +1 -1
- package/dist/{dates-Cww8UR_n.js → dates-ckJdYF7t.js} +1 -1
- package/dist/describe-lesson-BmREzDpt.js +175 -0
- package/dist/{dumbbell-plot-B2ZTgQaI.js → dumbbell-plot-CMv9llfd.js} +9 -7
- package/dist/{embedding-map-CGM_k6lC.js → embedding-map-DC-lgzCq.js} +8 -8
- package/dist/feedback.js +1 -1
- package/dist/{figure-frame-wRkIEAwe.js → figure-frame-BjFzbl3m.js} +3 -3
- package/dist/forms/dates.js +1 -1
- package/dist/forms.js +3 -3
- package/dist/{image-grid-CVA4SOy_.js → image-grid-DHqtj_zs.js} +4 -4
- package/dist/index.js +1 -1
- package/dist/kits/evaluation.js +5 -5
- package/dist/kits/interpretability.js +320 -302
- package/dist/kits/operations.js +6 -6
- package/dist/kits/research.js +558 -0
- package/dist/kits/training.js +6 -6
- package/dist/layout.js +205 -110
- package/dist/lesson/agent.js +811 -0
- package/dist/lesson/spec.js +661 -0
- package/dist/lesson.js +5 -0
- package/dist/mdx.js +227 -0
- package/dist/navigation.js +2 -2
- package/dist/packages/charts/src/cartesian/index.d.ts +1 -1
- package/dist/packages/charts/src/cartesian/scatter-plot.d.ts +18 -0
- package/dist/packages/charts/src/chart-theme.d.ts +1 -1
- package/dist/packages/charts/src/matrix/index.d.ts +1 -0
- package/dist/packages/charts/src/plot/plot-marks.d.ts +7 -3
- package/dist/packages/charts/src/plot/plot-surface.d.ts +3 -1
- package/dist/packages/collections/src/index.d.ts +1 -1
- package/dist/packages/collections/src/metrics.d.ts +9 -1
- package/dist/packages/content/src/index.d.ts +2 -0
- package/dist/packages/content/src/text-match.d.ts +22 -0
- package/dist/packages/core/src/index.d.ts +1 -0
- package/dist/packages/core/src/surfaces.d.ts +12 -2
- package/dist/packages/forms/src/index.d.ts +2 -0
- package/dist/packages/forms/src/token-input.d.ts +24 -0
- package/dist/packages/kits/src/interpretability/index.d.ts +1 -1
- package/dist/packages/kits/src/interpretability/logit-lens.d.ts +10 -1
- package/dist/packages/kits/src/research/finding-card.d.ts +43 -0
- package/dist/packages/kits/src/research/index.d.ts +8 -0
- package/dist/packages/kits/src/research/milestone-path.d.ts +36 -0
- package/dist/packages/kits/src/research/specimen-diff.d.ts +41 -0
- package/dist/packages/kits/src/research/work-heartbeat.d.ts +34 -0
- package/dist/packages/layout/src/figure-grid.d.ts +8 -0
- package/dist/packages/layout/src/index.d.ts +4 -1
- package/dist/packages/layout/src/sidebar.d.ts +7 -0
- package/dist/packages/layout/src/workbench.d.ts +4 -1
- package/dist/packages/teaching/src/agent/index.d.ts +11 -0
- package/dist/packages/teaching/src/agent/learner-trace.d.ts +84 -0
- package/dist/packages/teaching/src/agent/lesson-bridge.d.ts +59 -0
- package/dist/packages/teaching/src/agent/lesson-tour.d.ts +63 -0
- package/dist/packages/teaching/src/agent/tutor-tools.d.ts +86 -0
- package/dist/packages/teaching/src/article/article-checks.d.ts +9 -0
- package/dist/packages/teaching/src/article/article-context.d.ts +49 -0
- package/dist/packages/teaching/src/article/article-error.d.ts +12 -0
- package/dist/packages/teaching/src/article/article-labels.d.ts +54 -0
- package/dist/packages/teaching/src/article/article-layout.stylex.d.ts +14 -0
- package/dist/packages/teaching/src/article/article-outline.d.ts +9 -0
- package/dist/packages/teaching/src/article/article.d.ts +42 -0
- package/dist/packages/teaching/src/article/beat-steps.d.ts +18 -0
- package/dist/packages/teaching/src/article/beat.d.ts +16 -0
- package/dist/packages/teaching/src/article/challenge.d.ts +29 -0
- package/dist/packages/teaching/src/article/exercise-styles.d.ts +76 -0
- package/dist/packages/teaching/src/article/figure.d.ts +51 -0
- package/dist/packages/teaching/src/article/index.d.ts +31 -0
- package/dist/packages/teaching/src/article/lesson-values.d.ts +5 -0
- package/dist/packages/teaching/src/article/notes.d.ts +36 -0
- package/dist/packages/teaching/src/article/outline-types.d.ts +73 -0
- package/dist/packages/teaching/src/article/predict.d.ts +58 -0
- package/dist/packages/teaching/src/article/progress-store.d.ts +64 -0
- package/dist/packages/teaching/src/article/scrolly.d.ts +26 -0
- package/dist/packages/{kits/src/explainers → teaching/src/article}/term.d.ts +8 -2
- package/dist/packages/teaching/src/article/tex.d.ts +12 -0
- package/dist/packages/teaching/src/article/view-essay.d.ts +13 -0
- package/dist/packages/teaching/src/article/view-present.d.ts +8 -0
- package/dist/packages/teaching/src/article/view-sheet.d.ts +7 -0
- package/dist/packages/teaching/src/article/view-static.d.ts +7 -0
- package/dist/packages/teaching/src/article/walk.d.ts +34 -0
- package/dist/packages/teaching/src/lesson/define-lesson.d.ts +136 -0
- package/dist/packages/teaching/src/lesson/index.d.ts +24 -0
- package/dist/packages/teaching/src/lesson/inline-choice.d.ts +12 -0
- package/dist/packages/teaching/src/lesson/lesson-context.d.ts +18 -0
- package/dist/packages/teaching/src/lesson/lesson-error.d.ts +12 -0
- package/dist/packages/teaching/src/lesson/lesson-locale.d.ts +4 -0
- package/dist/packages/teaching/src/lesson/lesson-persistence.d.ts +17 -0
- package/dist/packages/teaching/src/lesson/lesson-player.d.ts +51 -0
- package/dist/packages/teaching/src/lesson/lesson-store.d.ts +84 -0
- package/dist/packages/teaching/src/lesson/lesson.d.ts +39 -0
- package/dist/packages/teaching/src/lesson/param-controls.d.ts +14 -0
- package/dist/packages/teaching/src/lesson/param.d.ts +34 -0
- package/dist/packages/teaching/src/lesson/playback.d.ts +42 -0
- package/dist/packages/teaching/src/lesson/transport.d.ts +19 -0
- package/dist/packages/teaching/src/lesson/use-lesson.d.ts +36 -0
- package/dist/packages/teaching/src/mdx/essay-components.d.ts +79 -0
- package/dist/packages/teaching/src/mdx/essay-markdown.d.ts +41 -0
- package/dist/packages/teaching/src/mdx/essay.d.ts +32 -0
- package/dist/packages/teaching/src/mdx/index.d.ts +9 -0
- package/dist/packages/teaching/src/mdx/requested-view.d.ts +6 -0
- package/dist/packages/teaching/src/scene/flow/flow-layout.d.ts +38 -0
- package/dist/packages/teaching/src/scene/flow/flow-pulse.d.ts +16 -0
- package/dist/packages/teaching/src/scene/flow/scene-flow.d.ts +81 -0
- package/dist/packages/teaching/src/scene/index.d.ts +77 -0
- package/dist/packages/teaching/src/scene/morph/morph-scope.d.ts +28 -0
- package/dist/packages/teaching/src/scene/plane/plane-hit.d.ts +22 -0
- package/dist/packages/teaching/src/scene/plane/plane-label.d.ts +23 -0
- package/dist/packages/teaching/src/scene/plane/plane-labels.d.ts +42 -0
- package/dist/packages/teaching/src/scene/plane/plane-math.d.ts +45 -0
- package/dist/packages/teaching/src/scene/plane/scene-axes.d.ts +30 -0
- package/dist/packages/teaching/src/scene/plane/scene-curve.d.ts +42 -0
- package/dist/packages/teaching/src/scene/plane/scene-point.d.ts +59 -0
- package/dist/packages/teaching/src/scene/plane/scene-projection.d.ts +27 -0
- package/dist/packages/teaching/src/scene/plane/scene-region.d.ts +38 -0
- package/dist/packages/teaching/src/scene/plane/scene-rule.d.ts +35 -0
- package/dist/packages/teaching/src/scene/plane/scene-vector.d.ts +39 -0
- package/dist/packages/teaching/src/scene/scene-bracket.d.ts +24 -0
- package/dist/packages/teaching/src/scene/scene-callout.d.ts +26 -0
- package/dist/packages/teaching/src/scene/scene-context.d.ts +179 -0
- package/dist/packages/teaching/src/scene/scene-custom.d.ts +31 -0
- package/dist/packages/teaching/src/scene/scene-geometry.d.ts +181 -0
- package/dist/packages/teaching/src/scene/scene-group.d.ts +28 -0
- package/dist/packages/teaching/src/scene/scene-highlight.d.ts +19 -0
- package/dist/packages/teaching/src/scene/scene-layer.d.ts +16 -0
- package/dist/packages/teaching/src/scene/scene-node.d.ts +67 -0
- package/dist/packages/teaching/src/scene/scene-obstacles.d.ts +27 -0
- package/dist/packages/teaching/src/scene/scene-registry.d.ts +79 -0
- package/dist/packages/teaching/src/scene/scene-stagger.d.ts +43 -0
- package/dist/packages/teaching/src/scene/scene-style.d.ts +14 -0
- package/dist/packages/teaching/src/scene/scene-validate.d.ts +65 -0
- package/dist/packages/teaching/src/scene/scene-wire.d.ts +45 -0
- package/dist/packages/teaching/src/scene/scene.d.ts +36 -0
- package/dist/packages/teaching/src/scene/shapes/cell-color.d.ts +11 -0
- package/dist/packages/teaching/src/scene/shapes/cell-grid.d.ts +69 -0
- package/dist/packages/teaching/src/scene/shapes/scene-card.d.ts +114 -0
- package/dist/packages/teaching/src/scene/shapes/scene-cells.d.ts +84 -0
- package/dist/packages/teaching/src/scene/shapes/scene-slot.d.ts +37 -0
- package/dist/packages/teaching/src/scene/shapes/scene-stack.d.ts +46 -0
- package/dist/packages/teaching/src/scene/shapes/scene-token.d.ts +63 -0
- package/dist/packages/teaching/src/scene/shapes/scene-tokens.d.ts +40 -0
- package/dist/packages/teaching/src/scene/shapes/stack-book.d.ts +35 -0
- package/dist/packages/teaching/src/scene/shapes/stack-layout.d.ts +63 -0
- package/dist/packages/teaching/src/scene/shapes/token-layout.d.ts +39 -0
- package/dist/packages/teaching/src/spec/advice.d.ts +23 -0
- package/dist/packages/teaching/src/spec/chart-names.d.ts +2 -0
- package/dist/packages/teaching/src/spec/describe-lesson.d.ts +85 -0
- package/dist/packages/teaching/src/spec/explainer-guide.d.ts +21 -0
- package/dist/packages/teaching/src/spec/findings.d.ts +39 -0
- package/dist/packages/teaching/src/spec/index.d.ts +14 -0
- package/dist/packages/teaching/src/spec/lesson-plan.d.ts +43 -0
- package/dist/packages/teaching/src/spec/validate-plan.d.ts +11 -0
- package/dist/packages/teaching/src/time/clock.d.ts +7 -0
- package/dist/packages/teaching/src/time/tween.d.ts +19 -0
- package/dist/packages/teaching/src/time/use-tween.d.ts +6 -0
- package/dist/param-BE3VMSkH.js +450 -0
- package/dist/{pierre-diff-DlvjyuJn.js → pierre-diff-aGyQK5xK.js} +1 -1
- package/dist/{plot-axes-DJkLW4wk.js → plot-axes-D5S9BnBa.js} +1 -1
- package/dist/{plot-layout-BEuoOHbs.js → plot-layout-Bqe4-0qZ.js} +4 -3
- package/dist/{plot-marks-A64v7aTw.js → plot-marks-FVsbFkUs.js} +18 -15
- package/dist/{plot-surface-CJTIqtck.js → plot-surface-DON6WUmk.js} +11 -11
- package/dist/{plot-width-DcqtSgzb.js → plot-width-D3hTycYX.js} +1 -1
- package/dist/{reference-lines-CWA8VeUR.js → reference-lines-hjuD1rRZ.js} +2 -2
- package/dist/scene-BP0Ue0R5.js +4938 -0
- package/dist/scene.js +1 -0
- package/dist/{slope-chart-DT22h_ym.js → slope-chart-C8eeSgL4.js} +7 -7
- package/dist/{src-CpdJlDhO.js → src-9EJskqB_.js} +73 -31
- package/dist/{src-D5NXRJZe.js → src-B2rgpWap.js} +48 -14
- package/dist/{src-BPTDJqt0.js → src-Ci8DeY8J.js} +1 -1
- package/dist/{src-CGc_hjxJ.js → src-DFW49IAs.js} +143 -111
- package/dist/{src-1EHkSFS-.js → src-Dxs3Buo_.js} +205 -139
- package/dist/{src-CExIrXPC.js → src-npqwq3Sa.js} +1 -1
- package/dist/styles2.css +542 -21
- package/dist/{time-series-IB3CB93O.js → time-series-BL933QyA.js} +787 -715
- package/dist/{token-heatmap-C00DnoNO.js → token-heatmap-BB65awva.js} +4 -4
- package/dist/{token-predictions-Cxx29iDr.js → token-predictions-Pa8eUGan.js} +6 -6
- package/dist/transport-DzyxVXbL.js +715 -0
- package/dist/{tree-diagram-DsckNKaW.js → tree-diagram-DJhKBiia.js} +6 -6
- package/dist/{treemap-9_DpLCW9.js → treemap-CxxgABUg.js} +5 -5
- package/dist/use-tween-5HZ55_9d.js +72 -0
- package/dist/{violin-plot-BhPHKXsN.js → violin-plot-CoAEF_7Z.js} +7 -6
- package/dist/{waterfall-CGksuTy5.js → waterfall-DdoEXEkT.js} +7 -7
- package/package.json +30 -5
- package/recipes/counting-cards.tsx +656 -0
- package/recipes/explorable-essay.tsx +172 -0
- package/skills/extend-elements/SKILL.md +21 -0
- package/skills/plan-lesson/SKILL.md +86 -0
- package/skills/plan-lesson/references/plan-format.md +114 -0
- package/skills/plan-lesson/references/worked-plan.md +171 -0
- package/skills/review-elements/SKILL.md +4 -2
- package/skills/review-explainer/SKILL.md +97 -0
- package/skills/upgrade-elements/references/releases.md +65 -0
- package/skills/use-elements/SKILL.md +18 -16
- package/skills/use-elements/references/kits.md +9 -26
- package/skills/use-elements/references/teaching.md +36 -0
- package/skills/write-explainer/SKILL.md +112 -0
- package/skills/write-explainer/references/article.md +164 -0
- package/skills/write-explainer/references/lesson.md +148 -0
- package/skills/write-explainer/references/mdx.md +78 -0
- package/skills/write-explainer/references/scene-parts.md +273 -0
- package/skills/write-explainer/references/scene.md +168 -0
- package/skills/write-explainer/references/tutor.md +104 -0
- package/skills/write-explainer/references/worked-essay.md +459 -0
- package/templates/essay/AGENTS.md +14 -0
- package/templates/essay/README.md +59 -0
- package/templates/essay/index.html +17 -0
- package/templates/essay/package.template.json +21 -0
- package/templates/essay/plan.json +96 -0
- package/templates/essay/src/essay.mdx +97 -0
- package/templates/essay/src/figures.tsx +92 -0
- package/templates/essay/src/lesson.ts +83 -0
- package/templates/essay/src/main.tsx +53 -0
- package/templates/essay/src/mdx.d.ts +7 -0
- package/templates/essay/tsconfig.template.json +15 -0
- package/templates/essay/vite.config.template.txt +8 -0
- package/dist/kits/explainers.js +0 -452
- package/dist/packages/kits/src/explainers/figures.d.ts +0 -31
- package/dist/packages/kits/src/explainers/index.d.ts +0 -8
- package/dist/packages/kits/src/explainers/story-steps.d.ts +0 -46
- /package/dist/packages/{kits/src/explainers → teaching/src/article}/linked-target.d.ts +0 -0
- /package/dist/packages/{kits/src/explainers → teaching/src/lesson}/bound-value.d.ts +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "learning-rate",
|
|
3
|
+
"title": "Why a big learning rate blows up",
|
|
4
|
+
"audience": "Readers who know a model is trained by gradient descent but have not seen why the learning rate has an upper limit.",
|
|
5
|
+
"idea": "Each step multiplies the loss by (1 - 2 × rate) squared, so it falls for rates under 1 and grows past it.",
|
|
6
|
+
"params": {
|
|
7
|
+
"rate": {
|
|
8
|
+
"kind": "number",
|
|
9
|
+
"label": "Learning rate",
|
|
10
|
+
"value": 0.1,
|
|
11
|
+
"min": 0.05,
|
|
12
|
+
"max": 1.2,
|
|
13
|
+
"step": 0.05,
|
|
14
|
+
"format": { "maximumFractionDigits": 2 }
|
|
15
|
+
},
|
|
16
|
+
"steps": {
|
|
17
|
+
"kind": "number",
|
|
18
|
+
"label": "Steps taken",
|
|
19
|
+
"value": 0,
|
|
20
|
+
"min": 0,
|
|
21
|
+
"max": 10,
|
|
22
|
+
"step": 1,
|
|
23
|
+
"format": { "maximumFractionDigits": 0 }
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"derived": {
|
|
27
|
+
"weight": {
|
|
28
|
+
"label": "Weight",
|
|
29
|
+
"format": { "maximumSignificantDigits": 3 },
|
|
30
|
+
"reads": ["rate", "steps"],
|
|
31
|
+
"formula": "(1 - 2 × rate) to the power of steps"
|
|
32
|
+
},
|
|
33
|
+
"loss": {
|
|
34
|
+
"label": "Loss",
|
|
35
|
+
"format": { "maximumSignificantDigits": 2 },
|
|
36
|
+
"reads": ["weight"],
|
|
37
|
+
"formula": "the weight squared"
|
|
38
|
+
},
|
|
39
|
+
"factor": {
|
|
40
|
+
"label": "Loss factor per step",
|
|
41
|
+
"format": { "maximumFractionDigits": 2 },
|
|
42
|
+
"reads": ["rate"],
|
|
43
|
+
"formula": "(1 - 2 × rate) squared"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"beats": [
|
|
47
|
+
{
|
|
48
|
+
"id": "update",
|
|
49
|
+
"title": "One step of gradient descent",
|
|
50
|
+
"goal": "See that a step moves the weight against its slope by a fixed fraction of that slope.",
|
|
51
|
+
"misconception": "That a bigger step always gets to the minimum sooner.",
|
|
52
|
+
"states": [
|
|
53
|
+
{ "id": "start", "label": "Before the first step", "values": { "rate": 0.1, "steps": 0 } },
|
|
54
|
+
{ "id": "one-step", "label": "After one step", "values": { "rate": 0.1, "steps": 1 } }
|
|
55
|
+
],
|
|
56
|
+
"figure": {
|
|
57
|
+
"part": "Scene",
|
|
58
|
+
"question": "How does one step turn a weight into the next weight?",
|
|
59
|
+
"shows": ["weight", "rate"]
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"id": "rate",
|
|
64
|
+
"title": "The rate sets how fast the loss falls",
|
|
65
|
+
"goal": "Connect a larger rate with a smaller loss factor, up to the rate that lands on the minimum.",
|
|
66
|
+
"states": [
|
|
67
|
+
{ "id": "slow", "label": "Rate 0.1, ten steps", "values": { "rate": 0.1, "steps": 10 } },
|
|
68
|
+
{ "id": "fast", "label": "Rate 0.4, ten steps", "values": { "rate": 0.4, "steps": 10 } }
|
|
69
|
+
],
|
|
70
|
+
"figure": {
|
|
71
|
+
"part": "CurveChart",
|
|
72
|
+
"question": "How fast does the loss fall at this rate?",
|
|
73
|
+
"shows": ["loss", "rate"]
|
|
74
|
+
},
|
|
75
|
+
"ask": { "kind": "predict", "prompt": "After ten steps, which learning rate leaves the smaller loss?" }
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"id": "blowup",
|
|
79
|
+
"title": "Past a rate of one, the loss grows",
|
|
80
|
+
"goal": "Find the rate where each step stops shrinking the loss and starts growing it.",
|
|
81
|
+
"states": [
|
|
82
|
+
{ "id": "edge", "label": "Rate 1, ten steps", "values": { "rate": 1, "steps": 10 } },
|
|
83
|
+
{ "id": "blown", "label": "Rate 1.1, ten steps", "values": { "rate": 1.1, "steps": 10 } }
|
|
84
|
+
],
|
|
85
|
+
"figure": {
|
|
86
|
+
"part": "CurveChart",
|
|
87
|
+
"question": "Does the loss fall, stay flat or climb at this rate?",
|
|
88
|
+
"shows": ["loss", "rate", "factor"]
|
|
89
|
+
},
|
|
90
|
+
"ask": {
|
|
91
|
+
"kind": "challenge",
|
|
92
|
+
"prompt": "Find the largest learning rate on the slider that still makes the loss fall."
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export const meta = {
|
|
2
|
+
title: 'Why a big learning rate blows up',
|
|
3
|
+
authors: ['Your name'],
|
|
4
|
+
date: '2026-11-23',
|
|
5
|
+
summary:
|
|
6
|
+
'Gradient descent on the simplest loss there is, and the one number that decides whether it settles or explodes. The numbers are synthetic.',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
import { LossCurve, UpdateRule } from './figures.tsx';
|
|
10
|
+
|
|
11
|
+
<Beat id="update">
|
|
12
|
+
|
|
13
|
+
Training moves a weight `w` to make a loss small. Take the loss `w²`: its slope is `2w`, and one step of gradient
|
|
14
|
+
descent moves the weight against the slope by a fraction of it, the **learning rate**.
|
|
15
|
+
|
|
16
|
+
At a learning rate of <Param name="rate" /> the weight after <Param name="steps" /> steps is <Value name="weight" />
|
|
17
|
+
(<FigureReference to="update-rule" />).
|
|
18
|
+
|
|
19
|
+
<Figure
|
|
20
|
+
id="update-rule"
|
|
21
|
+
caption="One step: read the weight, take its slope, move against it."
|
|
22
|
+
description="Three boxes joined by arrows: the weight, its slope, and the weight after the step. The arrow into the last box carries the learning rate."
|
|
23
|
+
reads={['rate', 'steps']}
|
|
24
|
+
>
|
|
25
|
+
<UpdateRule />
|
|
26
|
+
</Figure>
|
|
27
|
+
|
|
28
|
+
<Aside>
|
|
29
|
+
Real networks have millions of weights, but each one moves by the same rule: its own slope times the rate.
|
|
30
|
+
</Aside>
|
|
31
|
+
|
|
32
|
+
</Beat>
|
|
33
|
+
|
|
34
|
+
<Beat id="rate">
|
|
35
|
+
|
|
36
|
+
Every step multiplies the weight by `1 − 2 × rate`, so the loss, which is the weight squared, shrinks by a factor
|
|
37
|
+
of <Value name="factor" /> per step. Press play to run ten steps.<Footnote id="quadratic">This is exact only for a
|
|
38
|
+
loss of `w²`. Other losses bend, but near a minimum they look the same.</Footnote>
|
|
39
|
+
|
|
40
|
+
<Playback name="steps" pace="slow" />
|
|
41
|
+
|
|
42
|
+
<Figure
|
|
43
|
+
id="loss-curve"
|
|
44
|
+
caption="Loss at each step on a log scale. A straight line down means a constant factor per step."
|
|
45
|
+
description="A line falling steadily from a loss of 1 toward zero. A larger learning rate makes the line steeper."
|
|
46
|
+
reads={['rate']}
|
|
47
|
+
>
|
|
48
|
+
<LossCurve />
|
|
49
|
+
<Transport for="steps" />
|
|
50
|
+
</Figure>
|
|
51
|
+
|
|
52
|
+
<Predict
|
|
53
|
+
id="faster"
|
|
54
|
+
prompt="After ten steps, which learning rate leaves the smaller loss?"
|
|
55
|
+
options={[
|
|
56
|
+
{ id: 'slow', label: 'A rate of 0.1' },
|
|
57
|
+
{ id: 'fast', label: 'A rate of 0.4' },
|
|
58
|
+
{ id: 'same', label: 'The same' },
|
|
59
|
+
]}
|
|
60
|
+
answer="fast"
|
|
61
|
+
>
|
|
62
|
+
|
|
63
|
+
A rate of 0.4 multiplies the loss by 0.04 each step, a rate of 0.1 by 0.64. After ten steps one is about 10⁻¹⁴ and the
|
|
64
|
+
other about 10⁻². A rate of 0.5 lands on zero in one step.
|
|
65
|
+
|
|
66
|
+
</Predict>
|
|
67
|
+
|
|
68
|
+
</Beat>
|
|
69
|
+
|
|
70
|
+
<Beat id="blowup">
|
|
71
|
+
|
|
72
|
+
Nothing so far says a bigger rate is worse, so push it. The loss factor is `(1 − 2 × rate)²`. It stays below 1 for
|
|
73
|
+
every rate under 1, equals 1 at 1, and grows past it. At <Param name="rate" /> the factor is <Value name="factor" />
|
|
74
|
+
and the loss after <Value name="steps" /> steps is <Value name="loss" />.
|
|
75
|
+
|
|
76
|
+
<Figure
|
|
77
|
+
id="blowup-curve"
|
|
78
|
+
caption="The same curve at a rate the reader can push past one."
|
|
79
|
+
description="A line that falls, stays flat or climbs depending on whether the learning rate is under, at or over one."
|
|
80
|
+
reads={['rate']}
|
|
81
|
+
>
|
|
82
|
+
<LossCurve />
|
|
83
|
+
</Figure>
|
|
84
|
+
|
|
85
|
+
<Challenge
|
|
86
|
+
id="largest-rate"
|
|
87
|
+
prompt="Find the largest learning rate on the slider that still makes the loss fall."
|
|
88
|
+
isReached={(values) => Number(values.rate) > 0.9 && Number(values.factor) < 1}
|
|
89
|
+
hints={['The loss falls while the factor is under 1.', 'The factor is exactly 1 at a rate of 1.']}
|
|
90
|
+
>
|
|
91
|
+
|
|
92
|
+
The slider moves in steps of 0.05, so 0.95 is the last rate that falls. At 1 the weight flips sign and never gets
|
|
93
|
+
smaller.
|
|
94
|
+
|
|
95
|
+
</Challenge>
|
|
96
|
+
|
|
97
|
+
</Beat>
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { CurveChart } from '@mechane-ai/elements/charts/trend';
|
|
2
|
+
import { useLesson } from '@mechane-ai/elements/lesson';
|
|
3
|
+
import { Scene, SceneNode, SceneWire } from '@mechane-ai/elements/scene';
|
|
4
|
+
import type { ReactNode } from 'react';
|
|
5
|
+
import { LAST_STEP, lesson } from './lesson.ts';
|
|
6
|
+
|
|
7
|
+
/** The loss never plots below this, so a loss of exactly zero stays on the log axis. */
|
|
8
|
+
const LOSS_FLOOR = 1e-6;
|
|
9
|
+
const LOSS_CEILING = 1e3;
|
|
10
|
+
|
|
11
|
+
/** The loss after `steps` steps at `rate`: the weight shrinks by 1 − 2 × rate each step, and the loss is its square. */
|
|
12
|
+
function lossAfter(rate: number, steps: number): number {
|
|
13
|
+
return Math.max(((1 - 2 * rate) ** steps) ** 2, LOSS_FLOOR);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const steps = Array.from({ length: LAST_STEP + 1 }, (_, step) => step);
|
|
17
|
+
|
|
18
|
+
/** The loss at every step for the learning rate the reader chose, with the step they are at marked. */
|
|
19
|
+
export function LossCurve(): ReactNode {
|
|
20
|
+
const { values, locale } = useLesson(lesson);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<CurveChart
|
|
24
|
+
title="Loss by step"
|
|
25
|
+
description="Synthetic loss of gradient descent on w squared, from step 0 to step 10."
|
|
26
|
+
locale={locale}
|
|
27
|
+
series={[
|
|
28
|
+
{
|
|
29
|
+
id: 'loss',
|
|
30
|
+
label: 'Loss',
|
|
31
|
+
tone: 'series1',
|
|
32
|
+
points: steps.map((step) => ({ x: step, y: lossAfter(values.rate, step) })),
|
|
33
|
+
},
|
|
34
|
+
]}
|
|
35
|
+
x={{ label: 'Step', domain: [0, LAST_STEP], format: { maximumFractionDigits: 0 } }}
|
|
36
|
+
y={{ label: 'Loss', scale: 'log', domain: [LOSS_FLOOR, LOSS_CEILING], format: { maximumSignificantDigits: 2 } }}
|
|
37
|
+
references={[{ id: 'start', label: 'Loss at the start', y: 1 }]}
|
|
38
|
+
markers={[{ x: values.steps, label: 'Now' }]}
|
|
39
|
+
labels="none"
|
|
40
|
+
height="regular"
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** One step drawn as a scene: the weight, its slope, and the weight after the step. */
|
|
46
|
+
export function UpdateRule(): ReactNode {
|
|
47
|
+
const { values, locale } = useLesson(lesson);
|
|
48
|
+
const number = new Intl.NumberFormat(locale, { maximumSignificantDigits: 3 });
|
|
49
|
+
const next = values.weight * (1 - 2 * values.rate);
|
|
50
|
+
const isGrowing = Math.abs(next) > Math.abs(values.weight);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Scene
|
|
54
|
+
title="One step of gradient descent"
|
|
55
|
+
description="Synthetic numbers. The slope of the loss is twice the weight, and the step moves the weight against it."
|
|
56
|
+
locale={locale}
|
|
57
|
+
x={[0, 3]}
|
|
58
|
+
y={[0, 1]}
|
|
59
|
+
weightMax={1.2}
|
|
60
|
+
height="compact"
|
|
61
|
+
>
|
|
62
|
+
<SceneNode
|
|
63
|
+
id="weight"
|
|
64
|
+
at={[0.5, 0.5]}
|
|
65
|
+
text={`w = ${number.format(values.weight)}`}
|
|
66
|
+
label={`The weight now is ${number.format(values.weight)}`}
|
|
67
|
+
/>
|
|
68
|
+
<SceneNode
|
|
69
|
+
id="slope"
|
|
70
|
+
at={[1.5, 0.5]}
|
|
71
|
+
text={`slope ${number.format(2 * values.weight)}`}
|
|
72
|
+
label={`The slope of the loss is twice the weight, ${number.format(2 * values.weight)}`}
|
|
73
|
+
shape="pill"
|
|
74
|
+
/>
|
|
75
|
+
<SceneNode
|
|
76
|
+
id="next"
|
|
77
|
+
at={[2.5, 0.5]}
|
|
78
|
+
text={`next ${number.format(next)}`}
|
|
79
|
+
label={`The weight after this step is ${number.format(next)}`}
|
|
80
|
+
tone={isGrowing ? 'negative' : 'positive'}
|
|
81
|
+
/>
|
|
82
|
+
<SceneWire from="weight" to="slope" label="The slope is twice the weight" />
|
|
83
|
+
<SceneWire
|
|
84
|
+
from="slope"
|
|
85
|
+
to="next"
|
|
86
|
+
weight={values.rate}
|
|
87
|
+
text={`× ${number.format(values.rate)}`}
|
|
88
|
+
label={`The step is the slope times the learning rate, ${number.format(values.rate)}`}
|
|
89
|
+
/>
|
|
90
|
+
</Scene>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { defineLesson } from '@mechane-ai/elements/lesson';
|
|
2
|
+
|
|
3
|
+
/** The number of steps the loss curve draws. */
|
|
4
|
+
export const LAST_STEP = 10;
|
|
5
|
+
|
|
6
|
+
/** The slope of the loss w² is this multiple of the weight. */
|
|
7
|
+
const SLOPE = 2;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Gradient descent on the loss w². One step moves the weight against its slope 2w by a fraction `rate`, so the weight
|
|
11
|
+
* is multiplied by 1 − 2 × rate each step. The numbers are synthetic.
|
|
12
|
+
*/
|
|
13
|
+
export const lesson = defineLesson({
|
|
14
|
+
id: 'learning-rate',
|
|
15
|
+
title: 'Why a big learning rate blows up',
|
|
16
|
+
params: {
|
|
17
|
+
rate: {
|
|
18
|
+
kind: 'number',
|
|
19
|
+
label: 'Learning rate',
|
|
20
|
+
value: 0.1,
|
|
21
|
+
min: 0.05,
|
|
22
|
+
max: 1.2,
|
|
23
|
+
step: 0.05,
|
|
24
|
+
format: { maximumFractionDigits: 2 },
|
|
25
|
+
},
|
|
26
|
+
steps: {
|
|
27
|
+
kind: 'number',
|
|
28
|
+
label: 'Steps taken',
|
|
29
|
+
value: 0,
|
|
30
|
+
min: 0,
|
|
31
|
+
max: LAST_STEP,
|
|
32
|
+
step: 1,
|
|
33
|
+
format: { maximumFractionDigits: 0 },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
derived: {
|
|
37
|
+
weight: {
|
|
38
|
+
label: 'Weight',
|
|
39
|
+
format: { maximumSignificantDigits: 3 },
|
|
40
|
+
from: ({ rate, steps }) => (1 - SLOPE * rate) ** steps,
|
|
41
|
+
},
|
|
42
|
+
loss: { label: 'Loss', format: { maximumSignificantDigits: 2 }, from: ({ weight }) => weight * weight },
|
|
43
|
+
factor: {
|
|
44
|
+
label: 'Loss factor per step',
|
|
45
|
+
format: { maximumFractionDigits: 2 },
|
|
46
|
+
from: ({ rate }) => (1 - SLOPE * rate) ** SLOPE,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
beats: [
|
|
50
|
+
{
|
|
51
|
+
id: 'update',
|
|
52
|
+
title: 'One step of gradient descent',
|
|
53
|
+
goal: 'See that a step moves the weight against its slope by a fixed fraction of that slope.',
|
|
54
|
+
misconception: 'That a bigger step always gets to the minimum sooner.',
|
|
55
|
+
states: [
|
|
56
|
+
{ id: 'start', label: 'Before the first step', values: { rate: 0.1, steps: 0 } },
|
|
57
|
+
{ id: 'one-step', label: 'After one step', values: { rate: 0.1, steps: 1 } },
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: 'rate',
|
|
62
|
+
title: 'The rate sets how fast the loss falls',
|
|
63
|
+
goal: 'Connect a larger rate with a smaller loss factor, up to the rate that lands on the minimum.',
|
|
64
|
+
hints: ['Press play, then raise the rate to 0.4 and play again.', 'At 0.5 the very first step lands on zero.'],
|
|
65
|
+
states: [
|
|
66
|
+
{ id: 'slow', label: 'Rate 0.1, ten steps', values: { rate: 0.1, steps: LAST_STEP } },
|
|
67
|
+
{ id: 'fast', label: 'Rate 0.4, ten steps', values: { rate: 0.4, steps: LAST_STEP } },
|
|
68
|
+
{ id: 'exact', label: 'Rate 0.5, ten steps', values: { rate: 0.5, steps: LAST_STEP } },
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: 'blowup',
|
|
73
|
+
title: 'Past a rate of one, the loss grows',
|
|
74
|
+
goal: 'Find the rate where each step stops shrinking the loss and starts growing it.',
|
|
75
|
+
misconception: 'That the loss only grows once the rate is far above the best one.',
|
|
76
|
+
hints: ['The factor per step is exactly 1 at a rate of 1.', 'Look at the loss factor, not the weight.'],
|
|
77
|
+
states: [
|
|
78
|
+
{ id: 'edge', label: 'Rate 1, ten steps', values: { rate: 1, steps: LAST_STEP } },
|
|
79
|
+
{ id: 'blown', label: 'Rate 1.1, ten steps', values: { rate: 1.1, steps: LAST_STEP } },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import '@mechane-ai/elements/styles.css';
|
|
2
|
+
import { checkLesson, validateLessonPlan } from '@mechane-ai/elements/lesson/spec';
|
|
3
|
+
import { Essay } from '@mechane-ai/elements/mdx';
|
|
4
|
+
import { themeProps } from '@mechane-ai/elements/theme';
|
|
5
|
+
import { colors, spacing } from '@mechane-ai/elements/tokens';
|
|
6
|
+
import { createRoot } from 'react-dom/client';
|
|
7
|
+
import plan from '../plan.json';
|
|
8
|
+
import Content, { meta } from './essay.mdx';
|
|
9
|
+
import { lesson } from './lesson.ts';
|
|
10
|
+
|
|
11
|
+
const PAGE_WIDTH = 1200;
|
|
12
|
+
|
|
13
|
+
const theme = matchMedia('(prefers-color-scheme: dark)').matches ? themeProps.dark : themeProps.light;
|
|
14
|
+
|
|
15
|
+
document.documentElement.className = theme.className ?? '';
|
|
16
|
+
document.body.style.backgroundColor = colors.surface;
|
|
17
|
+
|
|
18
|
+
/** Lists what `plan.json` and the lesson still get wrong, so an author or an agent sees it beside the essay. */
|
|
19
|
+
function Findings() {
|
|
20
|
+
const findings = [...validateLessonPlan(plan).findings, ...checkLesson(lesson)];
|
|
21
|
+
|
|
22
|
+
if (findings.length === 0) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<details open>
|
|
28
|
+
<summary>Lesson checks</summary>
|
|
29
|
+
<ul>
|
|
30
|
+
{findings.map((finding) => (
|
|
31
|
+
<li
|
|
32
|
+
key={`${finding.path} ${finding.message}`}
|
|
33
|
+
>{`${finding.severity} at ${finding.path}: ${finding.message}`}</li>
|
|
34
|
+
))}
|
|
35
|
+
</ul>
|
|
36
|
+
</details>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const root = document.querySelector('#root');
|
|
41
|
+
|
|
42
|
+
if (root === null) {
|
|
43
|
+
throw new Error('index.html has no #root element.');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
createRoot(root).render(
|
|
47
|
+
<main
|
|
48
|
+
style={{ boxSizing: 'border-box', maxWidth: PAGE_WIDTH, margin: '0 auto', padding: `${spacing.xxl} ${spacing.lg}` }}
|
|
49
|
+
>
|
|
50
|
+
<Essay lesson={lesson} content={Content} locale="en-US" storageKey={lesson.id} {...meta} />
|
|
51
|
+
<Findings />
|
|
52
|
+
</main>,
|
|
53
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2024",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"isolatedModules": true,
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"types": ["vite/client"]
|
|
13
|
+
},
|
|
14
|
+
"include": ["src"]
|
|
15
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import mdx from '@mdx-js/rollup';
|
|
2
|
+
import react from '@vitejs/plugin-react';
|
|
3
|
+
import { defineConfig } from 'vite';
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
// MDX compiles to plain JSX calls, so it runs before the React plugin sees the other files.
|
|
7
|
+
plugins: [{ enforce: 'pre', ...mdx() }, react()],
|
|
8
|
+
});
|