<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Hands On "AI Engineering": 180-Day AI and Machine Learning Course from Scratch]]></title><description><![CDATA[This exhaustive curriculum provides a full 180-day plan, designed to take a learner from foundational skills to advanced AI topics. Each day's lesson is carefully structured to build upon the last, ensuring a smooth and logical learning progression.
https://www.youtube.com/watch?v=lTBxdWEUG5g]]></description><link>https://aieworks.substack.com/s/ai-and-ml-course</link><image><url>https://substackcdn.com/image/fetch/$s_!1tXM!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe98c103-2b00-43fb-a63d-781f7bd77735_1024x1024.png</url><title>Hands On &quot;AI Engineering&quot;: 180-Day AI and Machine Learning Course from Scratch</title><link>https://aieworks.substack.com/s/ai-and-ml-course</link></image><generator>Substack</generator><lastBuildDate>Mon, 24 Aug 2026 17:55:20 GMT</lastBuildDate><atom:link href="https://aieworks.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Systemdr, Inc.]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[aieworks@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[aieworks@substack.com]]></itunes:email><itunes:name><![CDATA[AI Engineering]]></itunes:name></itunes:owner><itunes:author><![CDATA[AI Engineering]]></itunes:author><googleplay:owner><![CDATA[aieworks@substack.com]]></googleplay:owner><googleplay:email><![CDATA[aieworks@substack.com]]></googleplay:email><googleplay:author><![CDATA[AI Engineering]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Week 25-26: Natural Language Processing (NLP) ]]></title><description><![CDATA[NLP Intelligence Platform: From Fragmented NLP Scripts to a Unified Production Stack]]></description><link>https://aieworks.substack.com/p/week-25-26-natural-language-processing</link><guid isPermaLink="false">https://aieworks.substack.com/p/week-25-26-natural-language-processing</guid><dc:creator><![CDATA[sdr]]></dc:creator><pubDate>Fri, 14 Aug 2026 08:30:42 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!hw3Y!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1e47a1ed-f52b-4cc9-adb7-ec74dc78fef2_2880x2240.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2><strong>Introduction</strong></h2><blockquote><p>Most NLP tutorials stop at isolated notebooks: one file for tokenization, another for sentiment, a third for intent, none wired to HTTP, persistence, or observability. <code>week_25_26_aiml_integrated_project</code> is a self-contained capstone that consolidates classical text processing, transformer tokenization, embeddings, sequence modeling, sentiment analysis, intent routing, and response selection into one runnable system:</p></blockquote><ul><li><p>An installable Python package (<code>week2526_python</code>) with a <strong>core</strong> engine, <strong>learning</strong> lab wrappers, and a <strong>product</strong> NLP pipeline</p></li><li><p>A single FastAPI backend exposing a <strong>lab path</strong> for component exploration and a <strong>product path</strong> for analyze, predict, and experiment training</p></li><li><p>A React dashboard with live telemetry, a support-assistant workflow, a pipeline studio, and an operations console</p></li><li><p>Postgres-backed experiment metadata, PyTorch artifacts on disk, and production hardening (timeouts, structured logging, graceful ML degradation)</p></li></ul><blockquote><p>The engineer payoff is operational clarity: one <code>/analyze</code> call runs preprocess &#8594; intent &#8594; sentiment &#8594; response; training jobs become <code>Run</code> rows you poll from the dashboard; missing models fall back to lexicon and keyword rules instead of crashing the API.</p></blockquote><div><hr></div><h2><strong>Core Components</strong></h2><p>Each block below is a distinct capability inside this repository&#8212;not an external dependency.</p><h3><strong>Classical text pipeline</strong></h3><p><code>week2526_python.core.text_pipeline</code> provides NLTK-backed normalization, tokenization, stemming, lemmatization, POS tagging, and TF-IDF feature extraction. <code>nltk_bootstrap.py</code> lazily downloads punkt and stopwords only when classical processing runs, keeping cold starts fast.</p><h3><strong>Subword tokenization</strong></h3><p><code>core.tokenization.distilbert</code> and <code>core.tokenization.subword</code> wrap Hugging Face tokenizers (DistilBERT, BERT, GPT-2). Lab endpoints expose side-by-side token comparisons without loading full models on every health check.</p><h3><strong>Word embeddings</strong></h3><p><code>core.embeddings.glove</code> loads GloVe vectors or falls back to a deterministic synthetic vocabulary for offline demos. <code>glove_bootstrap.py</code> caches vector files under <code>GLOVE_CACHE_DIR</code> on startup when <code>WEEK2526_BOOTSTRAP_MISSING=true</code>.</p><h3><strong>Character sequence model</strong></h3><p><code>core.sequence_models.char_lstm</code> implements a character-level LSTM for text generation. Checkpoints live under <code>artifacts/sequence/char_lstm.pt</code> after a lab train call.</p><h3><strong>Sentiment stack</strong></h3><p>The sentiment module spans vocabulary building (<code>vocabulary.py</code>), Bi-LSTM architecture (<code>model.py</code>), training (<code>training.py</code>), lexicon scoring (<code>lexicon.py</code>), and inference (<code>inference.py</code>). Artifacts: <code>artifacts/sentiment/best_model.pt</code>, <code>vocab.json</code>, and <code>metrics.json</code>.</p><h3><strong>Intent classification</strong></h3><p><code>core.intent.classifier</code> trains a DistilBERT head over six support intents. <code>core.intent.lightweight</code> provides keyword-based routing when no checkpoint exists or when <code>WEEK2526_LIGHTWEIGHT_MODE=true</code>. Checkpoint path: <code>artifacts/intent/intent_classifier.pt</code>.</p><h3><strong>Response selection</strong></h3><p><code>core.response_selection.selector</code> maps intent + sentiment score to template replies, optionally reranking with embedding similarity when ML artifacts are present.</p><h3><strong>Product NLP engine</strong></h3><p><code>core.nlp_engine.pipeline</code> implements <code>analyze_text</code>, <code>predict_sentiment_product</code>, <code>system_status</code>, and <code>bootstrap_missing_assets</code>. This is the orchestration layer the product API calls through <code>app.services.model_loader</code>.</p><h3><strong>Model registry loader</strong></h3><p><code>backend/app/services/model_loader.py</code> lazy-loads sentiment and intent models behind a thread-safe registry, exposes <code>readiness()</code>, and never raises on missing artifacts&#8212;lexicon and lightweight intent are used instead.</p><h3><strong>Experiment and training orchestration</strong></h3><p>SQLAlchemy models (<code>Experiment</code>, <code>Run</code>, <code>Artifact</code>) plus async repositories manage product training. <code>nlp_train_job.py</code> schedules background jobs with <code>asyncio.create_task</code> and supports synchronous training via <code>?sync=true</code>.</p><h3><strong>FastAPI surface and middleware</strong></h3><p><code>backend/app/main.py</code> defines the only <code>FastAPI()</code> instance. Middleware includes request timeouts (30s default, 600s for long train routes), upload size limits (<code>WEEK2526_MAX_UPLOAD_MB</code>), JSON request logging with <code>request_id</code> and <code>latency_ms</code>, and environment-aware CORS.</p><h3><strong>React dashboard</strong></h3><p>The frontend (<code>frontend/src/ui/</code>) ships four views&#8212;Overview, Support Assistant, Pipeline Studio, and Operations&#8212;with sidebar navigation, live metric polling (4s global, 3s during active training runs), animated pipeline progress on analyze, and module cards grouped by topic (text processing, embeddings, sentiment, intent and response).</p><div><hr></div><h2><strong>Architecture Overview</strong></h2><h3><strong>Surface table</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dXqi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60df32eb-b37a-40e7-9d82-7fc569a37175_1295x292.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dXqi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60df32eb-b37a-40e7-9d82-7fc569a37175_1295x292.png 424w, https://substackcdn.com/image/fetch/$s_!dXqi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60df32eb-b37a-40e7-9d82-7fc569a37175_1295x292.png 848w, https://substackcdn.com/image/fetch/$s_!dXqi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60df32eb-b37a-40e7-9d82-7fc569a37175_1295x292.png 1272w, https://substackcdn.com/image/fetch/$s_!dXqi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60df32eb-b37a-40e7-9d82-7fc569a37175_1295x292.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dXqi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60df32eb-b37a-40e7-9d82-7fc569a37175_1295x292.png" width="1295" height="292" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/60df32eb-b37a-40e7-9d82-7fc569a37175_1295x292.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:292,&quot;width&quot;:1295,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:48722,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/201552720?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60df32eb-b37a-40e7-9d82-7fc569a37175_1295x292.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dXqi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60df32eb-b37a-40e7-9d82-7fc569a37175_1295x292.png 424w, https://substackcdn.com/image/fetch/$s_!dXqi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60df32eb-b37a-40e7-9d82-7fc569a37175_1295x292.png 848w, https://substackcdn.com/image/fetch/$s_!dXqi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60df32eb-b37a-40e7-9d82-7fc569a37175_1295x292.png 1272w, https://substackcdn.com/image/fetch/$s_!dXqi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60df32eb-b37a-40e7-9d82-7fc569a37175_1295x292.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>http://localhost:3000</p><p>OperatorsMulti-panel NLP console proxied through Nginx</p><h3><strong>Architecture diagram</strong></h3><p>The diagram below shows how the dashboard, API layer, Python package tiers, and persistence volumes connect. External caches (NLTK, Hugging Face) feed the core package without blocking the product path in lightweight mode.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xW4P!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46c30e80-47ba-43d0-bb2f-3900ff14569b_3680x2080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xW4P!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46c30e80-47ba-43d0-bb2f-3900ff14569b_3680x2080.png 424w, https://substackcdn.com/image/fetch/$s_!xW4P!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46c30e80-47ba-43d0-bb2f-3900ff14569b_3680x2080.png 848w, https://substackcdn.com/image/fetch/$s_!xW4P!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46c30e80-47ba-43d0-bb2f-3900ff14569b_3680x2080.png 1272w, https://substackcdn.com/image/fetch/$s_!xW4P!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46c30e80-47ba-43d0-bb2f-3900ff14569b_3680x2080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xW4P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46c30e80-47ba-43d0-bb2f-3900ff14569b_3680x2080.png" width="1456" height="823" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/46c30e80-47ba-43d0-bb2f-3900ff14569b_3680x2080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:823,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:431244,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/201552720?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46c30e80-47ba-43d0-bb2f-3900ff14569b_3680x2080.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xW4P!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46c30e80-47ba-43d0-bb2f-3900ff14569b_3680x2080.png 424w, https://substackcdn.com/image/fetch/$s_!xW4P!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46c30e80-47ba-43d0-bb2f-3900ff14569b_3680x2080.png 848w, https://substackcdn.com/image/fetch/$s_!xW4P!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46c30e80-47ba-43d0-bb2f-3900ff14569b_3680x2080.png 1272w, https://substackcdn.com/image/fetch/$s_!xW4P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46c30e80-47ba-43d0-bb2f-3900ff14569b_3680x2080.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://aieworks.substack.com/p/week-25-26-natural-language-processing">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Final Capstone: Build a Production NLP Intelligence System]]></title><description><![CDATA[What We&#8217;re Building Today]]></description><link>https://aieworks.substack.com/p/final-capstone-build-a-production</link><guid isPermaLink="false">https://aieworks.substack.com/p/final-capstone-build-a-production</guid><dc:creator><![CDATA[sysdai]]></dc:creator><pubDate>Sat, 01 Aug 2026 08:30:24 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!EAU8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74cde9ba-652d-4efe-bb53-d03cc64b2217_3800x2600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>What We&#8217;re Building Today</h2><ul><li><p>A multi-capability NLP Intelligence API that classifies intent, scores sentiment, and generates contextual responses &#8212; all served through a single REST endpoint.</p></li><li><p>A modular PyTorch-based pipeline where each NLP component is independently testable and swappable without touching the rest of the system.</p></li><li><p>A production-style deployment with Docker, a health-check endpoint, structured logging, and a minimal web demo interface.</p></li></ul><div><hr></div><h2>Why This Matters</h2><blockquote><p>You&#8217;ve spent 176 days learning how individual pieces work &#8212; tensors, layers, training loops, embeddings, sequence models. What separates a student from a practitioner is the ability to compose those pieces into a system that solves a real problem end-to-end. Every major NLP product at companies like OpenAI, Cohere, or Hugging Face is not one model &#8212; it&#8217;s a pipeline of coordinated components: input normalization, classification, generation, post-processing, and serving. This capstone is your first time building that pipeline yourself, which means by the end of Day 180, you&#8217;ll have produced something you can legitimately show in a job interview or deploy for real users.</p></blockquote><div><hr></div><h2>Core Concepts</h2><h3>1. The NLP Pipeline as a System, Not a Script</h3><p>A pipeline is a directed graph of transformations. Each node takes in a well-defined input and produces a well-defined output. The moment you start building pipelines this way, your code becomes composable. You can swap a rule-based intent classifier for a neural one without touching the sentiment module. You can add a new component &#8212; say, entity extraction &#8212; without modifying the response generator.</p><p>In production systems at Stripe or Shopify, the ML inference path looks exactly like this: an API gateway hands the raw text to a normalization service, which passes the cleaned text to a classification model, which produces a structured prediction object, which routes to a generation or retrieval system, which formats the final response. Each handoff is a typed contract. Today you&#8217;re building that exact pattern.</p><h3>2. Intent Classification with Lightweight Transformers</h3><p>The dominant pattern for intent classification in production is fine-tuning a pre-trained transformer on a small labeled dataset. DistilBERT &#8212; a compressed version of BERT &#8212; gives you 97% of the accuracy at 40% of the size. This is the same trade-off that powers intent routing in voice assistants at Amazon and Google.</p><p>The key insight here is that the pre-trained model already understands language at a deep level. Your fine-tuning job is not to teach it language &#8212; it&#8217;s to teach it your categories. When you have only a few hundred labeled examples, this transfer learning approach outperforms training from scratch by a wide margin. Your final classifier is really just a linear layer sitting on top of a frozen or lightly-unfrozen transformer backbone.</p><h3>3. Sentiment-Aware Response Generation</h3><p>The response generation in this system is a hybrid: a retrieval layer picks a candidate response template based on intent and sentiment score, and a neural reranker scores each candidate against the original query context. This avoids the hallucination risk of pure generation while still producing contextually relevant responses.</p><p>This pattern &#8212; retrieval-augmented generation with a reranker &#8212; is exactly what systems like Perplexity AI and Bing Chat use at scale. The reranker is a cross-encoder transformer that takes (query, candidate) pairs as input and outputs a relevance score. You&#8217;re not building the full RAG stack today, but the architecture you implement mirrors the production pattern precisely.</p><h3>4. API Design for ML Systems</h3><p>Serving an ML model is fundamentally different from serving a database. Model inference has unpredictable latency, GPU resource contention, and serialization overhead. Three patterns matter most:</p><blockquote><p><strong>Request batching:</strong> Group multiple incoming requests together before sending to the model. A batch of 32 requests takes only 1.5&#215; the time of a single request on a GPU, so throughput multiplies dramatically. Your system implements a simple synchronous batch endpoint.</p><p><strong>Response caching:</strong> Identical or near-identical queries should return cached predictions. A simple Redis-backed LRU cache cuts GPU load significantly in production. The architecture includes a cache layer even if you implement it in-memory for the capstone.</p><p><strong>Structured error envelopes:</strong> Every response &#8212; success or failure &#8212; should follow the same JSON schema. Clients must be able to rely on the response structure regardless of what happened internally. Your API will always return <code>{status, data, error, latency_ms}</code>.</p></blockquote><h3>5. Component Architecture</h3><p>The preprocessor runs first and its output is shared by both the intent classifier and the sentiment scorer &#8212; they run in parallel, then their outputs converge at the response selector. This parallel fan-out pattern keeps latency bounded to <code>max(t_intent, t_sentiment)</code> rather than <code>t_intent + t_sentiment</code>.</p><pre><code><code>                   NLP Intelligence API

   Input Text
       |
       v
   [Preprocessor]  --&gt;  normalize, tokenize, truncate
       |
       +-----------------------------+
       v                             v
   [Intent Classifier]        [Sentiment Scorer]
   (DistilBERT + linear)      (LSTM / Day 176)
       |                             |
       +-------------+---------------+
                     v
            [Response Selector]
            (retrieve + rerank)
                     |
                     v
              [JSON Response]
</code></code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!EAU8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74cde9ba-652d-4efe-bb53-d03cc64b2217_3800x2600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!EAU8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74cde9ba-652d-4efe-bb53-d03cc64b2217_3800x2600.png 424w, https://substackcdn.com/image/fetch/$s_!EAU8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74cde9ba-652d-4efe-bb53-d03cc64b2217_3800x2600.png 848w, https://substackcdn.com/image/fetch/$s_!EAU8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74cde9ba-652d-4efe-bb53-d03cc64b2217_3800x2600.png 1272w, https://substackcdn.com/image/fetch/$s_!EAU8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74cde9ba-652d-4efe-bb53-d03cc64b2217_3800x2600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!EAU8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74cde9ba-652d-4efe-bb53-d03cc64b2217_3800x2600.png" width="1456" height="996" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/74cde9ba-652d-4efe-bb53-d03cc64b2217_3800x2600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:996,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!EAU8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74cde9ba-652d-4efe-bb53-d03cc64b2217_3800x2600.png 424w, https://substackcdn.com/image/fetch/$s_!EAU8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74cde9ba-652d-4efe-bb53-d03cc64b2217_3800x2600.png 848w, https://substackcdn.com/image/fetch/$s_!EAU8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74cde9ba-652d-4efe-bb53-d03cc64b2217_3800x2600.png 1272w, https://substackcdn.com/image/fetch/$s_!EAU8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74cde9ba-652d-4efe-bb53-d03cc64b2217_3800x2600.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://aieworks.substack.com/p/final-capstone-build-a-production">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Week 23-24 : Computer Vision ]]></title><description><![CDATA[VisionClassifier Platform: From Fragmented CV Scripts to a Unified Computer Vision Stack]]></description><link>https://aieworks.substack.com/p/week-23-24-computer-vision</link><guid isPermaLink="false">https://aieworks.substack.com/p/week-23-24-computer-vision</guid><dc:creator><![CDATA[AI Engineering]]></dc:creator><pubDate>Fri, 31 Jul 2026 02:10:30 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!u3In!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc345f7ec-0d83-48a7-96ef-e0c90cff42cc_3680x1920.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2><strong>Introduction</strong></h2><p>Computer vision prototypes usually die in notebooks: one script for preprocessing, another for training, a third for evaluation, and nothing that tracks experiments or serves inference behind a stable HTTP contract. <code>week_23_24_aiml_integrated_project</code> is a self-contained capstone that consolidates the full vision pipeline into one runnable system:</p><ul><li><p>An installable Python package (<code>week2324_python</code>) with concept-named modules for preprocessing, CNNs, pooling, datasets, training loops, evaluation, export, and deployment</p></li><li><p>A FastAPI backend exposing two API surfaces: a <strong>lab path</strong> for topic exploration and a <strong>product path</strong> for experiment lifecycle management</p></li><li><p><strong>VisionClassifier Platform</strong> &#8212; a React dashboard with a guided pipeline, component studio, live training monitor, and multipart image inference</p></li><li><p>PostgreSQL-backed experiment metadata (async SQLAlchemy + Alembic), named Docker volumes for artifacts and dataset caches, and offline-safe synthetic fallbacks when CIFAR archives cannot be downloaded</p></li></ul><p>The engineer payoff is traceability and boundaries. A quick CNN smoke test is not a stray script&#8212;it is <code>train_simple_cnn</code> behind a lab route with capped batches. Production training is not a blocking HTTP call&#8212;it is <code>POST /api/v1/cv/experiments/{id}/train</code> returning HTTP 202 while <code>asyncio.create_task</code> runs ResNet fine-tuning in a worker thread, with the dashboard polling run status until completion or failure.</p><div><hr></div><h2><strong>Core Components</strong></h2><p>The stack is layered. Each topic below is a distinct building block; together they form one coherent image-classification platform.</p><h3><strong>Image preprocessing and normalization</strong></h3><p><code>image_pipeline.py</code> handles OpenCV/PIL ingestion, ImageNet-style normalization profiles (<code>CIFAR10_MEAN</code> / <code>CIFAR100_MEAN</code>), and <code>build_inference_transform</code> for 224&#215;224 upload tensors. <code>preprocess_upload_bytes</code> powers multipart inference on the product API.</p><h3><strong>Convolutional network architectures</strong></h3><p><code>SimpleCNN</code> provides a pedagogical three-block classifier for CIFAR-10 smoke tests. <code>ImageClassifier</code> is a deeper three-block production-style CNN with checkpoint saving. <code>build_resnet18_classifier</code> wraps torchvision ResNet18 with a replaceable FC head for 100-way CIFAR-100 classification. <code>inspect_feature_maps</code> in <code>cnn/debug.py</code> exposes spatial activations for architecture demos.</p><h3><strong>Pooling strategies</strong></h3>
      <p>
          <a href="https://aieworks.substack.com/p/week-23-24-computer-vision">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Days 173–176: Build a Sentiment Analyzer]]></title><description><![CDATA[Agenda]]></description><link>https://aieworks.substack.com/p/days-173176-build-a-sentiment-analyzer</link><guid isPermaLink="false">https://aieworks.substack.com/p/days-173176-build-a-sentiment-analyzer</guid><dc:creator><![CDATA[sysdai]]></dc:creator><pubDate>Wed, 29 Jul 2026 08:30:38 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!I-2p!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6f591ea-7cb9-430f-befa-6af87d358616_4100x2600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Agenda</h2><ul><li><p>Wire together everything from Days 169&#8211;172 into a single end-to-end pipeline</p></li><li><p>Build a production-style sentiment classifier on the IMDB movie reviews dataset</p></li><li><p>Train, evaluate, and serve the model through a lightweight REST inference endpoint</p></li><li><p>Measure real metrics &#8212; accuracy, F1 score, and confusion matrix &#8212; not just training loss</p></li></ul><div><hr></div><h2>Why This Matters</h2><blockquote><p>Every product that handles user-generated text has a sentiment layer somewhere. Amazon uses it to surface trending complaints before they become PR crises. Airbnb uses it to flag toxic reviews in real time. Spotify uses it on social data to figure out which artists are gaining buzz before the charts reflect it. The pattern is always the same: preprocess text, encode meaning, classify intent, act on the signal. You have all three of those pieces now &#8212; tokenization from Day 169, embeddings from Day 170, and sequence modeling from Day 172. This project stitches them into a deployable system and teaches you the engineering discipline of closing the loop from raw data to a live prediction endpoint.</p></blockquote><div><hr></div><h2>Core Concepts</h2><h3>1. The Full NLP Pipeline as One Unit</h3><p>Up to now you have built each stage in isolation. A sentiment analyzer forces you to reason about the pipeline as a single contract: garbage in one stage poisons every stage after it. The input to your model is not text &#8212; it is a fixed-length integer sequence produced by a specific tokenizer trained on a specific vocabulary. That tokenizer must be saved alongside the model weights or the model is useless at inference time. This is the single most common mistake junior engineers make when deploying NLP systems: they checkpoint the weights and throw away the tokenizer.</p><p>Think of it like a lock-and-key pair. The model is the lock; the tokenizer is the key. Ship them as one artifact.</p><h3>2. Bidirectional LSTMs for Sentiment</h3><p>A standard LSTM reads a sentence left to right. But the word &#8220;not&#8221; near the beginning of a sentence can completely invert the meaning of a word that appears twelve tokens later. A Bidirectional LSTM runs two passes &#8212; one forward, one backward &#8212; and concatenates the hidden states at each timestep. The model can now &#8220;see&#8221; what comes after a word before it decides how to weight that word. For sentiment tasks, Bi-LSTMs consistently outperform unidirectional ones by three to five percentage points on benchmark datasets with no extra training data.</p><h3>3. Pretrained GloVe Embeddings vs Learned Embeddings</h3><p>You can initialize your embedding layer with random weights and let the model learn them from scratch. That works fine if you have hundreds of thousands of training examples. For smaller datasets &#8212; under fifty thousand examples &#8212; you are better off seeding the embedding layer with pretrained GloVe vectors (100d or 200d). GloVe was trained on billions of tokens; your model gets that knowledge for free and only needs to fine-tune it. The practical difference in validation accuracy on IMDB is typically three to eight points, and training converges two to three times faster.</p><h3>4. Evaluation Beyond Accuracy</h3><p>Binary sentiment on IMDB is balanced (50% positive, 50% negative), so accuracy is a fair metric here. The moment you move to a real production dataset &#8212; say, customer support tickets where 80% are neutral &#8212; accuracy becomes misleading. A model that always predicts &#8220;neutral&#8221; gets 80% accuracy while being completely useless. F1 score, which balances precision and recall, is the metric that actually tells you whether the model is doing something useful. Wire in scikit-learn&#8217;s <code>classification_report</code> from day one so you develop the habit of looking at the full picture.</p><h3>5. The Inference Contract</h3><p>A trained model sitting in a <code>.pt</code> file does nothing for a product team. What they need is an inference function with a clean, stable interface: string in, label and confidence score out. In production this function gets wrapped in a FastAPI endpoint, containerized, and deployed behind a load balancer. Building that wrapper is as much a part of the project as training the model. The function needs to handle edge cases &#8212; empty strings, non-ASCII characters, extremely long inputs &#8212; without crashing.</p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!I-2p!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6f591ea-7cb9-430f-befa-6af87d358616_4100x2600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!I-2p!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6f591ea-7cb9-430f-befa-6af87d358616_4100x2600.png 424w, https://substackcdn.com/image/fetch/$s_!I-2p!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6f591ea-7cb9-430f-befa-6af87d358616_4100x2600.png 848w, https://substackcdn.com/image/fetch/$s_!I-2p!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6f591ea-7cb9-430f-befa-6af87d358616_4100x2600.png 1272w, https://substackcdn.com/image/fetch/$s_!I-2p!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6f591ea-7cb9-430f-befa-6af87d358616_4100x2600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!I-2p!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6f591ea-7cb9-430f-befa-6af87d358616_4100x2600.png" width="1456" height="923" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d6f591ea-7cb9-430f-befa-6af87d358616_4100x2600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:923,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!I-2p!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6f591ea-7cb9-430f-befa-6af87d358616_4100x2600.png 424w, https://substackcdn.com/image/fetch/$s_!I-2p!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6f591ea-7cb9-430f-befa-6af87d358616_4100x2600.png 848w, https://substackcdn.com/image/fetch/$s_!I-2p!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6f591ea-7cb9-430f-befa-6af87d358616_4100x2600.png 1272w, https://substackcdn.com/image/fetch/$s_!I-2p!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6f591ea-7cb9-430f-befa-6af87d358616_4100x2600.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://aieworks.substack.com/p/days-173176-build-a-sentiment-analyzer">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 172 — Recurrent Neural Networks and LSTMs]]></title><description><![CDATA[What We Are Building Today]]></description><link>https://aieworks.substack.com/p/day-172-recurrent-neural-networks</link><guid isPermaLink="false">https://aieworks.substack.com/p/day-172-recurrent-neural-networks</guid><dc:creator><![CDATA[sysdai]]></dc:creator><pubDate>Sun, 26 Jul 2026 10:31:05 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3kRn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e6031ba-94bb-4368-b623-7c1e20b5df6f_4100x2400.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!30Ox!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F585e663c-c844-4c03-8912-fccc0aa528f2_850x303.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!30Ox!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F585e663c-c844-4c03-8912-fccc0aa528f2_850x303.png 424w, https://substackcdn.com/image/fetch/$s_!30Ox!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F585e663c-c844-4c03-8912-fccc0aa528f2_850x303.png 848w, https://substackcdn.com/image/fetch/$s_!30Ox!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F585e663c-c844-4c03-8912-fccc0aa528f2_850x303.png 1272w, https://substackcdn.com/image/fetch/$s_!30Ox!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F585e663c-c844-4c03-8912-fccc0aa528f2_850x303.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!30Ox!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F585e663c-c844-4c03-8912-fccc0aa528f2_850x303.png" width="850" height="303" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/585e663c-c844-4c03-8912-fccc0aa528f2_850x303.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:303,&quot;width&quot;:850,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:41916,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/192194183?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F585e663c-c844-4c03-8912-fccc0aa528f2_850x303.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!30Ox!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F585e663c-c844-4c03-8912-fccc0aa528f2_850x303.png 424w, https://substackcdn.com/image/fetch/$s_!30Ox!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F585e663c-c844-4c03-8912-fccc0aa528f2_850x303.png 848w, https://substackcdn.com/image/fetch/$s_!30Ox!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F585e663c-c844-4c03-8912-fccc0aa528f2_850x303.png 1272w, https://substackcdn.com/image/fetch/$s_!30Ox!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F585e663c-c844-4c03-8912-fccc0aa528f2_850x303.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><div><hr></div><h2>What We Are Building Today</h2><p>By the end of this lesson you will have done three things that actually matter:</p><ul><li><p><strong>Understood why sequential data breaks standard networks</strong> &#8212; and what RNNs do differently at the architectural level.</p></li><li><p><strong>Decoded how LSTMs solve the vanishing gradient problem</strong> that crippled early RNNs, using three learned memory gates.</p></li><li><p><strong>Built a working character-level language model</strong> that generates text one character at a time &#8212; the same core idea behind every autocomplete you have ever used.</p></li><li><p><strong>Connected this to production systems</strong> at Google, Amazon, Apple, and Stripe that run LSTM-based models today.</p></li></ul><div><hr></div><h2>Why This Matters</h2><blockquote><p>Yesterday you built word embeddings &#8212; dense vector representations of meaning. Today you learn how to <strong>process sequences</strong> of those vectors over time. Every autocomplete suggestion you have typed, every translation you have read, every voice command your phone understood &#8212; all of it traces back to the sequential modeling ideas you will master today.</p><p>Even in the age of transformers, understanding RNNs and LSTMs is not optional. Production systems at Apple (on-device Siri models), Amazon (Alexa keyword detection), and trading firms (time-series forecasting) still run LSTM-based models because they are computationally lighter and interpretable. Knowing <strong>why</strong> transformers replaced RNNs requires understanding what RNNs got wrong. That knowledge gap is what separates engineers who implement AI from engineers who design it.</p></blockquote><div><hr></div><h2>Core Concepts</h2><h3>1. The Sequence Problem &#8212; Why Feedforward Networks Fall Short</h3><blockquote><p>A standard dense neural network treats every input as independent. Feed it &#8220;The cat sat on the ___&#8221; and it sees seven unrelated word vectors with no awareness of order. The network has no memory &#8212; it cannot know that &#8220;cat&#8221; modifies what comes after &#8220;sat.&#8221;</p><p>Think of it like reading a book where each page is shuffled randomly. You see the words, but the story is gone.</p><p>RNNs fix this by introducing a <strong>hidden state</strong> &#8212; a memory vector that gets updated at every time step. At step <code>t</code>, the network takes two inputs: the current word vector <code>x_t</code> and the hidden state from the previous step <code>h_{t-1}</code>. The output hidden state <code>h_t</code> encodes everything the network has seen up to position <code>t</code>.</p></blockquote><pre><code><code>h_t = tanh( W_hh &#183; h_{t-1}  +  W_xh &#183; x_t  +  b )
