|
| 1 | +# Session Notes: JavaScript Error Fixes (Issue #32) |
| 2 | + |
| 3 | +## Date: 2026-01-01 |
| 4 | + |
| 5 | +## Summary |
| 6 | + |
| 7 | +Fixed JavaScript errors in multiple LLM course demos as documented in GitHub issue #32. |
| 8 | + |
| 9 | +## Changes Made |
| 10 | + |
| 11 | +### 1. Demo 02 (Tokenization) - `tokenizer.tokenize is not a function` |
| 12 | +**File:** `demos/02-tokenization/js/tokenizer-comparison.js` |
| 13 | + |
| 14 | +**Issue:** The `tokenizer.tokenize()` method doesn't exist in Transformers.js AutoTokenizer. Only `encode()` and `decode()` are available. |
| 15 | + |
| 16 | +**Fix:** Changed the implementation to: |
| 17 | +1. Use `tokenizer.encode(text)` to get token IDs |
| 18 | +2. Decode each token ID individually with `tokenizer.decode([id])` to get token strings |
| 19 | +3. Also fixed innerHTML usage to use safe DOM methods (removeChild loop) |
| 20 | + |
| 21 | +### 2. Demo 04 (Attention) - Version Inconsistency |
| 22 | +**File:** `demos/04-attention/js/attention-extractor.js` |
| 23 | + |
| 24 | +**Issue:** Used Transformers.js version @2.17.2 while other demos use @2.17.1 |
| 25 | + |
| 26 | +**Fix:** Changed import to use consistent version @2.17.1 |
| 27 | + |
| 28 | +### 3. Demo 05 (Transformer) - OrbitControls Error |
| 29 | +**File:** `demos/05-transformer/index.html` |
| 30 | + |
| 31 | +**Issue:** OrbitControls was loaded from `https://threejs.org/examples/js/controls/OrbitControls.js` which may not be available or have CORS issues. |
| 32 | + |
| 33 | +**Fix: ** Changed to use jsdelivr CDN: `https://cdn.jsdelivr.net/npm/[email protected]/examples/js/controls/OrbitControls.js` |
| 34 | + |
| 35 | +### 4. Demo 10 (POS Tagging) - `nlp is not defined` |
| 36 | +**File:** `demos/10-pos-tagging/index.html` |
| 37 | + |
| 38 | +**Issue:** Compromise.js was loaded from unpkg CDN which may have reliability issues. |
| 39 | + |
| 40 | +**Fix: ** Changed from `https://unpkg.com/[email protected]/builds/compromise.min.js` to `https://cdn.jsdelivr.net/npm/[email protected]/builds/compromise.min.js` |
| 41 | + |
| 42 | +### 5. Demo 13 (BERT MLM) - Transformers.js Not Loading |
| 43 | +**File:** `demos/13-bert-mlm/js/bert-model.js` |
| 44 | + |
| 45 | +**Issue:** The code tried to destructure `{ pipeline, AutoTokenizer, AutoModelForMaskedLM }` from `window.Transformers`, but the Transformers.js script tag doesn't set a global `window.Transformers` object. |
| 46 | + |
| 47 | +**Fix:** |
| 48 | +1. Added ES module import at top of file: `import { pipeline, AutoTokenizer, AutoModelForMaskedLM, Tensor } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]'` |
| 49 | +2. Removed references to `window.Transformers` |
| 50 | +3. Moved `Tensor` import to module level instead of dynamic import |
| 51 | + |
| 52 | +## Demos Analyzed But Not Changed |
| 53 | + |
| 54 | +The following demos were analyzed and found to have correct code structure. Their issues are likely environment-related: |
| 55 | + |
| 56 | +### Demo 01 (ELIZA) - Path Error |
| 57 | +- Code correctly loads from `data/eliza-rules.json` |
| 58 | +- The JSON file exists at the correct path |
| 59 | +- Issue may be CORS/local file access when not using a web server |
| 60 | + |
| 61 | +### Demo 03, 12, 14 (Embeddings, Semantic Search, Embeddings Comparison) - ES Module Issues |
| 62 | +- All three demos already have `type="module"` on script tags |
| 63 | +- Code correctly uses ES module syntax |
| 64 | +- Dynamic imports use proper CDN URLs |
| 65 | +- Issue may be CORS or CDN availability |
| 66 | + |
| 67 | +### Demo 07 (RAG) - Model Loading Fails |
| 68 | +- Uses dynamic import for Transformers.js (correct approach) |
| 69 | +- Data file `wikipedia-articles.json` exists (5MB) |
| 70 | +- Issue is likely network-related (large model download, CDN availability) |
| 71 | + |
| 72 | +### Demo 11 (Analogies) - Plotly 3D Cameraposition Error |
| 73 | +- Visualization code uses correct Plotly layout syntax |
| 74 | +- Camera configuration is properly structured: `camera: { eye: { x, y, z } }` |
| 75 | +- Error may be intermittent or browser-specific |
| 76 | + |
| 77 | +## Root Causes Identified |
| 78 | + |
| 79 | +1. **CDN Reliability:** unpkg and threejs.org direct links can be unreliable. jsdelivr is more consistent. |
| 80 | + |
| 81 | +2. **Transformers.js API:** |
| 82 | + - No `window.Transformers` global - must use ES module imports |
| 83 | + - `tokenizer.tokenize()` doesn't exist - use `encode()` + `decode()` |
| 84 | + |
| 85 | +3. **Three.js OrbitControls:** Must use versioned CDN URL that matches Three.js version |
| 86 | + |
| 87 | +4. **ES Modules:** Script tags must have `type="module"` for import/export syntax |
| 88 | + |
| 89 | +## Files Changed |
| 90 | +- `demos/02-tokenization/js/tokenizer-comparison.js` |
| 91 | +- `demos/04-attention/js/attention-extractor.js` |
| 92 | +- `demos/05-transformer/index.html` |
| 93 | +- `demos/10-pos-tagging/index.html` |
| 94 | +- `demos/13-bert-mlm/js/bert-model.js` |
0 commit comments