</code></code></pre><p>That shared weight matrix <code>W_hh</code> is identical at every time step &#8212; it is what makes RNNs parameter-efficient. A 10-step sequence and a 1,000-step sequence use exactly the same parameter count.</p><div><hr></div><h3>2. The Vanishing Gradient &#8212; The RNN&#8217;s Achilles Heel</h3><p>Here is the bitter irony. Backpropagation through an RNN means multiplying gradients across every time step. If those gradients are smaller than 1.0 (which they almost always are after a tanh), they shrink exponentially. By the time you are 50 steps back, the gradient is effectively zero.</p><p>The network literally forgets what happened earlier in the sequence. Training an RNN on a long paragraph and asking it to remember the subject from sentence one is like whispering a secret across 100 people &#8212; by the end, the message is noise.</p><blockquote><p><strong>Key Insight &#8212; The Vanishing Gradient Problem</strong> This is the single biggest reason vanilla RNNs struggle with dependencies longer than roughly 10&#8211;20 tokens. Each time step multiplies gradients together, and repeated multiplication of values less than 1.0 sends them toward zero exponentially fast. LSTMs were invented specifically to fix this.</p></blockquote><div><hr></div><h3>3. LSTMs &#8212; Learned Memory Management</h3><p>Long Short-Term Memory networks (Hochreiter &amp; Schmidhuber, 1997) solve the vanishing gradient problem with a second memory channel: the <strong>cell state</strong> <code>C_t</code>. Where the hidden state is your working memory, the cell state is long-term storage &#8212; and crucially, information flows through it additively, not multiplicatively.</p><p>LSTMs use three learned <strong>gates</strong> to control information flow:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3kRn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e6031ba-94bb-4368-b623-7c1e20b5df6f_4100x2400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3kRn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e6031ba-94bb-4368-b623-7c1e20b5df6f_4100x2400.png 424w, https://substackcdn.com/image/fetch/$s_!3kRn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e6031ba-94bb-4368-b623-7c1e20b5df6f_4100x2400.png 848w, https://substackcdn.com/image/fetch/$s_!3kRn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e6031ba-94bb-4368-b623-7c1e20b5df6f_4100x2400.png 1272w, https://substackcdn.com/image/fetch/$s_!3kRn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e6031ba-94bb-4368-b623-7c1e20b5df6f_4100x2400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3kRn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e6031ba-94bb-4368-b623-7c1e20b5df6f_4100x2400.png" width="1456" height="852" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5e6031ba-94bb-4368-b623-7c1e20b5df6f_4100x2400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:852,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3kRn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e6031ba-94bb-4368-b623-7c1e20b5df6f_4100x2400.png 424w, https://substackcdn.com/image/fetch/$s_!3kRn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e6031ba-94bb-4368-b623-7c1e20b5df6f_4100x2400.png 848w, https://substackcdn.com/image/fetch/$s_!3kRn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e6031ba-94bb-4368-b623-7c1e20b5df6f_4100x2400.png 1272w, https://substackcdn.com/image/fetch/$s_!3kRn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e6031ba-94bb-4368-b623-7c1e20b5df6f_4100x2400.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><ul><li><p></p></li></ul>
      <p>
          <a href="https://aieworks.substack.com/p/day-172-recurrent-neural-networks">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Week 21-22 : Deep Learning with TensorFlow & PyTorch (Days 141-154) ]]></title><description><![CDATA[Introduction]]></description><link>https://aieworks.substack.com/p/week-21-22-deep-learning-with-tensorflow</link><guid isPermaLink="false">https://aieworks.substack.com/p/week-21-22-deep-learning-with-tensorflow</guid><dc:creator><![CDATA[sdr]]></dc:creator><pubDate>Sat, 25 Jul 2026 00:03:53 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!4NEB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4e18b1c-6c9d-4f14-832f-3dbcc5f9351f_3600x1600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><blockquote><p>Notebook lessons teach tensors, Keras <code>Sequential</code>, PyTorch <code>nn.Module</code>, and CIFAR-10 pipelines in isolation. A platform team needs the opposite: one service that runs curriculum demos for learning, a product API for experiments and async training, and a core library that both surfaces import&#8212;without duplicating model code across fourteen days.</p><p>This project composes Days 141&#8211;147 into a single stack: <code>week2122_python</code> (TensorFlow + PyTorch cores), FastAPI with Learning and Vision APIs, Postgres-backed runs, a React dashboard on port 3000, and HTTP 501 stubs for Days 148&#8211;154 until lesson code lands.</p></blockquote><p><strong>Takeaway:</strong> You will see how to unify two deep-learning frameworks behind one vision engine, expose them through intentional API layers, and keep long training off the request thread.</p><h3><strong>System Overview</strong></h3><p>Four bands carry the design:</p><ul><li><p><strong>React + Nginx (port 3000)</strong> &#8212; unified pipeline, curriculum studio, operations monitor with live metrics polling.</p></li><li><p><strong>FastAPI (port 8000)</strong> &#8212; <code>/api/v1/week2122/learn/day{N}/...</code> for Days 141&#8211;147 demos; <code>/api/v1/vision/...</code> for experiments, Iris comparison, and CIFAR jobs; lesson aliases at <code>/api/v1/learn/lesson-{N}/</code>.</p></li><li><p><code>week2122_python</code><strong> core</strong> &#8212; <code>core/tensorflow/</code> (tensors, autodiff, Iris Sequential, MNIST, CIFAR-10 <code>tf.data</code>), <code>core/pytorch/</code> (tensors, autograd, tabular nets), <code>core/vision_engine/pipeline.py</code> (product composition), <code>core/runtime/write_gate.py</code> (Day 145 freeze pattern).</p></li><li><p><strong>Postgres + Alembic</strong> &#8212; experiments, runs, artifacts; background CIFAR training via <code>cifar_train_job.py</code> and <code>asyncio.to_thread</code>.</p></li></ul><p>Day 141&#8211;143 material surfaces as TensorFlow learning routes and MNIST smoke tests. Days 144&#8211;146 feed PyTorch learning routes and the Iris compare product endpoint. Day 147 drives CIFAR baseline training and experiment registration.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tdA_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8c58c58-b8a9-4ee0-ae33-24fc7f1705ce_3600x2480.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tdA_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8c58c58-b8a9-4ee0-ae33-24fc7f1705ce_3600x2480.png 424w, https://substackcdn.com/image/fetch/$s_!tdA_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8c58c58-b8a9-4ee0-ae33-24fc7f1705ce_3600x2480.png 848w, https://substackcdn.com/image/fetch/$s_!tdA_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8c58c58-b8a9-4ee0-ae33-24fc7f1705ce_3600x2480.png 1272w, https://substackcdn.com/image/fetch/$s_!tdA_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8c58c58-b8a9-4ee0-ae33-24fc7f1705ce_3600x2480.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tdA_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8c58c58-b8a9-4ee0-ae33-24fc7f1705ce_3600x2480.png" width="1456" height="1003" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f8c58c58-b8a9-4ee0-ae33-24fc7f1705ce_3600x2480.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1003,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:453015,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/200410866?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8c58c58-b8a9-4ee0-ae33-24fc7f1705ce_3600x2480.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tdA_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8c58c58-b8a9-4ee0-ae33-24fc7f1705ce_3600x2480.png 424w, https://substackcdn.com/image/fetch/$s_!tdA_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8c58c58-b8a9-4ee0-ae33-24fc7f1705ce_3600x2480.png 848w, https://substackcdn.com/image/fetch/$s_!tdA_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8c58c58-b8a9-4ee0-ae33-24fc7f1705ce_3600x2480.png 1272w, https://substackcdn.com/image/fetch/$s_!tdA_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8c58c58-b8a9-4ee0-ae33-24fc7f1705ce_3600x2480.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Engine / Core System Design</strong></h3><p>The core package owns tensors, training loops, and evaluation metrics. The backend owns HTTP, SQLAlchemy repositories, and job scheduling. Routes validate caps from <code>settings</code> (max epochs, batch limits) and delegate synchronously or enqueue work.</p>
      <p>
          <a href="https://aieworks.substack.com/p/week-21-22-deep-learning-with-tensorflow">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 171 — Word Embeddings: Word2Vec and GloVe]]></title><description><![CDATA[What We Cover Today]]></description><link>https://aieworks.substack.com/p/day-171-word-embeddings-word2vec</link><guid isPermaLink="false">https://aieworks.substack.com/p/day-171-word-embeddings-word2vec</guid><dc:creator><![CDATA[sysdai]]></dc:creator><pubDate>Thu, 23 Jul 2026 08:30:23 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!R0aa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dfd9af5-d463-49a9-9526-0724ad7a7970_4100x2600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>What We Cover Today</h2><ul><li><p>Understand why raw text is unusable by neural networks and what embeddings solve</p></li><li><p>Explore the architecture of Word2Vec (Skip-gram and CBOW) and GloVe</p></li><li><p>Implement embedding lookups, similarity search, and semantic arithmetic in Python</p></li><li><p>Connect word vectors to production NLP systems at scale</p></li></ul><div><hr></div><h2>Why This Matters</h2><blockquote><p>Every search engine, recommendation system, and large language model you have ever used runs on one foundational idea: words can be represented as points in high-dimensional space, and words with similar meanings cluster near each other. Without this, a model cannot know that &#8220;bank&#8221; and &#8220;financial institution&#8221; refer to similar concepts, or that &#8220;Paris&#8221; relates to &#8220;France&#8221; the same way &#8220;Tokyo&#8221; relates to &#8220;Japan.&#8221;</p><p>Word embeddings are the bridge between human language and mathematical computation. They are the reason modern NLP works at all.</p></blockquote><div><hr></div><h2>Core Concepts</h2><h3>The Problem: Language Has No Natural Numbers</h3><blockquote><p>Neural networks process tensors &#8212; grids of floating point numbers. The letter &#8220;A&#8221; means nothing to a matrix multiplication. One-hot encoding is the naive fix: represent 50,000 vocabulary words as a 50,000-dimensional vector where only one position is 1. It works, but it is catastrophically wasteful and semantically blind. &#8220;Dog&#8221; and &#8220;canine&#8221; have zero overlap in one-hot space even though they mean the same thing.</p></blockquote><h3>Word2Vec: Learning Meaning From Context</h3><p>Word2Vec, introduced by Google researchers in 2013, learns embeddings by training a shallow neural network on a deceptively simple task: given a word, predict its neighbors, or given neighbors, predict the center word.</p><p><strong>Skip-gram</strong> &#8212; Takes a center word, predicts surrounding context words. Works well for infrequent words.</p><p><strong>CBOW (Continuous Bag of Words)</strong> &#8212; Takes surrounding context words, predicts the center word. Faster, better for frequent words.</p><p>The key insight is that the network never actually cares about the prediction task. What matters is the weight matrix it builds while solving that task &#8212; a 300-dimensional vector per word that encodes semantic relationships the model learned purely from co-occurrence patterns in billions of text examples.</p><blockquote><p><strong>The &#8220;aha&#8221; moment.</strong> After training on billions of words, the geometry that emerges is astonishing. King minus man plus woman equals queen. Paris minus France plus Germany equals Berlin. These are not programmed rules. The geometry emerges entirely from statistics.</p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!R0aa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dfd9af5-d463-49a9-9526-0724ad7a7970_4100x2600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!R0aa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dfd9af5-d463-49a9-9526-0724ad7a7970_4100x2600.png 424w, https://substackcdn.com/image/fetch/$s_!R0aa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dfd9af5-d463-49a9-9526-0724ad7a7970_4100x2600.png 848w, https://substackcdn.com/image/fetch/$s_!R0aa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dfd9af5-d463-49a9-9526-0724ad7a7970_4100x2600.png 1272w, https://substackcdn.com/image/fetch/$s_!R0aa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dfd9af5-d463-49a9-9526-0724ad7a7970_4100x2600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!R0aa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dfd9af5-d463-49a9-9526-0724ad7a7970_4100x2600.png" width="1456" height="923" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2dfd9af5-d463-49a9-9526-0724ad7a7970_4100x2600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:923,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!R0aa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dfd9af5-d463-49a9-9526-0724ad7a7970_4100x2600.png 424w, https://substackcdn.com/image/fetch/$s_!R0aa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dfd9af5-d463-49a9-9526-0724ad7a7970_4100x2600.png 848w, https://substackcdn.com/image/fetch/$s_!R0aa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dfd9af5-d463-49a9-9526-0724ad7a7970_4100x2600.png 1272w, https://substackcdn.com/image/fetch/$s_!R0aa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dfd9af5-d463-49a9-9526-0724ad7a7970_4100x2600.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://aieworks.substack.com/p/day-171-word-embeddings-word2vec">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 170: Text Preprocessing and Tokenization]]></title><description><![CDATA[What We Cover Today]]></description><link>https://aieworks.substack.com/p/day-170-text-preprocessing-and-tokenization</link><guid isPermaLink="false">https://aieworks.substack.com/p/day-170-text-preprocessing-and-tokenization</guid><dc:creator><![CDATA[sysdai]]></dc:creator><pubDate>Mon, 20 Jul 2026 08:30:32 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!xaJc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee0af34-3afe-490a-b21f-d18d2a7e6981_4100x2300.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>What We Cover Today</h2><ul><li><p>Why raw text is useless to a neural network, and what preprocessing actually does</p></li><li><p>The tokenization spectrum: from character-level splits to subword vocabularies</p></li><li><p>How modern NLP pipelines (BERT, GPT, LLaMA) tokenize text at production scale</p></li><li><p>Building a preprocessing pipeline from scratch: cleaning, normalization, tokenization, and encoding</p></li><li><p>Where this sits in a live AI system&#8217;s data flow</p></li></ul><div><hr></div><h2>Why This Matters</h2><blockquote><p>Yesterday you got the 10,000-foot view of NLP. Today you go one level down into the engine room. Every language model &#8212; whether it&#8217;s the BERT model powering Google Search or the GPT-4 backbone behind ChatGPT &#8212; starts with the exact same problem: text is just a sequence of Unicode characters, and neural networks only understand numbers.</p><p>Text preprocessing is the translation layer. It transforms messy, human-written language into clean, structured numerical representations that a model can actually learn from. Get this wrong and your model learns noise. Get it right and you&#8217;ve handed your model a consistent, information-dense signal. At companies like OpenAI, Hugging Face, and Cohere, entire teams are dedicated to tokenizer design &#8212; not because it&#8217;s glamorous, but because a bad tokenizer caps the ceiling on everything built on top of it.</p></blockquote><p><strong>Tokenizers are not utilities. They are model components.</strong></p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xaJc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee0af34-3afe-490a-b21f-d18d2a7e6981_4100x2300.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xaJc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee0af34-3afe-490a-b21f-d18d2a7e6981_4100x2300.png 424w, https://substackcdn.com/image/fetch/$s_!xaJc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee0af34-3afe-490a-b21f-d18d2a7e6981_4100x2300.png 848w, https://substackcdn.com/image/fetch/$s_!xaJc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee0af34-3afe-490a-b21f-d18d2a7e6981_4100x2300.png 1272w, https://substackcdn.com/image/fetch/$s_!xaJc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee0af34-3afe-490a-b21f-d18d2a7e6981_4100x2300.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xaJc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee0af34-3afe-490a-b21f-d18d2a7e6981_4100x2300.png" width="1456" height="817" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6ee0af34-3afe-490a-b21f-d18d2a7e6981_4100x2300.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:817,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xaJc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee0af34-3afe-490a-b21f-d18d2a7e6981_4100x2300.png 424w, https://substackcdn.com/image/fetch/$s_!xaJc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee0af34-3afe-490a-b21f-d18d2a7e6981_4100x2300.png 848w, https://substackcdn.com/image/fetch/$s_!xaJc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee0af34-3afe-490a-b21f-d18d2a7e6981_4100x2300.png 1272w, https://substackcdn.com/image/fetch/$s_!xaJc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ee0af34-3afe-490a-b21f-d18d2a7e6981_4100x2300.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>Core Concepts</h2><h3>1. The Raw Text Problem</h3><p>Neural networks are mathematical functions. They compute dot products, matrix multiplications, and nonlinear activations &#8212; all operations that require floating-point numbers. The sentence <code>"The model crashed at 3am!!"</code> has no numeric form until you create one.</p><p>Before you even think about tokenization, the text itself needs to be cleaned. Production text is full of HTML artifacts (<code>&amp;amp;</code>, <code>&lt;br/&gt;</code>), inconsistent Unicode, mixed case, multiple whitespace characters, and null bytes from encoding issues. These irregularities don&#8217;t just add noise &#8212; they fragment your vocabulary. <code>"Apple"</code>, <code>"apple"</code>, and <code>"APPLE"</code> would all become different tokens if you skip lowercasing. That&#8217;s three entries in your vocabulary table for the same semantic concept.</p><p>The cleaning phase handles:</p><ul><li><p>Lowercasing (where appropriate)</p></li><li><p>HTML unescaping and tag stripping</p></li><li><p>Unicode normalization (NFC vs NFD)</p></li><li><p>Punctuation handling</p></li><li><p>Whitespace collapsing</p></li></ul><p>This is not optional housekeeping &#8212; it directly determines vocabulary size, which determines model parameter count.</p><div><hr></div><h3>2. Tokenization Strategies</h3><p>Tokenization is the act of splitting text into discrete units called tokens. Three main strategies exist, and each makes a different tradeoff.</p><p><strong>Word-level tokenization</strong> splits on whitespace and punctuation. Simple and interpretable &#8212; <code>"the cat sat"</code> becomes <code>["the", "cat", "sat"]</code>. The fatal flaw: out-of-vocabulary (OOV) words. If your training data never contained <code>"transformer"</code>, the model has no representation for it at inference time. Vocabularies also explode &#8212; English alone has 500,000+ words, and that&#8217;s before you add technical jargon, names, and typos.</p><p><strong>Character-level tokenization</strong> splits into individual characters. No OOV problem by definition &#8212; every character is in your alphabet. But sequences become extremely long, and the model must learn to compose meaning from scratch, which requires vastly more training data and compute.</p><p><strong>Subword tokenization</strong> is the practical solution that modern systems use. The insight is elegant: keep common words as single tokens, but split rare or unknown words into meaningful sub-pieces. The word <code>"tokenization"</code> might become <code>["token", "ization"]</code>. The word <code>"unhappiness"</code> might become <code>["un", "happiness"]</code>. The model sees morphemic structure rather than opaque character soup.</p><blockquote><p><strong>Two dominant subword algorithms:</strong></p><p><strong>Byte Pair Encoding (BPE)</strong> &#8212; used by GPT-2, GPT-3, GPT-4, and LLaMA. Starts with character-level tokenization and iteratively merges the most frequent adjacent pairs until a target vocabulary size is reached.</p><p><strong>WordPiece</strong> &#8212; used by BERT. Same general idea as BPE, but uses a likelihood-based merge criterion instead of raw frequency. Results in a vocabulary of 30,000&#8211;100,000 tokens that covers essentially any input text without OOV issues.</p></blockquote><div><hr></div><h3>3. Vocabulary and Encoding</h3><p>Once you have tokens, you need to map them to integers &#8212; this is the vocabulary lookup. The vocabulary is a dictionary: <code>{"the": 0, "cat": 1, ...}</code>. Every token in your corpus gets a unique integer ID. Special tokens are added explicitly to handle structural positions in a sequence.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Agt3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa27e2547-a36c-4fc5-b23d-fa878e4f8d01_840x350.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Agt3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa27e2547-a36c-4fc5-b23d-fa878e4f8d01_840x350.png 424w, https://substackcdn.com/image/fetch/$s_!Agt3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa27e2547-a36c-4fc5-b23d-fa878e4f8d01_840x350.png 848w, https://substackcdn.com/image/fetch/$s_!Agt3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa27e2547-a36c-4fc5-b23d-fa878e4f8d01_840x350.png 1272w, https://substackcdn.com/image/fetch/$s_!Agt3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa27e2547-a36c-4fc5-b23d-fa878e4f8d01_840x350.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Agt3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa27e2547-a36c-4fc5-b23d-fa878e4f8d01_840x350.png" width="840" height="350" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a27e2547-a36c-4fc5-b23d-fa878e4f8d01_840x350.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:350,&quot;width&quot;:840,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:50135,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/191960002?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa27e2547-a36c-4fc5-b23d-fa878e4f8d01_840x350.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Agt3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa27e2547-a36c-4fc5-b23d-fa878e4f8d01_840x350.png 424w, https://substackcdn.com/image/fetch/$s_!Agt3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa27e2547-a36c-4fc5-b23d-fa878e4f8d01_840x350.png 848w, https://substackcdn.com/image/fetch/$s_!Agt3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa27e2547-a36c-4fc5-b23d-fa878e4f8d01_840x350.png 1272w, https://substackcdn.com/image/fetch/$s_!Agt3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa27e2547-a36c-4fc5-b23d-fa878e4f8d01_840x350.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>After encoding, each sentence is a list of integers. This is the actual input to the embedding layer &#8212; not the words themselves.</p><div><hr></div><h3>4. Attention Masks and the Padding Problem</h3><p>Batching sequences requires them to be the same length. But sentences are not. The solution is to pad shorter sequences with <code>[PAD]</code> tokens up to the maximum sequence length in the batch, then provide an <strong>attention mask</strong> &#8212; a binary vector marking which positions are real tokens (<code>1</code>) and which are padding (<code>0</code>).</p><p>The transformer&#8217;s attention mechanism uses this mask to ignore padded positions during computation. This is architectural plumbing that most tutorials skip, but it&#8217;s fundamental to how batched inference works at production scale.</p><div><hr></div><h2>Component Architecture</h2><p>The preprocessing pipeline has five distinct stages. Each stage is stateless except the Tokenizer and Encoder &#8212; both depend on a trained vocabulary file (typically a <code>.json</code> or <code>.txt</code> vocab file loaded at startup). In production systems, this vocabulary file is versioned alongside the model weights.</p><pre><code><code>Raw Input Text
      |
      v
+---------------------+
|   Text Cleaner      |  --&gt; strip HTML, normalize unicode, collapse whitespace
+---------------------+
      |
      v
+---------------------+
|   Normalizer        |  --&gt; lowercase, remove/keep punctuation, handle numbers
+---------------------+
      |
      v
+---------------------+
|   Tokenizer         |  --&gt; split into subword tokens using BPE/WordPiece vocab
+---------------------+
      |
      v
+---------------------+
|   Encoder           |  --&gt; map tokens --&gt; integer IDs via vocabulary lookup
+---------------------+
      |
      v
+---------------------+
|   Padder/Masker     |  --&gt; pad to batch length, generate attention masks
+---------------------+
      |
      v
 Tensor [batch_size, seq_len]  &lt;--&gt;  Model Input
</code></code></pre><blockquote><p><strong>Critical production note:</strong> Swapping a vocabulary file without updating the corresponding model weights is a silent failure mode. The model receives a different token distribution than it was trained on and produces degraded outputs with no error thrown. Tokenizer and weights are always versioned together.</p></blockquote><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SGVw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdd73daa-83fb-4830-b6b1-149a219eeaa2_4100x2400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SGVw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdd73daa-83fb-4830-b6b1-149a219eeaa2_4100x2400.png 424w, https://substackcdn.com/image/fetch/$s_!SGVw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdd73daa-83fb-4830-b6b1-149a219eeaa2_4100x2400.png 848w, https://substackcdn.com/image/fetch/$s_!SGVw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdd73daa-83fb-4830-b6b1-149a219eeaa2_4100x2400.png 1272w, https://substackcdn.com/image/fetch/$s_!SGVw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdd73daa-83fb-4830-b6b1-149a219eeaa2_4100x2400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SGVw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdd73daa-83fb-4830-b6b1-149a219eeaa2_4100x2400.png" width="1456" height="852" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cdd73daa-83fb-4830-b6b1-149a219eeaa2_4100x2400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:852,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SGVw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdd73daa-83fb-4830-b6b1-149a219eeaa2_4100x2400.png 424w, https://substackcdn.com/image/fetch/$s_!SGVw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdd73daa-83fb-4830-b6b1-149a219eeaa2_4100x2400.png 848w, https://substackcdn.com/image/fetch/$s_!SGVw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdd73daa-83fb-4830-b6b1-149a219eeaa2_4100x2400.png 1272w, https://substackcdn.com/image/fetch/$s_!SGVw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcdd73daa-83fb-4830-b6b1-149a219eeaa2_4100x2400.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>Real-World Connection</h2><p>At Stripe, every merchant-facing text field &#8212; chargeback descriptions, dispute notes, fraud explanations &#8212; passes through a preprocessing pipeline before hitting the risk classification model. The tokenizer there is trained on financial domain text to ensure that terms like <code>"ACH reversal"</code> and <code>"NSF fee"</code> are preserved as meaningful units rather than split arbitrarily.</p><p>At Google, the search query tokenizer handles 8.5 billion queries per day, many in low-resource languages where subword tokenization is the only viable strategy. The design of that tokenizer &#8212; its vocabulary size, its handling of numerals and punctuation &#8212; directly affects ranking quality for billions of searches.</p><p>Tokenizers are not utilities. They are model components.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aieworks.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands On "AI Engineering" is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><div><hr></div><h1>Implementation: Build, Test and Demo</h1><h2>Github Link:</h2><p><a href="https://github.com/sysdr/aiml/tree/main/day170/day170_tokenization">https://github.com/sysdr/aiml/tree/main/day170/day170_tokenization</a></p><blockquote><p><strong>What you will build:</strong> A complete, five-stage NLP preprocessing pipeline in Python, ending with batched tensors ready to feed directly into a BERT or GPT-2 model. All code lives in <code>lesson_code.py</code>. The test suite (20 pytest tests) lives in <code>test_lesson.py</code>. </p></blockquote><div><hr></div><p><strong>Expected output:</strong> a confirmation message and a listing of the five files created inside <code>day170_tokenization/</code>.</p><div><hr></div><h2>Step 1 &#8212; Set Up the Environment</h2><p> Installs all pinned dependencies, and downloads the NLTK and spaCy data required for tokenization exercises.<br></p><p><strong>Expected output:</strong> <code>"Environment ready."</code> followed by the activation command. If you see a warning about a missing Rust compiler, ignore it &#8212; the Hugging Face tokenizers library ships pre-compiled wheels.</p><blockquote><p><strong>With Docker instead:</strong> <code>docker build -t day170 . &amp;&amp; docker run --rm day170</code></p></blockquote><div><hr></div><h2>Step 2 &#8212; Run the Lesson Demo</h2><p><code>lesson_code.py</code> runs all seven sections of the pipeline in sequence, printing labeled output for each stage. Read through the terminal output as it runs &#8212; every printed block corresponds to a Core Concept section above.</p><pre><code><code>python lesson_code.py
</code></code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sl_S!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd947fa52-e764-4978-be6f-451e764a5e87_857x662.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sl_S!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd947fa52-e764-4978-be6f-451e764a5e87_857x662.png 424w, https://substackcdn.com/image/fetch/$s_!sl_S!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd947fa52-e764-4978-be6f-451e764a5e87_857x662.png 848w, https://substackcdn.com/image/fetch/$s_!sl_S!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd947fa52-e764-4978-be6f-451e764a5e87_857x662.png 1272w, https://substackcdn.com/image/fetch/$s_!sl_S!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd947fa52-e764-4978-be6f-451e764a5e87_857x662.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sl_S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd947fa52-e764-4978-be6f-451e764a5e87_857x662.png" width="857" height="662" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d947fa52-e764-4978-be6f-451e764a5e87_857x662.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:662,&quot;width&quot;:857,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:113006,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/191960002?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd947fa52-e764-4978-be6f-451e764a5e87_857x662.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sl_S!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd947fa52-e764-4978-be6f-451e764a5e87_857x662.png 424w, https://substackcdn.com/image/fetch/$s_!sl_S!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd947fa52-e764-4978-be6f-451e764a5e87_857x662.png 848w, https://substackcdn.com/image/fetch/$s_!sl_S!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd947fa52-e764-4978-be6f-451e764a5e87_857x662.png 1272w, https://substackcdn.com/image/fetch/$s_!sl_S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd947fa52-e764-4978-be6f-451e764a5e87_857x662.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>Step 3 &#8212; Run the Test Suite</h2><p>The test suite has 20 tests organized into six classes, each covering a distinct stage of the pipeline.</p><pre><code><code>pytest test_lesson.py -v
</code></code></pre><p><strong>Expected result:</strong> 20 passed in approximately 8 seconds. The first run will download the BERT and GPT-2 tokenizer files from Hugging Face (~500 MB total). Subsequent runs use the local cache.</p><p>To also see line coverage:</p><pre><code><code>pytest test_lesson.py -v --cov=lesson_code --cov-report=term-missing
</code></code></pre><div><hr></div><h2>Step 4 &#8212; Key Exercises to Try Yourself</h2><h3>Exercise A &#8212; Compare tokenization of a medical vs. general sentence</h3><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;e406a1f3-cce7-4bea-aed0-d714cdd88b80&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">from lesson_code import load_bert_tokenizer, bert_tokenize

tok = load_bert_tokenizer()
medical = "The patient presented with tachycardia and diaphoresis."
general = "The patient felt dizzy and was sweating."

print(bert_tokenize(tok, medical))
print(bert_tokenize(tok, general))
</code></pre></div><p>Pay attention to how the medical terms fragment into subwords. This is exactly why clinical NLP teams train domain-specific tokenizers.</p><div><hr></div><h3>Exercise B &#8212; Inspect the token distribution of a larger corpus</h3><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;61b89dec-71df-4f37-96c0-68c884b32f83&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">from lesson_code import load_bert_tokenizer, token_length_analysis

sentences = [
    "BERT uses WordPiece tokenization.",
    "GPT uses byte pair encoding.",
    "Both are subword tokenization methods.",
    "The quick brown fox jumps over the lazy dog.",
    "Tokenizers convert text into numbers.",
]

tok = load_bert_tokenizer()
print(token_length_analysis(tok, sentences))
</code></pre></div><p>Change <code>max_length</code> in <code>bert_encode_batch</code> to the <code>max</code> value from this analysis. Compare the number of padding tokens before and after.</p><div><hr></div><h3>Exercise C &#8212; Find where BERT and GPT-2 agree</h3><pre><code><code>from lesson_code import load_bert_tokenizer, load_gpt2_tokenizer, compare_tokenizers

words = ["running", "cats", "the", "AI", "unhappiness"]
result = compare_tokenizers(load_bert_tokenizer(), load_gpt2_tokenizer(), words)

for word, splits in result.items():
    match = splits['bert_wordpiece'] == splits['gpt2_bpe']
    print(f"{word:15s}  match={match}  bert={splits['bert_wordpiece']}")
</code></code></pre><p>Common English function words like <code>"the"</code> and <code>"cats"</code> produce identical single-token results in both tokenizers. Rare or morphologically complex words diverge.</p><div><hr></div><h2>Verification Checklist</h2><p>Before moving to Day 171, confirm you can answer each of these from memory or by looking at <code>lesson_code.py</code>:</p><ol><li><p>Why does skipping lowercasing inflate vocabulary size?</p></li><li><p>What does the <code>##</code> prefix mean in a WordPiece token list?</p></li><li><p>What is the integer ID for <code>[CLS]</code> in <code>bert-base-uncased</code>? (Hint: check <code>bert_tok.cls_token_id</code>)</p></li><li><p>What shape does <code>bert_encode_batch</code> return for 3 sentences padded to <code>max_length=32</code>?</p></li><li><p>Why do BERT and GPT-2 produce different splits for the same word?</p></li><li><p>What does a <code>0</code> in the <code>attention_mask</code> indicate, and why does it matter?</p></li><li><p>If you swap the <code>vocab.json</code> file without updating model weights, what happens at inference?</p></li></ol><div><hr></div><h2>Working Code Demo:</h2><div id="youtube2-E-xi636mvY4" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;E-xi636mvY4&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/E-xi636mvY4?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aieworks.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands On "AI Engineering" is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Day 169 · Introduction to NLP — Teaching Machines to Read]]></title><link>https://aieworks.substack.com/p/day-169-introduction-to-nlp-teaching</link><guid isPermaLink="false">https://aieworks.substack.com/p/day-169-introduction-to-nlp-teaching</guid><dc:creator><![CDATA[sysdai]]></dc:creator><pubDate>Fri, 17 Jul 2026 03:34:03 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ZILe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac96a5f9-b441-46bd-9b07-f9d079645297_4100x2200.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZILe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac96a5f9-b441-46bd-9b07-f9d079645297_4100x2200.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZILe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac96a5f9-b441-46bd-9b07-f9d079645297_4100x2200.png 424w, https://substackcdn.com/image/fetch/$s_!ZILe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac96a5f9-b441-46bd-9b07-f9d079645297_4100x2200.png 848w, https://substackcdn.com/image/fetch/$s_!ZILe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac96a5f9-b441-46bd-9b07-f9d079645297_4100x2200.png 1272w, https://substackcdn.com/image/fetch/$s_!ZILe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac96a5f9-b441-46bd-9b07-f9d079645297_4100x2200.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZILe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac96a5f9-b441-46bd-9b07-f9d079645297_4100x2200.png" width="1456" height="781" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ac96a5f9-b441-46bd-9b07-f9d079645297_4100x2200.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:781,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZILe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac96a5f9-b441-46bd-9b07-f9d079645297_4100x2200.png 424w, https://substackcdn.com/image/fetch/$s_!ZILe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac96a5f9-b441-46bd-9b07-f9d079645297_4100x2200.png 848w, https://substackcdn.com/image/fetch/$s_!ZILe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac96a5f9-b441-46bd-9b07-f9d079645297_4100x2200.png 1272w, https://substackcdn.com/image/fetch/$s_!ZILe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac96a5f9-b441-46bd-9b07-f9d079645297_4100x2200.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://aieworks.substack.com/p/day-169-introduction-to-nlp-teaching">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 159 — Day 168 Project Kickoff: Image Classifier for a Complex Dataset]]></title><description><![CDATA[Today at a Glance]]></description><link>https://aieworks.substack.com/p/day-159-day-168-project-kickoff-image</link><guid isPermaLink="false">https://aieworks.substack.com/p/day-159-day-168-project-kickoff-image</guid><dc:creator><![CDATA[sysdai]]></dc:creator><pubDate>Tue, 14 Jul 2026 08:30:13 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!dlfV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc281dc43-99d5-4135-9c4e-e25c46406435_4100x2500.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Today at a Glance</strong></p><ul><li><p>Set up a production-grade image classification project targeting CIFAR-100 (100 classes, 60,000 images)</p></li><li><p>Conduct exploratory data analysis to understand class distribution, sample quality, and inter-class similarity</p></li><li><p>Design the full system architecture, from raw pixel ingestion through augmentation pipelines, model selection, and evaluation strategy</p></li><li><p>Lay down the project scaffolding that Days 160-168 will build on top of</p></li></ul><div><hr></div><h2>Why This Matters</h2><blockquote><p>Every production computer vision system at scale &#8212; Google Lens classifying 200+ plant species, Tesla&#8217;s object detection distinguishing pedestrians from cyclists, Pinterest&#8217;s visual search mapping images to 10,000+ product categories &#8212; started exactly here: someone had to decide the architecture before writing a single line of model code.</p><p>The decisions you make on Day 1 of a project, dataset splits, augmentation strategy, whether to train from scratch or fine-tune, have cascading effects on every downstream component. A model that reaches 92% accuracy on the training set but ships with a leaky train/test split is worse than useless in production. This project week teaches you to think like an ML engineer, not just a model trainer.</p></blockquote><div><hr></div><h2>Agenda</h2><ol><li><p>Understanding CIFAR-100 and why complex datasets break naive CNN approaches</p></li><li><p>Project architecture: pipeline layers, data flow, and evaluation contracts</p></li><li><p>Exploratory data analysis: class imbalance, visual difficulty, superclass groupings</p></li><li><p>Transfer learning decision framework: when to fine-tune vs. train from scratch</p></li><li><p>Project directory scaffolding and reproducibility practices</p></li></ol><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dlfV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc281dc43-99d5-4135-9c4e-e25c46406435_4100x2500.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dlfV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc281dc43-99d5-4135-9c4e-e25c46406435_4100x2500.png 424w, https://substackcdn.com/image/fetch/$s_!dlfV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc281dc43-99d5-4135-9c4e-e25c46406435_4100x2500.png 848w, https://substackcdn.com/image/fetch/$s_!dlfV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc281dc43-99d5-4135-9c4e-e25c46406435_4100x2500.png 1272w, https://substackcdn.com/image/fetch/$s_!dlfV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc281dc43-99d5-4135-9c4e-e25c46406435_4100x2500.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dlfV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc281dc43-99d5-4135-9c4e-e25c46406435_4100x2500.png" width="1456" height="888" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c281dc43-99d5-4135-9c4e-e25c46406435_4100x2500.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:888,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dlfV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc281dc43-99d5-4135-9c4e-e25c46406435_4100x2500.png 424w, https://substackcdn.com/image/fetch/$s_!dlfV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc281dc43-99d5-4135-9c4e-e25c46406435_4100x2500.png 848w, https://substackcdn.com/image/fetch/$s_!dlfV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc281dc43-99d5-4135-9c4e-e25c46406435_4100x2500.png 1272w, https://substackcdn.com/image/fetch/$s_!dlfV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc281dc43-99d5-4135-9c4e-e25c46406435_4100x2500.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://aieworks.substack.com/p/day-159-day-168-project-kickoff-image">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Week 19-20 : Neural Networks from Scratch (Days 127-140) ]]></title><description><![CDATA[Introduction]]></description><link>https://aieworks.substack.com/p/week-19-20-neural-networks-from-scratch</link><guid isPermaLink="false">https://aieworks.substack.com/p/week-19-20-neural-networks-from-scratch</guid><dc:creator><![CDATA[sdr]]></dc:creator><pubDate>Mon, 13 Jul 2026 09:51:53 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!orsz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F710914d8-5a87-41f4-bf14-cfa431a38d34_3600x2080.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><blockquote><p>Most &#8220;from scratch&#8221; neural network repos stop at a script that prints accuracy. That&#8217;s useful for learning, but it&#8217;s not a system engineers can iterate on: there&#8217;s no stable API surface, no durable run metadata, no clear separation between reusable core logic and orchestration, and no way to observe what the system is doing while it works.</p><p>This project turns Days 127-140 into a single production-style application: a NumPy-first core package, a FastAPI backend that exposes both Learning and Product endpoints, a React dashboard, and a Postgres-backed run ledger. You&#8217;ll walk away with a practical blueprint for integrating neural network lesson code into an operable service without losing the educational &#8220;glass box&#8221; properties.</p></blockquote><h3><strong>System Overview</strong></h3><p>The stack is intentionally small and explicit:</p><ul><li><p><strong>React dashboard (Vite build served by Nginx, port 3000)</strong> &#8212; one integrated workbench: a stepper for Days 127&#8211;131 and a Product view for experiments and runs.</p></li><li><p><strong>FastAPI backend (port 8000)</strong> &#8212; <code>/api/v1/week1920/learn/...</code> for curriculum-backed demos, <code>/api/v1/ml/...</code> for persisted experiments, runs, artifacts, and live metrics.</p></li><li><p><code>week1920_python</code><strong> core package</strong> &#8212; the &#8220;engine room&#8221;: perceptron training, activation primitives, MLP forward passes, backprop trainer, MNIST forward model, plus a minimal losses/metrics surface.</p></li><li><p><strong>Persistence</strong> &#8212; Postgres (async SQLAlchemy + Alembic) for experiment and run metadata; Docker volumes for artifacts and cache directories.</p></li></ul><p>The curriculum topics don&#8217;t show up as separate apps. They show up as modules that the system can execute: perceptron training is a callable unit, activations expose gradient checks, backprop is a bounded training job, and MNIST is operationalized as a forward pipeline (with training staged for later days).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!orsz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F710914d8-5a87-41f4-bf14-cfa431a38d34_3600x2080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!orsz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F710914d8-5a87-41f4-bf14-cfa431a38d34_3600x2080.png 424w, https://substackcdn.com/image/fetch/$s_!orsz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F710914d8-5a87-41f4-bf14-cfa431a38d34_3600x2080.png 848w, https://substackcdn.com/image/fetch/$s_!orsz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F710914d8-5a87-41f4-bf14-cfa431a38d34_3600x2080.png 1272w, https://substackcdn.com/image/fetch/$s_!orsz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F710914d8-5a87-41f4-bf14-cfa431a38d34_3600x2080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!orsz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F710914d8-5a87-41f4-bf14-cfa431a38d34_3600x2080.png" width="1456" height="841" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/710914d8-5a87-41f4-bf14-cfa431a38d34_3600x2080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:841,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:367415,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/200256096?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F710914d8-5a87-41f4-bf14-cfa431a38d34_3600x2080.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!orsz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F710914d8-5a87-41f4-bf14-cfa431a38d34_3600x2080.png 424w, https://substackcdn.com/image/fetch/$s_!orsz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F710914d8-5a87-41f4-bf14-cfa431a38d34_3600x2080.png 848w, https://substackcdn.com/image/fetch/$s_!orsz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F710914d8-5a87-41f4-bf14-cfa431a38d34_3600x2080.png 1272w, https://substackcdn.com/image/fetch/$s_!orsz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F710914d8-5a87-41f4-bf14-cfa431a38d34_3600x2080.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Engine / Core System Design</strong></h3><p>The core package owns math and algorithms; the backend owns HTTP, input validation, and orchestration. That separation is what keeps the &#8220;lesson logic&#8221; reusable while letting the system behave like a service.</p><p>At the core layer, the &#8220;day modules&#8221; are not scripts. They&#8217;re importable functions and classes that can be dispatched from either the Learning API or a Product workflow. The engine layer is minimal on purpose: it standardizes conventions (shapes, seeds, bounded defaults) and provides a stable surface for orchestration.</p><p>Two details matter for correctness and operability:</p><h4><strong>1) A consistent parameter convention</strong></h4><p>The core uses a consistent dense-layer convention (<code>(fan_in, fan_out)</code> weights and <code>Z = A @ W + b</code>) across MLP and MNIST. That makes later training code predictable and keeps &#8220;shape debugging&#8221; localized.</p><h4><strong>2) Non-blocking orchestration</strong></h4><p>Learning endpoints can still do &#8220;real work&#8221; (training or dataset access), but the backend must remain responsive while that happens. This repo moves CPU-heavy work into <code>asyncio.to_thread(...)</code> so the event loop isn&#8217;t blocked by NumPy loops or dataset preprocessing.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;59b7b14f-f3c3-4c60-98c6-94adbddac3bc&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">backend/app/routes/week1920_lab.py (excerpt)
@week1920_router.post(&#8221;/learn/day130/backprop/train&#8221;)

async def learn_day130_backprop_train(epochs: int = 200, lr: float = 0.05, seed: int = 0):
    epochs = min(epochs, settings.WEEK1920_MAX_EPOCHS_LEARN)
def _run_sync():
        X, y = get_xor_data()
        y2 = y.reshape(-1, 1).astype(float)
        net = Trainer(layer_sizes=[2, 4, 4, 1], hidden_activation=&#8221;relu&#8221;, seed=seed)
        result = net.train(X, y2, epochs=epochs, lr=lr)
        preds = net.predict(X)
        accuracy = float(np.mean((preds &gt;= 0.5).astype(int).flatten() == y2.flatten()))
return {&#8221;final_loss&#8221;: result[&#8221;final_loss&#8221;], &#8220;accuracy&#8221;: accuracy}
return await asyncio.to_thread(_run_sync)</code></pre></div><h3><strong>Data Flow Diagram Reference</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!o0-r!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b5a939f-93f6-4fd3-a372-df8b8b82d327_3680x2080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!o0-r!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b5a939f-93f6-4fd3-a372-df8b8b82d327_3680x2080.png 424w, https://substackcdn.com/image/fetch/$s_!o0-r!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b5a939f-93f6-4fd3-a372-df8b8b82d327_3680x2080.png 848w, https://substackcdn.com/image/fetch/$s_!o0-r!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b5a939f-93f6-4fd3-a372-df8b8b82d327_3680x2080.png 1272w, https://substackcdn.com/image/fetch/$s_!o0-r!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b5a939f-93f6-4fd3-a372-df8b8b82d327_3680x2080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!o0-r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b5a939f-93f6-4fd3-a372-df8b8b82d327_3680x2080.png" width="1456" height="823" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1b5a939f-93f6-4fd3-a372-df8b8b82d327_3680x2080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:823,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:403195,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/200256096?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b5a939f-93f6-4fd3-a372-df8b8b82d327_3680x2080.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!o0-r!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b5a939f-93f6-4fd3-a372-df8b8b82d327_3680x2080.png 424w, https://substackcdn.com/image/fetch/$s_!o0-r!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b5a939f-93f6-4fd3-a372-df8b8b82d327_3680x2080.png 848w, https://substackcdn.com/image/fetch/$s_!o0-r!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b5a939f-93f6-4fd3-a372-df8b8b82d327_3680x2080.png 1272w, https://substackcdn.com/image/fetch/$s_!o0-r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b5a939f-93f6-4fd3-a372-df8b8b82d327_3680x2080.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>API Design</strong></h3><p>The API is split into two surfaces that behave differently:</p><ul><li><p><strong>Learning</strong> endpoints are stateless, bounded, and &#8220;demo-first.&#8221;</p></li><li><p><strong>Product</strong> endpoints are stateful: they create experiments, record runs, and surface artifacts/metrics for the dashboard.</p></li></ul><p>Representative endpoints:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;json&quot;,&quot;nodeId&quot;:&quot;fa8d23f9-8cec-4fad-a775-8e003c818f2c&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-json">GET /api/v1/week1920/learn/day127/perceptron?dataset=xor&amp;max_epochs=50
Response: {
  lesson: "day127",
  dataset: "xor",
  accuracy: number,
  training: { converged: boolean, epochs_run: number, training_errors: number[] }
}</code></pre></div><p>Runs the perceptron training loop with bounded epochs to demonstrate separability limits.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;json&quot;,&quot;nodeId&quot;:&quot;4e8e6b89-cd1b-447a-9881-b61ecf709de0&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-json">POST /api/v1/week1920/learn/day130/backprop/train?epochs=200&amp;lr=0.05
Response: {
  lesson: "day130",
  epochs: number,
  lr: number,
  final_loss: number,
  loss_history_tail: number[],
  accuracy: number
}</code></pre></div><p>Executes a bounded XOR backprop training run; designed to stay responsive by pushing CPU work off the event loop.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;json&quot;,&quot;nodeId&quot;:&quot;03a934b6-7a4d-4699-86d9-cd377afae19c&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-json">POST /api/v1/ml/experiments
Request:  { name: string, dataset_profile: "mnist", model_backend: "numpy_scratch", task_type: "mnist" }
Response: { id: uuid, name: string, created_at: string, architecture_json: object }</code></pre></div><p>Creates a durable experiment record that will own many runs.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;json&quot;,&quot;nodeId&quot;:&quot;1b2bd9d7-d1df-4bcb-b0f1-f31e9bb6d242&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-json">GET /api/v1/ml/metrics/live
Response: {
  server_time: string,
  experiments_count: number,
  runs_summary: { running: number, pending: number, completed: number, failed: number },
  latest_runs: [{ id: uuid, run_type: string, status: string, elapsed_seconds: number|null }]
}</code></pre></div><p>A lightweight polling endpoint for the dashboard; it must remain fast even when learning routes are active.</p><p>In FastAPI, the pattern is consistent: validate inputs, then delegate to core modules or background jobs. The Product layer uses repositories to persist metadata, and services to execute work.</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:&quot;814f3f07-204a-40d7-a286-3e11e1dbd25d&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">backend/app/routes/week1920_lab.py (excerpt)
@ml_router.post(&#8221;/experiments&#8221;, response_model=ExperimentOut)
async def create_experiment(payload: ExperimentCreate, db: AsyncSession = Depends(get_db)):
    repo = ExperimentRepository(db)
    exp = await repo.create_experiment(
        name=payload.name,
        dataset_profile=payload.dataset_profile,
        model_backend=payload.model_backend,
        objective_metric=payload.objective_metric,
        task_type=payload.task_type,
        architecture_json=payload.architecture_json or {&#8221;layers&#8221;: [784, 128, 64, 10]},
)
return ExperimentOut.model_validate(exp)</code></pre></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://aieworks.substack.com/subscribe&quot;,&quot;text&quot;:&quot;Subscribe to access Github&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://aieworks.substack.com/subscribe"><span>Subscribe to access Github</span></a></p><h3>Github Link:</h3><p><a href="https://github.com/sysdr/aiml-p/tree/main/week_19_20_aiml_integrated_project">https://github.com/sysdr/aiml-p/tree/main/week_19_20_aiml_integrated_project</a></p><h2><strong>Implementation Guide</strong></h2>
      <p>
          <a href="https://aieworks.substack.com/p/week-19-20-neural-networks-from-scratch">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 158 — Building a CNN for Image Classification]]></title><description><![CDATA[What You Will Build Today]]></description><link>https://aieworks.substack.com/p/day-158-building-a-cnn-for-image</link><guid isPermaLink="false">https://aieworks.substack.com/p/day-158-building-a-cnn-for-image</guid><dc:creator><![CDATA[sysdai]]></dc:creator><pubDate>Sat, 11 Jul 2026 08:30:18 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3hrH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7df794cc-a69c-4db4-8fea-66d3d75a4f0d_4300x2400.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>What You Will Build Today</h2><ul><li><p>Assemble a complete CNN pipeline &#8212; from raw pixels to class predictions &#8212; using PyTorch</p></li><li><p>Wire together Conv2d, BatchNorm, pooling, and fully connected layers into a production-grade architecture</p></li><li><p>Train, evaluate, and export a model that mirrors what ships in real computer vision systems</p></li></ul><h2>Why This Matters</h2><blockquote><p>Every camera-facing AI product you interact with &#8212; <strong>Google Photos</strong> tagging your vacation, <strong>Tesla&#8217;s Autopilot</strong> reading lane markings, <strong>Pinterest&#8217;s visual search</strong> matching your screenshots &#8212; runs on a CNN at its core. Yesterday you understood pooling and flattening in isolation. Today those pieces click together into a working classifier you can train end-to-end. This is the moment the theory stops being abstract. A student who completes today&#8217;s lesson walks away with a neural network architecture that, with more data and compute, could power a real production service.</p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3hrH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7df794cc-a69c-4db4-8fea-66d3d75a4f0d_4300x2400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3hrH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7df794cc-a69c-4db4-8fea-66d3d75a4f0d_4300x2400.png 424w, https://substackcdn.com/image/fetch/$s_!3hrH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7df794cc-a69c-4db4-8fea-66d3d75a4f0d_4300x2400.png 848w, https://substackcdn.com/image/fetch/$s_!3hrH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7df794cc-a69c-4db4-8fea-66d3d75a4f0d_4300x2400.png 1272w, https://substackcdn.com/image/fetch/$s_!3hrH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7df794cc-a69c-4db4-8fea-66d3d75a4f0d_4300x2400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3hrH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7df794cc-a69c-4db4-8fea-66d3d75a4f0d_4300x2400.png" width="1456" height="813" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7df794cc-a69c-4db4-8fea-66d3d75a4f0d_4300x2400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:813,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3hrH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7df794cc-a69c-4db4-8fea-66d3d75a4f0d_4300x2400.png 424w, https://substackcdn.com/image/fetch/$s_!3hrH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7df794cc-a69c-4db4-8fea-66d3d75a4f0d_4300x2400.png 848w, https://substackcdn.com/image/fetch/$s_!3hrH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7df794cc-a69c-4db4-8fea-66d3d75a4f0d_4300x2400.png 1272w, https://substackcdn.com/image/fetch/$s_!3hrH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7df794cc-a69c-4db4-8fea-66d3d75a4f0d_4300x2400.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://aieworks.substack.com/p/day-158-building-a-cnn-for-image">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 157: Pooling Layers and Flattening]]></title><description><![CDATA[Agenda]]></description><link>https://aieworks.substack.com/p/day-157-pooling-layers-and-flattening</link><guid isPermaLink="false">https://aieworks.substack.com/p/day-157-pooling-layers-and-flattening</guid><dc:creator><![CDATA[sysdai]]></dc:creator><pubDate>Wed, 08 Jul 2026 08:30:35 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!us7e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce30bb94-7abb-470b-ac4e-dbbc433c71c8_3900x2100.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Agenda</h2><ul><li><p>Why CNNs need pooling and what happens without it</p></li><li><p>Max pooling vs. average pooling: mechanics and tradeoffs</p></li><li><p>Flattening: the bridge from spatial features to classification decisions</p></li><li><p>How pooling and flattening appear in production vision pipelines at Google, Tesla, and Meta</p></li></ul><div><hr></div><h2>Why This Matters</h2><blockquote><p>Yesterday you built your first convolutional layers. They extract features &#8212; edges, textures, gradients &#8212; by sliding filters across an image. But there is a problem: a raw convolution output is enormous, spatially sensitive, and computationally expensive to work with. Pooling solves this. It compresses spatial information aggressively while retaining the parts that actually matter. Flattening then converts those compressed feature maps into a vector that a dense classifier can reason over.</p><p>Together, these two operations form the backbone of every production image classifier you have ever interacted with &#8212; the photo tagger on Instagram, the defect detector in a Tesla factory, the medical scan reader at a hospital.</p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!us7e!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce30bb94-7abb-470b-ac4e-dbbc433c71c8_3900x2100.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!us7e!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce30bb94-7abb-470b-ac4e-dbbc433c71c8_3900x2100.png 424w, https://substackcdn.com/image/fetch/$s_!us7e!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce30bb94-7abb-470b-ac4e-dbbc433c71c8_3900x2100.png 848w, https://substackcdn.com/image/fetch/$s_!us7e!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce30bb94-7abb-470b-ac4e-dbbc433c71c8_3900x2100.png 1272w, https://substackcdn.com/image/fetch/$s_!us7e!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce30bb94-7abb-470b-ac4e-dbbc433c71c8_3900x2100.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!us7e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce30bb94-7abb-470b-ac4e-dbbc433c71c8_3900x2100.png" width="1456" height="784" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ce30bb94-7abb-470b-ac4e-dbbc433c71c8_3900x2100.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:784,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!us7e!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce30bb94-7abb-470b-ac4e-dbbc433c71c8_3900x2100.png 424w, https://substackcdn.com/image/fetch/$s_!us7e!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce30bb94-7abb-470b-ac4e-dbbc433c71c8_3900x2100.png 848w, https://substackcdn.com/image/fetch/$s_!us7e!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce30bb94-7abb-470b-ac4e-dbbc433c71c8_3900x2100.png 1272w, https://substackcdn.com/image/fetch/$s_!us7e!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fce30bb94-7abb-470b-ac4e-dbbc433c71c8_3900x2100.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://aieworks.substack.com/p/day-157-pooling-layers-and-flattening">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Week 17-18 : Advanced ML & Course Review (Days 113-126) ]]></title><description><![CDATA[Introduction]]></description><link>https://aieworks.substack.com/p/week-17-18-advanced-ml-and-course</link><guid isPermaLink="false">https://aieworks.substack.com/p/week-17-18-advanced-ml-and-course</guid><dc:creator><![CDATA[sdr]]></dc:creator><pubDate>Mon, 06 Jul 2026 01:04:13 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!FxHN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd800abba-6572-4634-8d1a-0ae3571c8788_3600x2320.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2><strong>Introduction</strong></h2><blockquote><p>Most course notebooks stop at a trained model on disk. Production teams need something else: repeatable experiments, tracked runs, persisted artifacts, and lesson code that does not fork into fifteen copies. This project unifies Days 113&#8211;126 into one stack&#8212;a shared Python core, a FastAPI service with separate Learning and Product APIs, a React dashboard, and Postgres-backed experiment metadata with background Optuna tuning.</p><p>You will walk away knowing how to compose gradient-boosting lessons into a single engine, expose them through two API surfaces, and run hyperparameter search without blocking HTTP or corrupting your database schema.</p></blockquote><h3><strong>System Overview</strong></h3><p>The system splits into four bands:</p><ul><li><p><strong>React dashboard (Nginx, port 3000)</strong> &#8212; experiment workbench, learning demos, live run polling.</p></li><li><p><strong>FastAPI backend (port 8000)</strong> &#8212; <code>/api/v1/week1718/learn/*</code> for curriculum demos; <code>/api/v1/ml/*</code> for experiments, runs, artifacts, and studies.</p></li><li><p><code>week1718_python</code><strong> core</strong> &#8212; synthetic fraud data, scratch GBM, XGBoost/LightGBM trainers, bias&#8211;variance diagnostics, Optuna objectives, inference benchmarks.</p></li><li><p><strong>Persistence</strong> &#8212; Postgres (async SQLAlchemy + Alembic) for product metadata; dedicated SQLite file for Optuna RDB; Docker volume for joblib models.</p></li></ul><p>Day 113&#8217;s scratch booster lives in the learning route. Day 114&#8217;s library comparison powers <code>/learn/day114</code>. Days 115&#8211;116 inform diagnostics and search configuration inside <code>optuna_tuning.py</code>. Days 117&#8211;126 drive the product flow: baseline run &#8594; async tune job &#8594; artifact write &#8594; study reference row.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FxHN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd800abba-6572-4634-8d1a-0ae3571c8788_3600x2320.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FxHN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd800abba-6572-4634-8d1a-0ae3571c8788_3600x2320.png 424w, https://substackcdn.com/image/fetch/$s_!FxHN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd800abba-6572-4634-8d1a-0ae3571c8788_3600x2320.png 848w, https://substackcdn.com/image/fetch/$s_!FxHN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd800abba-6572-4634-8d1a-0ae3571c8788_3600x2320.png 1272w, https://substackcdn.com/image/fetch/$s_!FxHN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd800abba-6572-4634-8d1a-0ae3571c8788_3600x2320.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FxHN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd800abba-6572-4634-8d1a-0ae3571c8788_3600x2320.png" width="1456" height="938" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d800abba-6572-4634-8d1a-0ae3571c8788_3600x2320.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:938,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:436764,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/200072490?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd800abba-6572-4634-8d1a-0ae3571c8788_3600x2320.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FxHN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd800abba-6572-4634-8d1a-0ae3571c8788_3600x2320.png 424w, https://substackcdn.com/image/fetch/$s_!FxHN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd800abba-6572-4634-8d1a-0ae3571c8788_3600x2320.png 848w, https://substackcdn.com/image/fetch/$s_!FxHN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd800abba-6572-4634-8d1a-0ae3571c8788_3600x2320.png 1272w, https://substackcdn.com/image/fetch/$s_!FxHN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd800abba-6572-4634-8d1a-0ae3571c8788_3600x2320.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Engine / Core System Design</strong></h3>
      <p>
          <a href="https://aieworks.substack.com/p/week-17-18-advanced-ml-and-course">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 156 — Convolutional Neural Networks (CNNs)]]></title><description><![CDATA[What We Cover Today]]></description><link>https://aieworks.substack.com/p/day-156-convolutional-neural-networks</link><guid isPermaLink="false">https://aieworks.substack.com/p/day-156-convolutional-neural-networks</guid><dc:creator><![CDATA[sysdai]]></dc:creator><pubDate>Sun, 05 Jul 2026 08:31:09 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!v0ax!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadeab4c6-8569-4e8f-9ce4-658c75dc730b_4000x2600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>What We Cover Today</h2><ul><li><p>What a convolutional layer actually does &#8212; and why it beats dense layers for images</p></li><li><p>Filters, kernels, feature maps, stride, and padding explained from first principles</p></li><li><p>CNN architecture: how layers stack to build spatial understanding</p></li><li><p>Implementing a CNN in PyTorch for image classification</p></li><li><p>Where CNNs live inside production computer vision pipelines at scale</p></li></ul><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!v0ax!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadeab4c6-8569-4e8f-9ce4-658c75dc730b_4000x2600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!v0ax!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadeab4c6-8569-4e8f-9ce4-658c75dc730b_4000x2600.png 424w, https://substackcdn.com/image/fetch/$s_!v0ax!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadeab4c6-8569-4e8f-9ce4-658c75dc730b_4000x2600.png 848w, https://substackcdn.com/image/fetch/$s_!v0ax!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadeab4c6-8569-4e8f-9ce4-658c75dc730b_4000x2600.png 1272w, https://substackcdn.com/image/fetch/$s_!v0ax!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadeab4c6-8569-4e8f-9ce4-658c75dc730b_4000x2600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!v0ax!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadeab4c6-8569-4e8f-9ce4-658c75dc730b_4000x2600.png" width="1456" height="946" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/adeab4c6-8569-4e8f-9ce4-658c75dc730b_4000x2600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:946,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!v0ax!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadeab4c6-8569-4e8f-9ce4-658c75dc730b_4000x2600.png 424w, https://substackcdn.com/image/fetch/$s_!v0ax!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadeab4c6-8569-4e8f-9ce4-658c75dc730b_4000x2600.png 848w, https://substackcdn.com/image/fetch/$s_!v0ax!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadeab4c6-8569-4e8f-9ce4-658c75dc730b_4000x2600.png 1272w, https://substackcdn.com/image/fetch/$s_!v0ax!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fadeab4c6-8569-4e8f-9ce4-658c75dc730b_4000x2600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://aieworks.substack.com/p/day-156-convolutional-neural-networks">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 155: Introduction to Computer Vision]]></title><description><![CDATA[Today&#8217;s Agenda]]></description><link>https://aieworks.substack.com/p/day-155-introduction-to-computer</link><guid isPermaLink="false">https://aieworks.substack.com/p/day-155-introduction-to-computer</guid><dc:creator><![CDATA[sysdai]]></dc:creator><pubDate>Thu, 02 Jul 2026 08:31:02 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!S3B7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0753c850-7ce3-4960-95cb-85705b232e51_4100x2150.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Today&#8217;s Agenda</h2><ul><li><p>What computer vision actually is, and why it matters beyond &#8220;image recognition&#8221;</p></li><li><p>How raw pixels become structured data that neural networks can learn from</p></li><li><p>The classic CV pipeline: acquire, preprocess, extract, classify</p></li><li><p>Hands-on: build an image preprocessing pipeline using OpenCV and PIL</p></li><li><p>How production CV systems at Google, Tesla, and Waymo handle millions of frames per second</p></li></ul><div><hr></div><h2>Why This Matters</h2><blockquote><p>You have spent the last 28 days building neural networks that work on numbers in tables. Computer vision breaks that constraint entirely. The moment you can teach a model to understand images, you unlock a class of problems that touches nearly every industry on the planet: autonomous vehicles reading road signs, radiologists&#8217; assistants flagging tumors in X-rays, warehouse robots locating items on shelves, retail systems tracking inventory without barcodes.</p><p>Every one of those systems starts with the same foundational step you are learning today: turning a raw image into a tensor a neural network can process. This is the bridge between the physical world and the computational one.</p></blockquote><div><hr></div><h2>Core Concepts</h2><h3>What an Image Actually Is</h3><p>An image is nothing more than a 3-dimensional array of numbers. A standard color photo with dimensions 224 &#215; 224 pixels is a tensor of shape (224, 224, 3), where the three channels represent red, green, and blue intensity values ranging from 0 to 255. Grayscale images collapse to (224, 224, 1). That is it. The moment you accept that an image is just a matrix of integers, the entire field of computer vision becomes approachable.</p><p>NumPy stores this as a uint8 array. PyTorch and TensorFlow expect float32 tensors with values normalized to the range [0.0, 1.0]. Every preprocessing pipeline you write will include a division by 255.0 at some point. That single operation is the handshake between the imaging world and the deep learning world.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aieworks.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands On "AI Engineering" is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!S3B7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0753c850-7ce3-4960-95cb-85705b232e51_4100x2150.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!S3B7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0753c850-7ce3-4960-95cb-85705b232e51_4100x2150.png 424w, https://substackcdn.com/image/fetch/$s_!S3B7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0753c850-7ce3-4960-95cb-85705b232e51_4100x2150.png 848w, https://substackcdn.com/image/fetch/$s_!S3B7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0753c850-7ce3-4960-95cb-85705b232e51_4100x2150.png 1272w, https://substackcdn.com/image/fetch/$s_!S3B7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0753c850-7ce3-4960-95cb-85705b232e51_4100x2150.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!S3B7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0753c850-7ce3-4960-95cb-85705b232e51_4100x2150.png" width="1456" height="764" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0753c850-7ce3-4960-95cb-85705b232e51_4100x2150.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:764,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!S3B7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0753c850-7ce3-4960-95cb-85705b232e51_4100x2150.png 424w, https://substackcdn.com/image/fetch/$s_!S3B7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0753c850-7ce3-4960-95cb-85705b232e51_4100x2150.png 848w, https://substackcdn.com/image/fetch/$s_!S3B7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0753c850-7ce3-4960-95cb-85705b232e51_4100x2150.png 1272w, https://substackcdn.com/image/fetch/$s_!S3B7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0753c850-7ce3-4960-95cb-85705b232e51_4100x2150.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>The Four-Stage CV Pipeline</h3><p>Production computer vision systems, from Google Lens to Tesla Autopilot, follow a consistent architecture regardless of their ultimate task.</p><p><strong>Stage 1 &#8212; Acquisition.</strong> Raw image data enters the system from a camera, file system, or network stream. Resolution, color space, and frame rate are properties of the acquisition layer. Tesla&#8217;s FSD cameras capture at 36 frames per second across eight cameras simultaneously. Every frame must enter the pipeline within 27 milliseconds to maintain real-time performance.</p><p><strong>Stage 2 &#8212; Preprocessing.</strong> Raw images are noisy, inconsistently sized, and poorly lit. Preprocessing normalizes all of that. Resizing to a fixed resolution (commonly 224 &#215; 224 for ImageNet-pretrained models), converting color spaces (BGR to RGB is a classic OpenCV gotcha), applying normalization using dataset-specific mean and standard deviation values &#8212; these operations create the clean, consistent input tensors that models expect. Skipping or misapplying preprocessing is the single most common cause of poor model performance on good data.</p><p><strong>Stage 3 &#8212; Feature Extraction.</strong> This is where neural networks replaced decades of hand-crafted algorithms. Before deep learning, engineers spent careers writing code to detect edges with Sobel filters, find corners with Harris detectors, and describe local patches with SIFT descriptors. Convolutional Neural Networks, which you will build tomorrow, learn those detectors automatically from data. Today, understanding that features are the intermediate representations of meaningful visual structure &#8212; edges, textures, shapes, objects &#8212; is the conceptual foundation you need.</p><p><strong>Stage 4 &#8212; Inference and Post-processing.</strong> The model produces raw scores (logits) or bounding box coordinates. Post-processing converts those into human-readable outputs: class labels, confidence scores, pixel masks. Non-Maximum Suppression (NMS) for object detection, sigmoid/softmax for classification, and morphological operations for segmentation all live here.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ont6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75a92b02-27dd-4e99-8c46-8997b2c8199a_970x495.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ont6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75a92b02-27dd-4e99-8c46-8997b2c8199a_970x495.png 424w, https://substackcdn.com/image/fetch/$s_!ont6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75a92b02-27dd-4e99-8c46-8997b2c8199a_970x495.png 848w, https://substackcdn.com/image/fetch/$s_!ont6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75a92b02-27dd-4e99-8c46-8997b2c8199a_970x495.png 1272w, https://substackcdn.com/image/fetch/$s_!ont6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75a92b02-27dd-4e99-8c46-8997b2c8199a_970x495.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ont6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75a92b02-27dd-4e99-8c46-8997b2c8199a_970x495.png" width="970" height="495" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/75a92b02-27dd-4e99-8c46-8997b2c8199a_970x495.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:495,&quot;width&quot;:970,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:203929,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/191004020?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75a92b02-27dd-4e99-8c46-8997b2c8199a_970x495.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ont6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75a92b02-27dd-4e99-8c46-8997b2c8199a_970x495.png 424w, https://substackcdn.com/image/fetch/$s_!ont6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75a92b02-27dd-4e99-8c46-8997b2c8199a_970x495.png 848w, https://substackcdn.com/image/fetch/$s_!ont6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75a92b02-27dd-4e99-8c46-8997b2c8199a_970x495.png 1272w, https://substackcdn.com/image/fetch/$s_!ont6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75a92b02-27dd-4e99-8c46-8997b2c8199a_970x495.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>Color Spaces and Channel Ordering</h3><p>A persistent source of bugs in CV pipelines is channel ordering. OpenCV loads images in BGR order by default. PyTorch models trained on ImageNet expect RGB. Loading an image with <code>cv2.imread()</code> and passing it directly to a pretrained model produces subtly wrong results that are difficult to diagnose because the model still produces predictions, just worse ones. Always apply <code>cv2.cvtColor(img, cv2.COLOR_BGR2RGB)</code> when bridging OpenCV and PyTorch.</p><blockquote><p><strong>Watch out for this one.</strong> BGR vs RGB is the most common silent bug in new CV pipelines. The model will still run and produce predictions &#8212; they will just be quietly wrong. It is the kind of error that costs days of debugging. One line of code prevents it entirely.</p></blockquote><h3>Normalization: Mean and Standard Deviation</h3><p>ImageNet-pretrained models expect inputs normalized with specific statistics: mean = [0.485, 0.456, 0.406] and std = [0.229, 0.224, 0.225] across the RGB channels. These numbers represent the channel-wise mean and standard deviation of the entire ImageNet training set. Applying this normalization ensures your input distribution matches what the model learned on. Forgetting this step when using pretrained weights is another quiet killer of model performance.</p><blockquote><p><strong>Why these specific numbers?</strong> They were computed once across all 1.2 million images in the ImageNet dataset and published with the original models. Every researcher and engineer in the field uses the same values. You will have them memorized by the end of this module.</p></blockquote><h3>Key Concepts at a Glance</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5IBA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ccb184-9c9f-4103-a974-3ded5d6dd353_853x463.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5IBA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ccb184-9c9f-4103-a974-3ded5d6dd353_853x463.png 424w, https://substackcdn.com/image/fetch/$s_!5IBA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ccb184-9c9f-4103-a974-3ded5d6dd353_853x463.png 848w, https://substackcdn.com/image/fetch/$s_!5IBA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ccb184-9c9f-4103-a974-3ded5d6dd353_853x463.png 1272w, https://substackcdn.com/image/fetch/$s_!5IBA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ccb184-9c9f-4103-a974-3ded5d6dd353_853x463.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5IBA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ccb184-9c9f-4103-a974-3ded5d6dd353_853x463.png" width="853" height="463" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/72ccb184-9c9f-4103-a974-3ded5d6dd353_853x463.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:463,&quot;width&quot;:853,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:80647,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/191004020?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ccb184-9c9f-4103-a974-3ded5d6dd353_853x463.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5IBA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ccb184-9c9f-4103-a974-3ded5d6dd353_853x463.png 424w, https://substackcdn.com/image/fetch/$s_!5IBA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ccb184-9c9f-4103-a974-3ded5d6dd353_853x463.png 848w, https://substackcdn.com/image/fetch/$s_!5IBA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ccb184-9c9f-4103-a974-3ded5d6dd353_853x463.png 1272w, https://substackcdn.com/image/fetch/$s_!5IBA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72ccb184-9c9f-4103-a974-3ded5d6dd353_853x463.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>Implementation</h2><p>These five steps walk you through the full preprocessing pipeline from raw file to normalized tensor. The code is intentionally minimal &#8212; you are learning what each operation does before you run the full package.</p><h3>1. Install the dependencies</h3><pre><code><code>pip install opencv-python-headless Pillow torch torchvision numpy matplotlib
</code></code></pre><h3>2. Load and inspect a raw image</h3><p>This is the acquisition stage. You are reading the file, confirming its shape, and understanding the data type before touching anything.</p><pre><code><code>import cv2
import numpy as np
from PIL import Image

img_bgr = cv2.imread("sample.jpg")
print(f"Shape: {img_bgr.shape}")   # (H, W, 3)
print(f"Dtype: {img_bgr.dtype}")   # uint8
print(f"Range: [{img_bgr.min()}, {img_bgr.max()}]")
</code></code></pre><h3>3. Build the preprocessing pipeline</h3><p><code>transforms.Compose</code> chains operations in order. <code>ToTensor</code> handles the /255.0 conversion and the HxWxC to CxHxW transpose simultaneously. <code>Normalize</code> applies the ImageNet statistics channel by channel.</p><pre><code><code>import torch
from torchvision import transforms

preprocess = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor(),                # uint8 HxWxC -&gt; float32 CxHxW, divides by 255
    transforms.Normalize(
        mean=[0.485, 0.456, 0.406],
        std=[0.229, 0.224, 0.225]
    )
])

img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
pil_img = Image.fromarray(img_rgb)
tensor  = preprocess(pil_img)
print(f"Tensor shape: {tensor.shape}")   # torch.Size([3, 224, 224])
print(f"Tensor range: [{tensor.min():.3f}, {tensor.max():.3f}]")
</code></code></pre><h3>4. Batch multiple images</h3><p>Models do not process a single image at a time &#8212; they process batches. <code>torch.stack</code> adds the N dimension, turning a list of [3, 224, 224] tensors into a single [N, 3, 224, 224] tensor ready for a model.</p><pre><code><code>batch = torch.stack([preprocess(Image.open(p).convert("RGB")) for p in image_paths])
print(f"Batch shape: {batch.shape}")  # [N, 3, 224, 224]
</code></code></pre><h3>5. Visualize preprocessed tensors</h3><p>You cannot display a normalized tensor directly &#8212; the values are outside the 0&#8211;1 range that image viewers expect. This function reverses the normalization so you can confirm the preprocessing visually.</p><pre><code><code>def tensor_to_displayable(tensor):
    # Undo normalization for visualization
    mean = torch.tensor([0.485, 0.456, 0.406]).view(3, 1, 1)
    std  = torch.tensor([0.229, 0.224, 0.225]).view(3, 1, 1)
    img  = tensor * std + mean
    img  = img.permute(1, 2, 0).numpy()
    return (img * 255).astype(np.uint8)
</code></code></pre><div><hr></div><h2>Build, Test, and Demo</h2><h2>Github Link:</h2><p><a href="https://github.com/sysdr/aiml/tree/main/day155/day155_cv_intro">https://github.com/sysdr/aiml/tree/main/day155/day155_cv_intro</a></p><p>The bash script scaffolds the full implementation package &#8212; <code>lesson_code.py</code>, <code>test_lesson.py</code>, <code>setup.sh</code>, <code>requirements.txt</code>, and <code>README.md</code>. <br></p><h3>1. Run the demo</h3><pre><code><code>python lesson_code.py
</code></code></pre><p>Expected output:</p><pre><code><code>=== Stage 1: Acquisition &amp; Inspection ===
  shape_hwc: (100, 280, 3)
  dtype: uint8    pixel_min: 0    pixel_max: 255

=== Stage 2: Preprocessing ===
  Output tensor shape : torch.Size([3, 224, 224])
  Output tensor dtype : torch.float32

=== Stage 3: Channel Statistics ===
  R -&gt; mean=-0.1823  std=1.0241  range=[-2.117, 2.640]
  G -&gt; mean=-0.0514  std=0.9876  range=[-1.966, 2.428]
  B -&gt; mean= 0.0241  std=1.0103  range=[-1.804, 2.640]

=== Stage 4: Batch Demo ===
  Batch shape: torch.Size([2, 3, 224, 224])

Pipeline visualization saved: pipeline_demo.png
All stages complete.
</code></code></pre><h3>2. Run the test suite</h3><pre><code><code>pytest test_lesson.py -v
</code></code></pre><p>25 tests across 5 classes: <code>TestAcquisition</code>, <code>TestColorConversion</code>, <code>TestPreprocessing</code>, <code>TestBatchProcessing</code>, and <code>TestStatisticsAndInverse</code>. All pass in under 30 seconds.</p><pre><code><code>test_lesson.py::TestAcquisition::test_load_returns_dict PASSED
test_lesson.py::TestAcquisition::test_correct_dimensions PASSED
test_lesson.py::TestColorConversion::test_bgr_to_rgb_channels_swapped PASSED
test_lesson.py::TestPreprocessing::test_output_shape_default PASSED
...
25 passed in 18.43s
</code></code></pre><h3>3. Docker (optional)</h3><pre><code><code>docker build -t day155-cv .
docker run --rm day155-cv python lesson_code.py
docker run --rm day155-cv pytest test_lesson.py -v
</code></code></pre><div><hr></div><h2>Real-World Connection</h2><p>At Google Photos, every uploaded image passes through a preprocessing pipeline before entering the embedding model that powers visual search. The pipeline handles EXIF-aware rotation correction, HEIC-to-JPEG conversion, and adaptive resizing based on detected content type &#8212; portrait photos resize differently than landscape panoramas. At Waymo, the preprocessing pipeline for camera inputs must be deterministic and latency-bounded to guarantee frame synchrony across the sensor array. What you built today is a simplified version of those same foundations. The tensor you produce in step 3 is exactly what gets passed into a convolutional neural network.</p><div><hr></div><h2>Working Code Demo:</h2><div id="youtube2-4eGloFTOAWg" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;4eGloFTOAWg&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/4eGloFTOAWg?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://aieworks.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Hands On "AI Engineering" is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Week 15–16 : Reinforcement Learning & Other Topics (Days 99-112) ]]></title><description><![CDATA[Introduction]]></description><link>https://aieworks.substack.com/p/week-1516-reinforcement-learning</link><guid isPermaLink="false">https://aieworks.substack.com/p/week-1516-reinforcement-learning</guid><dc:creator><![CDATA[sdr]]></dc:creator><pubDate>Tue, 30 Jun 2026 23:41:12 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!JKJ8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F778ca5de-0816-448a-a1df-f539895d49b6_3600x1520.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="callout-block" data-callout="true"><p>Preparing for Job Interviews explore preparation material - <a href="https://aieworks.systemdrd.com/">here</a></p><p>Subscribe to get Free copy of <strong><a href="https://systemdrd.com/ebooks/ai-engineers-blueprint/">AI Engineer&#8217;s Blueprint</a></strong></p></div><h3><strong>Introduction</strong></h3><blockquote><p>Reinforcement learning and recommender systems usually arrive as separate lesson repos: a grid-world Q-learning script here, a MovieLens notebook there. That works for studying algorithms in isolation. It breaks when you need <strong>one deployable service</strong> that trains policies, serves hybrid recommendations, exposes curriculum demos over HTTP, and gives operators a live dashboard.</p></blockquote><p><code>week_15_16_aiml_integrated_project</code> unifies Days 99&#8211;112 into a single Dockerized stack:</p><ul><li><p>A <strong>learning layer</strong> that exposes each lesson through structured FastAPI routes.</p></li><li><p>A <strong>core layer</strong> that holds canonical RL and recommender implementations.</p></li><li><p>A <strong>product layer</strong> that runs grid-world training and MovieLens hybrid workflows end-to-end.</p></li><li><p>A <strong>React dashboard</strong> behind nginx for learners and operators.</p></li></ul><p>You will walk away knowing how Q-learning agents, collaborative SVD, content-based filters, and adaptive hybrids become <strong>modules inside one engine</strong>&#8212;not a pile of disconnected notebooks.</p><h3><strong>System Overview</strong></h3><p>Runtime shape stays deliberately small:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BSP9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c206601-bca1-4f4c-98d3-a8cda31662a9_629x424.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BSP9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c206601-bca1-4f4c-98d3-a8cda31662a9_629x424.png 424w, https://substackcdn.com/image/fetch/$s_!BSP9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c206601-bca1-4f4c-98d3-a8cda31662a9_629x424.png 848w, https://substackcdn.com/image/fetch/$s_!BSP9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c206601-bca1-4f4c-98d3-a8cda31662a9_629x424.png 1272w, https://substackcdn.com/image/fetch/$s_!BSP9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c206601-bca1-4f4c-98d3-a8cda31662a9_629x424.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BSP9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c206601-bca1-4f4c-98d3-a8cda31662a9_629x424.png" width="629" height="424" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7c206601-bca1-4f4c-98d3-a8cda31662a9_629x424.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:424,&quot;width&quot;:629,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:54501,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/199837095?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c206601-bca1-4f4c-98d3-a8cda31662a9_629x424.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!BSP9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c206601-bca1-4f4c-98d3-a8cda31662a9_629x424.png 424w, https://substackcdn.com/image/fetch/$s_!BSP9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c206601-bca1-4f4c-98d3-a8cda31662a9_629x424.png 848w, https://substackcdn.com/image/fetch/$s_!BSP9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c206601-bca1-4f4c-98d3-a8cda31662a9_629x424.png 1272w, https://substackcdn.com/image/fetch/$s_!BSP9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c206601-bca1-4f4c-98d3-a8cda31662a9_629x424.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Original lesson folders (<code>day99/</code> &#8230; <code>day106_to_day112/</code>) in the parent repo stay read-only. Logic is <strong>re-homed</strong> into <code>packages/week1516_python/</code> with explicit one-way imports: <code>learning/</code> never depends on <code>core/</code> or <code>product/</code>.</p><p>Days 99&#8211;112 operationalize inside the system as follows&#8212;without re-teaching the algorithms:</p><ul><li><p><strong>Days 99&#8211;102</strong> feed the RL product path: intro Q-learning, agent/environment comparison, tabular Q-table export, and the Day 102 canonical grid-world agent persisted as JSON policy artifacts.</p></li><li><p><strong>Days 103&#8211;105</strong> power the recommender theory and content-filter learning routes; collaborative user/item similarity and TF-IDF catalog demos run over synthetic or sample data.</p></li><li><p><strong>Days 106&#8211;112</strong> collapse into the MovieLens product pipeline: temporal train/test split, dual artifact persistence (collab + content), and adaptive alpha blending at serve time.</p></li></ul><p>Two routers share the same FastAPI process but serve different audiences. <code>/api/v1/week1516/learn/*</code> returns educational payloads&#8212;Q-table snapshots, CF similarity matrices, abbreviated pipeline demos. <code>/api/v1/ml/*</code> returns operator-grade artifacts: policy reward curves, RMSE/MAE scores, ranked movie lists. Both call into the same <code>week1516_python</code> package; only the adapter layer differs.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cWb2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d024e68-e005-4993-ac43-20fe15f9f90f_3600x2320.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cWb2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d024e68-e005-4993-ac43-20fe15f9f90f_3600x2320.png 424w, https://substackcdn.com/image/fetch/$s_!cWb2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d024e68-e005-4993-ac43-20fe15f9f90f_3600x2320.png 848w, https://substackcdn.com/image/fetch/$s_!cWb2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d024e68-e005-4993-ac43-20fe15f9f90f_3600x2320.png 1272w, https://substackcdn.com/image/fetch/$s_!cWb2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d024e68-e005-4993-ac43-20fe15f9f90f_3600x2320.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cWb2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d024e68-e005-4993-ac43-20fe15f9f90f_3600x2320.png" width="1456" height="938" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0d024e68-e005-4993-ac43-20fe15f9f90f_3600x2320.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:938,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:497431,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/199837095?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d024e68-e005-4993-ac43-20fe15f9f90f_3600x2320.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cWb2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d024e68-e005-4993-ac43-20fe15f9f90f_3600x2320.png 424w, https://substackcdn.com/image/fetch/$s_!cWb2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d024e68-e005-4993-ac43-20fe15f9f90f_3600x2320.png 848w, https://substackcdn.com/image/fetch/$s_!cWb2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d024e68-e005-4993-ac43-20fe15f9f90f_3600x2320.png 1272w, https://substackcdn.com/image/fetch/$s_!cWb2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d024e68-e005-4993-ac43-20fe15f9f90f_3600x2320.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Engine and Core System Design</strong></h3>
      <p>
          <a href="https://aieworks.substack.com/p/week-1516-reinforcement-learning">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 147 - Day 154: Image Classification with TensorFlow]]></title><description><![CDATA[Project Kickoff &#183; Data Pipeline &#183; Baseline Model]]></description><link>https://aieworks.substack.com/p/day-147-day-154-image-classification</link><guid isPermaLink="false">https://aieworks.substack.com/p/day-147-day-154-image-classification</guid><dc:creator><![CDATA[sysdai]]></dc:creator><pubDate>Mon, 29 Jun 2026 08:31:11 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!xxMZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9da77e9f-29e4-473d-9db2-fb661eca8d59_4100x2400.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Today&#8217;s Agenda</h2><ul><li><p>Architect the full image classification system we&#8217;ll build across Days 147&#8211;154</p></li><li><p>Build a production-grade data pipeline: loading, normalizing, and augmenting CIFAR-10</p></li><li><p>Define the model skeleton, compile it, and run a single training epoch to verify the pipeline end-to-end</p></li><li><p>Understand where this project fits inside real-world CV systems at companies like Google, Tesla, and Pinterest</p></li></ul><div><hr></div><h2>Why This Project Matters</h2><blockquote><p>You spent Day 146 building a neural network in PyTorch by hand &#8212; manually writing the forward pass, the loss calculation, and the optimization step. That exercise taught you what happens under the hood. Now we flip to TensorFlow/Keras, the framework that powers production systems at Google, Waymo, Airbnb, and Twitter, and we use it to build something real: an image classifier trained on CIFAR-10, a 60,000-image benchmark dataset covering 10 object categories.</p><p>This is not a toy exercise. The architecture patterns you apply here &#8212; data pipeline separation, augmentation strategies, checkpointing, and evaluation loops &#8212; are the same ones used in production vision systems handling millions of inference calls per day.</p></blockquote><div><hr></div><h2>The 7-Day Project Arc</h2><p>Before writing a single line of code, understand what the week looks like:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!p_ce!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab575d12-274b-485d-8889-b8079c57cc4d_922x487.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!p_ce!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab575d12-274b-485d-8889-b8079c57cc4d_922x487.png 424w, https://substackcdn.com/image/fetch/$s_!p_ce!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab575d12-274b-485d-8889-b8079c57cc4d_922x487.png 848w, https://substackcdn.com/image/fetch/$s_!p_ce!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab575d12-274b-485d-8889-b8079c57cc4d_922x487.png 1272w, https://substackcdn.com/image/fetch/$s_!p_ce!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab575d12-274b-485d-8889-b8079c57cc4d_922x487.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!p_ce!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab575d12-274b-485d-8889-b8079c57cc4d_922x487.png" width="922" height="487" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ab575d12-274b-485d-8889-b8079c57cc4d_922x487.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:487,&quot;width&quot;:922,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:72794,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/190912806?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab575d12-274b-485d-8889-b8079c57cc4d_922x487.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!p_ce!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab575d12-274b-485d-8889-b8079c57cc4d_922x487.png 424w, https://substackcdn.com/image/fetch/$s_!p_ce!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab575d12-274b-485d-8889-b8079c57cc4d_922x487.png 848w, https://substackcdn.com/image/fetch/$s_!p_ce!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab575d12-274b-485d-8889-b8079c57cc4d_922x487.png 1272w, https://substackcdn.com/image/fetch/$s_!p_ce!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab575d12-274b-485d-8889-b8079c57cc4d_922x487.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><blockquote><p><strong>Instructor Note:</strong> Today is the foundation. Get this wrong and every subsequent day compounds the error. Get it right and the rest of the week flows cleanly.</p></blockquote><div><hr></div><h2>Core Concepts</h2><h3>1. The Data Pipeline Is Not an Afterthought</h3><p>In production ML, teams consistently report that 60&#8211;80% of engineering effort lives in data, not models. The model itself is often 50 lines. The pipeline that feeds it reliably &#8212; handling corrupted files, class imbalance, augmentation, batching, and prefetching &#8212; is where the real work happens.</p><p>TensorFlow&#8217;s <code>tf.data</code> API is the production-standard answer to this. It is a lazy, composable pipeline that runs data loading and preprocessing on the CPU while the GPU trains the model in parallel. Netflix uses <code>tf.data</code> patterns for their recommendation system feature pipelines. Google Vision uses it to feed TPU clusters processing petabytes of images.</p><blockquote><p><strong>The Mental Model:</strong> Think of <code>tf.data</code> as a factory conveyor belt. Raw images come in one end. Normalized, augmented, batched tensors come out the other. The belt runs independently of the machine doing the work.</p></blockquote><pre><code><code># Conceptual pipeline structure
dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
dataset = dataset.shuffle(buffer_size=10000)
dataset = dataset.map(augment_fn, num_parallel_calls=tf.data.AUTOTUNE)
dataset = dataset.batch(64)
dataset = dataset.prefetch(tf.data.AUTOTUNE)
</code></code></pre><p><code>AUTOTUNE</code> is TensorFlow telling the runtime: measure the actual hardware, then decide the optimal parallelism automatically. You never hard-code thread counts in production.</p><p> </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xxMZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9da77e9f-29e4-473d-9db2-fb661eca8d59_4100x2400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xxMZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9da77e9f-29e4-473d-9db2-fb661eca8d59_4100x2400.png 424w, https://substackcdn.com/image/fetch/$s_!xxMZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9da77e9f-29e4-473d-9db2-fb661eca8d59_4100x2400.png 848w, https://substackcdn.com/image/fetch/$s_!xxMZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9da77e9f-29e4-473d-9db2-fb661eca8d59_4100x2400.png 1272w, https://substackcdn.com/image/fetch/$s_!xxMZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9da77e9f-29e4-473d-9db2-fb661eca8d59_4100x2400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xxMZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9da77e9f-29e4-473d-9db2-fb661eca8d59_4100x2400.png" width="1456" height="852" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9da77e9f-29e4-473d-9db2-fb661eca8d59_4100x2400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:852,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xxMZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9da77e9f-29e4-473d-9db2-fb661eca8d59_4100x2400.png 424w, https://substackcdn.com/image/fetch/$s_!xxMZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9da77e9f-29e4-473d-9db2-fb661eca8d59_4100x2400.png 848w, https://substackcdn.com/image/fetch/$s_!xxMZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9da77e9f-29e4-473d-9db2-fb661eca8d59_4100x2400.png 1272w, https://substackcdn.com/image/fetch/$s_!xxMZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9da77e9f-29e4-473d-9db2-fb661eca8d59_4100x2400.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://aieworks.substack.com/p/day-147-day-154-image-classification">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 146: Building a Simple Neural Network in PyTorch]]></title><description><![CDATA[Agenda]]></description><link>https://aieworks.substack.com/p/day-146-building-a-simple-neural</link><guid isPermaLink="false">https://aieworks.substack.com/p/day-146-building-a-simple-neural</guid><dc:creator><![CDATA[sysdai]]></dc:creator><pubDate>Thu, 25 Jun 2026 08:30:29 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!f8__!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd24f1ad4-71d9-49bb-be58-05ae81a0e7e6_4100x2400.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Agenda</h2><ul><li><p>Translate the computational graph from Day 145 into a full <code>nn.Module</code> &#8212; the standard building block of every PyTorch model in production</p></li><li><p>Wire together layers, activation functions, a loss function, and an optimizer into a working training loop</p></li><li><p>Train a two-layer network on real tabular data and read the metrics that engineers use to confirm a model is actually learning</p></li></ul><div><hr></div><h2>Why This Matters</h2><blockquote><p>Yesterday you held a raw tensor and watched autograd track every gradient through the graph. That was the engine exposed. Today you bolt the body panels on: <code>torch.nn</code> gives you a composable API that every serious PyTorch codebase &#8212; from Meta&#8217;s recommendation systems to Waymo&#8217;s perception stack &#8212; is built on top of. Understanding <code>nn.Module</code> at this level is not academic; it is the exact mental model you need to read open-source model code, debug training failures, and eventually swap in your own custom layers without breaking anything downstream.</p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!f8__!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd24f1ad4-71d9-49bb-be58-05ae81a0e7e6_4100x2400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!f8__!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd24f1ad4-71d9-49bb-be58-05ae81a0e7e6_4100x2400.png 424w, https://substackcdn.com/image/fetch/$s_!f8__!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd24f1ad4-71d9-49bb-be58-05ae81a0e7e6_4100x2400.png 848w, https://substackcdn.com/image/fetch/$s_!f8__!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd24f1ad4-71d9-49bb-be58-05ae81a0e7e6_4100x2400.png 1272w, https://substackcdn.com/image/fetch/$s_!f8__!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd24f1ad4-71d9-49bb-be58-05ae81a0e7e6_4100x2400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!f8__!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd24f1ad4-71d9-49bb-be58-05ae81a0e7e6_4100x2400.png" width="1456" height="852" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d24f1ad4-71d9-49bb-be58-05ae81a0e7e6_4100x2400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:852,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!f8__!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd24f1ad4-71d9-49bb-be58-05ae81a0e7e6_4100x2400.png 424w, https://substackcdn.com/image/fetch/$s_!f8__!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd24f1ad4-71d9-49bb-be58-05ae81a0e7e6_4100x2400.png 848w, https://substackcdn.com/image/fetch/$s_!f8__!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd24f1ad4-71d9-49bb-be58-05ae81a0e7e6_4100x2400.png 1272w, https://substackcdn.com/image/fetch/$s_!f8__!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd24f1ad4-71d9-49bb-be58-05ae81a0e7e6_4100x2400.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p>
      <p>
          <a href="https://aieworks.substack.com/p/day-146-building-a-simple-neural">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Week 13–14 : Unsupervised Learning (Days 85-98)]]></title><description><![CDATA[Introduction]]></description><link>https://aieworks.substack.com/p/week-1314-unsupervised-learning-days</link><guid isPermaLink="false">https://aieworks.substack.com/p/week-1314-unsupervised-learning-days</guid><dc:creator><![CDATA[sdr]]></dc:creator><pubDate>Wed, 24 Jun 2026 02:16:26 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!X2EK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63e91c20-d5cf-46bb-b9e5-11210f722232_3280x1680.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><blockquote><p>Unsupervised learning tutorials usually ship as disconnected scripts: K-Means in one folder, PCA in another, hierarchical clustering in a third. That is fine for learning algorithms in isolation. It fails when you need a <strong>single service</strong> that trains segmentations, serves predictions, exposes lesson demos over HTTP, and runs in Docker without eight separate virtual environments.</p></blockquote><p><code>This project</code> unifies Days 85&#8211;92 (plus stub health routes for the 93&#8211;98 review window) into one stack:</p><ul><li><p>A <strong>learning layer</strong> that exposes each lesson&#8217;s logic through structured HTTP routes.</p></li><li><p>A <strong>composition layer</strong> that selects canonical implementations when multiple days solve the same problem differently.</p></li><li><p>A <strong>product layer</strong> that runs customer segmentation, taxonomy building, and PCA workflows end-to-end.</p></li><li><p>A <strong>React dashboard</strong> behind nginx for operators and learners.</p></li></ul><p>You will walk away knowing how clustering theory, optimal-K selection, hierarchical taxonomies, and production PCA become <strong>modules inside one engine</strong>&#8212;not eight apps stitched together.</p><h3><strong>System Overview</strong></h3><p>Runtime shape is deliberately small:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Zlza!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2efdf68d-48cf-4092-afd2-5e0d6a76bd02_624x378.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Zlza!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2efdf68d-48cf-4092-afd2-5e0d6a76bd02_624x378.png 424w, https://substackcdn.com/image/fetch/$s_!Zlza!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2efdf68d-48cf-4092-afd2-5e0d6a76bd02_624x378.png 848w, https://substackcdn.com/image/fetch/$s_!Zlza!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2efdf68d-48cf-4092-afd2-5e0d6a76bd02_624x378.png 1272w, https://substackcdn.com/image/fetch/$s_!Zlza!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2efdf68d-48cf-4092-afd2-5e0d6a76bd02_624x378.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Zlza!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2efdf68d-48cf-4092-afd2-5e0d6a76bd02_624x378.png" width="624" height="378" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2efdf68d-48cf-4092-afd2-5e0d6a76bd02_624x378.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:378,&quot;width&quot;:624,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:49976,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://aieworks.substack.com/i/199829250?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2efdf68d-48cf-4092-afd2-5e0d6a76bd02_624x378.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Zlza!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2efdf68d-48cf-4092-afd2-5e0d6a76bd02_624x378.png 424w, https://substackcdn.com/image/fetch/$s_!Zlza!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2efdf68d-48cf-4092-afd2-5e0d6a76bd02_624x378.png 848w, https://substackcdn.com/image/fetch/$s_!Zlza!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2efdf68d-48cf-4092-afd2-5e0d6a76bd02_624x378.png 1272w, https://substackcdn.com/image/fetch/$s_!Zlza!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2efdf68d-48cf-4092-afd2-5e0d6a76bd02_624x378.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://aieworks.substack.com/p/week-1314-unsupervised-learning-days">
              Read more
          </a>
      </p>
   ]]></content:encoded></item></channel></rss>