<?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:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jacob Danner on Medium]]></title>
        <description><![CDATA[Stories by Jacob Danner on Medium]]></description>
        <link>https://medium.com/@jacobdanner?source=rss-5e6316ae78ae------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FDgISbAcjQfjsIE2</url>
            <title>Stories by Jacob Danner on Medium</title>
            <link>https://medium.com/@jacobdanner?source=rss-5e6316ae78ae------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 06:52:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jacobdanner/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Vision = Language: I Decoded VLM Tokens to See What AI ‘Sees’ ]]></title>
            <link>https://medium.com/@jacobdanner/vision-language-i-decoded-vlm-tokens-to-see-what-ai-sees-2802bf5a203d?source=rss-5e6316ae78ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/2802bf5a203d</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[vision-language-model]]></category>
            <category><![CDATA[large-language-models]]></category>
            <dc:creator><![CDATA[Jacob Danner]]></dc:creator>
            <pubDate>Mon, 24 Nov 2025 20:27:31 GMT</pubDate>
            <atom:updated>2025-11-24T20:27:31.109Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve spent a lot of time learning how language models work, but images obviously aren’t language — so how is it possible for AI to understand an image? I studied Gemma 3 to learn about how modern vision language models work.</p><p><strong>The core finding:</strong> Vision language models are just language models that learned to “speak image”. Images get encoded as tokens in linguistic space, and then the language model processes them identically to text.</p><p>So, if visual information gets translated into linguistic space, can we interpret the image tokens by mapping them to vocabulary space? I built an unembedding technique to answer that question and analyze what semantic information is encoded in the image tokens.</p><h3>Background: How VLMs Work</h3><p>Here’s a diagram I created for my video that I think is helpful:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*39cxNdqSotG7Axkn" /></figure><p>As you can see, there are two pieces: the vision tower + a standard language model. The vision tower is quite literally bolted on to a normal language model.</p><p>For Gemma 3 specifically, the data flow is:</p><ol><li>Preprocessing: Convert image → 3 × 896 × 896 pixels</li><li>Vision transformer: Process pixels → 4,096 image tokens</li><li>Multimodal projector: Compress 4,096 tokens → 256 tokens (semantically meaningful in language model’s d_model space)</li><li>Language model: Image tokens and text tokens processed identically</li></ol><p>The brilliance is the multimodal projector — it translates visual information into linguistic space.</p><h3>Method: Unembedding Image Tokens</h3><p><strong>Validation:</strong> First, I validated the technique with text tokens. By taking a token embedding and passing it directly through the language head (bypassing the transformer layers), I could recover the original token with 100% accuracy. This proves that unembedding works for linguistic tokens.</p><p><strong>Applying to images:</strong> The same technique can be applied to image tokens:</p><pre>Image → Vision Tower → Multimodal Projector → 256 image tokens → Unembed each token</pre><p>This is greedy unembedding — finding the nearest vocabulary token to any embedding vector. Since this is a nearest neighbor approach, it’s lossy. The reality is that image tokens live in linguistic space but don’t necessarily map exactly to a single vocabulary token. An image token can exist between different vocabulary words in the embedding space.</p><pre>| Token Type   | Embedding Space Behavior                                                               |<br>|--------------|----------------------------------------------------------------------------------------|<br>| Text tokens  | Map 1:1 to embedding space – each vocabulary token has exactly 1 vector representation |<br>| Image tokens | Have vector representations that exist **between** text tokens                         |</pre><h3>What I Found</h3><p>Here’s what the unembedding revealed for different image types (see the linked notebook for more):</p><p><strong>Purple square (monocolor):</strong> The model correctly identifies the dominant color</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/0*GIxaUSpf-kdzg7tA" /></figure><p><strong>Mountain scene (sunrise over mountains):</strong> Rich semantic encoding: proper nouns, landscape features, time of day</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/0*G0x_T-rBNilcSHeS" /></figure><p><strong>Key observations</strong></p><ul><li><em>The “ the” phenomenon:</em> Across all image types, a large percentage of tokens map to “ the”. Since “ the” is usually the most common token in training data, it likely occupies a central location in embedding space. This might reveal either that not all image tokens are informative, or it might expose a limitation of greedy unembedding: when image tokens don’t map cleanly to a single vocabulary word, the nearest neighbor defaults to the most “central” token — there may be information encoded that greedy nearest-neighbor decoding can’t reveal.</li><li><em>Semantic emergence:</em> Even with the “ the” dominance, semantically meaningful tokens do emerge — colors, landscape features, proper nouns. The language model’s understanding of images is messy, but there’s signal in the noise.</li></ul><h3>Implications &amp; Open Questions</h3><p><strong>Implication: The 256-Token Bottleneck: Feature, Not Flaw?</strong></p><p>The multimodal projector compresses 4,096 visual patches down to 256 tokens. At first, this seemed like a clear limitation — you’re losing information in that compression. There is only so much that can be encoded in 256 tokens, right?</p><p>There has been some buzz recently about the DeepSeek-OCR paper and how image tokens can be used as a form of compression. This got me thinking about the 256-token budget differently.</p><p>Remember that image tokens exist <em>between</em> text tokens in embedding space. A text token maps 1:1 to exactly one vocabulary word. But an image token isn’t constrained to discrete vocabulary positions — it can exist anywhere in the continuous embedding space between multiple words. This means a single image token can simultaneously encode aspects of multiple concepts.</p><p>In other words, <em>image tokens have higher information density than text tokens.</em> Each of the 256 image tokens can encode more nuanced information than a discrete text token could.</p><p>This reframes the 256-token “bottleneck” — maybe it’s not a limitation but an efficient compression that can be exploited.</p><p><strong>Open Question: Positional Encoding: Distributed or Discrete?</strong></p><p>Someone asked me recently how positional information in an image gets encoded in the vision tokens. I don’t have a good answer, but I think it’s a really interesting question. Positional information is obviously encoded somewhere, but where? Is it very distributed across the 256? Or are there specific token positions that effectively act as positional experts? How is information encoded across the 256 token budget?</p><ul><li><em>1 giant pool</em> (each token plays a small role in constructing what appears as an aggregate meaning when looking at all 256)</li></ul><p>OR</p><ul><li><em>256 smaller pools</em> (each token is more of a specialist, i.e., the 0th position vision token serves a different function than the 255th)</li></ul><p>My gut tells me the 1 giant pool idea seems more likely to me. But, as I’ve learned with VLMs, the reality is probably somewhere in the middle, and quite messy and hard to study! But I bet there is some cool stuff to discover with more sophisticated techniques.</p><h3>Want to Explore More?</h3><ul><li><a href="https://youtu.be/NpWP-hOq6II?si=Qun_EsWq7LLQ4ugw"><strong>“Dissecting Vision Language Models: How AI Sees”</strong></a> — My 20-min video walkthrough going deeper into VLM architecture and the unembedding technique</li><li><a href="https://github.com/jacob-danner/dissecting-vlm/blob/main/dissecting_vlm.ipynb"><strong>GitHub repo with notebook</strong></a> — Clone the repo and try unembedding your own images to see what the model “sees” in linguistic space</li><li><a href="https://www.youtube.com/watch?v=mLgyZ5GauhM&amp;t=6s"><strong>Teaching AI to See: A Technical Deep-Dive on Vision Language Models with Will Hardman of Veratai</strong></a> — <em>Cognitive Revolution</em> podcast episode that’s an excellent comprehensive map of the VLM landscape</li></ul><p>I think vision language models are super fascinating, especially on the mechanistic interpretability side trying to understand what those image tokens actually represent. Let me know what you discover!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2802bf5a203d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Retrieval Augmented Classification — LLMs as Classifiers]]></title>
            <link>https://thequantasticjournal.com/retrieval-augmented-classification-llms-as-classifiers-c28d40391738?source=rss-5e6316ae78ae------2</link>
            <guid isPermaLink="false">https://medium.com/p/c28d40391738</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[retrieval-augmented]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Jacob Danner]]></dc:creator>
            <pubDate>Sat, 28 Sep 2024 21:11:11 GMT</pubDate>
            <atom:updated>2024-11-01T05:32:00.067Z</atom:updated>
            <content:encoded><![CDATA[<h3>Retrieval Augmented Classification — LLMs as Classifiers</h3><h4>To address performance issues outside the LLM’s training distribution, we can improve classification by augmenting the prompt with retrieval.</h4><figure><img alt="Retrieval Augmented Classification — LLMs as Classifiers" src="https://cdn-images-1.medium.com/max/1024/1*730pcy4xOjHEKQQVlKxrFw.png" /></figure><p>Classification problems are everywhere. From identifying spam messages to recommending us the next YouTube video, we constantly rely on systems that classify data to make our lives easier, often without even realizing it.</p><p>Traditional machine learning excels at this type of thing. Train a model with enough example data and it will learn to classify effectively.</p><p>However, in my own experience, there’s a set of real-world problems, where having a classification model would be ideal, but training one just isn’t practical. Whether you lack enough data or the complexity isn’t worth the effort, training a custom model doesn’t always make sense.</p><p>That’s where <em>Large Language Models</em> (LLMs) like GPT, Claude, etc. come in. These powerful, general-purpose models can be adapted to a wide range of tasks using prompts, without the need for retraining. LLMs are ideal for situations where building a traditional classification model isn’t practical for the following reasons:</p><ul><li><strong>General Knowledge</strong>: LLMs are trained on vast, diverse data, allowing them to classify text across various domains without domain-specific training. This makes them perfect for use cases where you lack sufficient labeled data or need broad contextual understanding.</li><li><strong>Flexibility</strong>: Unlike rigid traditional models, LLMs don’t require retraining when new categories or criteria emerge. You can simply modify the prompt to handle changes, making them ideal for dynamic environments where the classification needs to evolve over time.</li></ul><h3>LLM as a classifier</h3><p>How do you get the LLM to classify your data?—With a prompt. The prompt should roughly resemble something like this:</p><pre># Instruction<br><br>Hey LLM, you are a classifier.<br>Choose the most appropriate class and output only your classification.<br><br>There are these classes:<br>{classes}<br><br># Solve<br><br>This is the input to be classified:<br>{input}</pre><p>Given a prompt like this, the LLM will operate as a classification model. This is called <em>zero-shot prompting</em>. Results here will vary depending on your use case, which generally falls into two categories:</p><p><strong>In training distribution (category 1):</strong></p><ul><li><em>LLM can perform your task well out of the box</em>: Both the classes and the input are common enough in the LLM’s training dataset that the concepts are generally understood</li><li><em>Example</em>: Classifying customer reviews into categories like “Positive”, “Neutral”, “Negative”. The boundaries between these categories are well reflected in the training data.</li></ul><p><strong>Out of training distribution (category 2):</strong></p><ul><li><em>LLM cannot perform your task well out of the box: </em>Either the classes or the input are too unique or proprietary, meaning the concepts wouldn’t be reflected in the LLM’s training data.</li><li><em>Example</em>: Classifying expenses into personalized categories like “Needs”, “Wants”, “Travel”. Such distinctions are personal and wouldn’t be reflected in the LLM’s training data.</li></ul><p>If your use case is category 1, then you will likely see excellent performance from the most advanced LLMs with zero-shot prompting.</p><p>If your use case is category 2, then the bad news it that even the most advanced LLMs will struggle to accurately classify your input with zero-shot prompting. The good news is, we can improve the results.</p><h3>Better classification through retrieval</h3><p>To address performance issues, especially when tasks fall outside the LLM’s training distribution, we can improve classification by augmenting the prompt with retrieval. This approach is called <em>Retrieval Augmented Classification</em> (<a href="https://arxiv.org/abs/2202.11233">RAC</a>), a method that integrates retrieval with classification to improve the LLM’s decision-making.</p><p>Incorporating retrieval into your classification pipeline transforms the LLM from a simple zero-shot classifier to a more contextually informed one. This works by retrieving relevant information from a pre-indexed dataset and feeding it into the prompt. This additional data can narrow the scope of the problem, making it easier for the LLM to correctly classify the input.</p><h4>How RAC improves classification</h4><p><strong>Enhancing context with similar examples</strong>:</p><p>By retrieving similar examples from your dataset, you provide the LLM with more context about the specific input. This contextual information is crucial, especially when the classification involves nuanced or domain-specific distinctions.</p><p>For example, if you’re classifying transactions into categories like “Needs”, “Wants”, and “Travel” retrieving previous transactions that have been labeled similarly can guide the LLM toward the right classification by showing it how similar data points were categorized in the past.</p><p><strong>Altering the prompt with retrieved data</strong>:</p><p>In a retrieval-augmented setup, the prompt includes the relevant retrieved examples, which help the LLM better understand the decision boundaries between classes. A retrieval-enhanced prompt might look like this:</p><pre># Instruction<br><br>Hey LLM, you are a classifier.<br>Consider the previously labeled examples when making your classification.<br>Choose the most appropriate class and output only your classification.<br><br>There are these classes:<br>{classes}<br><br>Here are some examples of previously labeled data:<br>{retrieved_examples}<br><br># Solve<br><br>This is the input to be classified:<br>{input}</pre><p>The core idea being that classification becomes easier and more accurate when the LLM has similar examples to guide its decisions.</p><h4>How to implement retrieval</h4><p>To implement RAC, you’ll need to set up a retrieval system. Retrieval can be implemented in different ways, depending on what’s best suited for your use case. Some options include:</p><ul><li><strong>Vector search with embeddings</strong>: This involves converting your data into embeddings and using a vector database to find the most similar examples based on their semantic meaning. This is especially powerful for unstructured data like text because it captures semantic meaning.</li><li><strong>Keyword search</strong>: If your data lacks semantic meaning and doesn’t need the power of embeddings, a simple keyword search can do the job.</li><li><strong>Hybrid search</strong>: You can combine the benefits of vector and keyword search by using a hybrid approach.</li></ul><p>While there are options, vector search is probably the easiest way to integrate retrieval into your pipeline, especially with fully managed services like Pinecone that handle the infrastructure for you. With Pinecone, this process is as simple as making a few API calls.</p><p>Regardless of retrieval strategy, the retrieval system must be capable of doing 2 things:</p><ol><li><strong>Index your data</strong></li><li><strong>Retrieve similar data</strong></li></ol><p>To tie it all together, a full RAC pipeline looks like:</p><ol><li><strong>Data indexing</strong>: You index your labeled examples.</li><li><strong>Input</strong>: You send the input data to the retrieval system.</li><li><strong>Retrieval</strong>: The system fetches relevant examples from your pre-indexed data.</li><li><strong>Augmentation</strong>: These examples are passed to the LLM in the prompt.</li><li><strong>Classification</strong>: The LLM uses both the input and the retrieved examples to classify the data more accurately.</li></ol><p>It’s as simple as that. Once retrieval is in place, your LLM is no longer flying blind — it is now informed with relevant context, which means better results.</p><h3>A case study: personal transaction classification</h3><h4>Transaction data overview</h4><p>I worked with a set of my own personal transaction data, categorized into labels like:</p><pre>- Assets:Discover:Main:Needs:Monthly<br>- Assets:Discover:Main:Needs:Groceries<br>- Assets:Discover:Main:Needs:Gas<br>- Assets:Discover:Main:Needs:Other<br>- Assets:Discover:Main:Wants:Monthly<br>- Assets:Discover:Main:Wants:Other<br>- Assets:Discover:Furniture<br>- Assets:Discover:FutureWants<br>- Assets:Discover:Travel</pre><p>This task falls into the out of training distribution category. These classes are my own personal budget categories, meaning that this data likely differs from anything the LLM has seen in training.</p><p>Each transaction represents a real-world expense that I wanted to automatically classify into these categories for budgeting purposes. Labeled examples are JSON objects consisting of 4 fields, example:</p><pre>{<br>    &quot;vendor&quot;: &quot;AMAZON PRIME&quot;,<br>    &quot;day&quot;: &quot;04&quot;,<br>    &quot;amount&quot;: &quot;16.04&quot;,<br>    &quot;from_account&quot;: &quot;Assets:Discover:Main:Needs:Monthly&quot;<br>}</pre><p>Unlabeled examples (AKA test data) lack a from_account, example:</p><pre>{<br>    &quot;vendor&quot;: &quot;SPOTIFY&quot;,<br>    &quot;day&quot;: &quot;09&quot;,<br>    &quot;amount&quot;: &quot;11.76&quot;,<br>}</pre><p>I had 130 labeled transactions and 57 unlabeled transactions.</p><p>To evaluate how well different approaches worked for this classification task, I ran several experiments using zero-shot prompting, vector retrieval K-Nearest Neighbors, and RAC to evaluate the classification accuracy of from_account on the 57 unlabeled transactions.</p><p>For my retrieval system, I uploaded the 130 labeled transactions to Pinecone’s serverless vector database using OpenAI embeddings and cosine similarity as the measure of embedding distance.</p><h4>Evaluation: z<strong><em>ero-shot</em></strong></h4><p>I began by testing the zero-shot capabilities of two models: GPT 4o-mini and GPT 4o.</p><ul><li><strong>GPT 4o-mini</strong>: Achieved an accuracy of <strong>38%</strong>. This was expectedly low, as GPT 4o-mini struggled to map my personalized categories without any additional context or learning from examples.</li><li><strong>GPT 4o</strong>: Performed better, achieving an accuracy of <strong>63%</strong>. This improvement can be attributed to GPT 4o’s more advanced understanding of language and broader knowledge base.</li></ul><p>These results highlight the limitations of zero-shot prompting for domain-specific classification tasks. While GPT 4o could handle generic categories fairly well, personalized categories significantly hindered its performance.</p><h4>Evaluation: KNN with vector retrieval</h4><p>In this experiment, I used the retrieval system to find the K most similar transactions from the vector database and classified the unlabeled transaction based on the mode from_account. In other words, what is the most common from_account in the set of retrieved similar transactions? This method relied solely on the retrieval system and didn&#39;t utilize any LLM calls.</p><ul><li><strong>KNN</strong>: This method increased the accuracy to <strong>64%</strong>. While the improvement was not drastic compared to GPT 4o’s zero-shot performance, it demonstrated that simply retrieving similar transactions without any classification model could yield better results than an LLM working without context.</li></ul><p>This approach works well for more frequently occurring categories where similar historical transactions provide strong classification guidance. However, for more personalized categories or those with less data, this approach struggled, as the nearest neighbors were often insufficiently distinct to capture the correct classification.</p><h4>Evaluation: RAC</h4><p>Next, I implemented RAC, combining vector retrieval with LLM classification. In this setup, I used vector embeddings to retrieve similar historical transactions and then fed this retrieved context into the LLM to assist in making a more informed classification decision.</p><ul><li><strong>GPT 4o-mini with RAC</strong>: Accuracy jumped to <strong>85%</strong>. This significant improvement shows how powerful contextual retrieval can be. By providing the model with relevant examples before asking it to classify the transaction, the LLM was able to handle the nuanced distinctions between categories like “Needs” vs “Wants” much better than in the zero-shot scenario.</li><li><strong>GPT 4o with RAC</strong>: Interestingly, the accuracy here reached <strong>76%</strong>, lower than GPT 4o-mini’s performance in this setup. While GPT 4o benefited from retrieval, it didn’t show the same leap in performance as GPT 4o-mini. This was unexpected. This could be due to GPT 4o’s tendency to rely more on its inherent knowledge base, which, in this case, led to overconfidence in certain predictions.</li></ul><p>RAC demonstrated its strength, especially in cases where zero-shot LLMs struggled to classify accurately. The additional context provided by vector retrieval helped disambiguate transactions that were harder to categorize based purely on the transaction description.</p><p>RAC demonstrates a practical solution for low-data and highly personalized classification tasks, offering a flexible and effective alternative to traditional custom model training.</p><p>Moving forward, there’s potential for further optimization with improving data quality, retrieval techniques, and prompting to further improve classification accuracy.</p><h4>Things to know</h4><p><strong>Cost Efficiency:</strong></p><p>One of the major advantages of RAC is its affordability. With LLM API calls costing fractions of a cent and services like Pinecone offering generous free tiers, the cost of running RAC is minimal. You don’t need to invest time or money in training a custom model or managing complex infrastructure, making RAC accessible for personal projects or small-scale deployments.</p><p><strong>Accuracy vs. Human Oversight:</strong></p><p>In this case study, I achieved <strong>85% accuracy</strong> using GPT 4o-mini with RAC, which is certainly useful but not perfect. In practice, this means that while RAC can automate a large portion of the classification work, some human oversight may still be required, particularly for edge cases or critical decisions.</p><p>To handle this, I recommend incorporating a mechanism that allows the model to “opt out” when it’s uncertain about a classification. One practical solution is to introduce an additional class: UNKNOWN.</p><p>By prompting the LLM to return an UNKNOWN label when it&#39;s not confident in its classification, you create a more robust system. This allows you to focus human effort only on the transactions that the model is unsure about, while automating the bulk of the process.</p><h3>Conclusion</h3><p>As discussed, LLMs are a viable solution for situations where training your own classification model isn’t practical. RAC enhances LLMs’ classification power in situations where zero-shot LLMs fall short. By combining the broad knowledge and language understanding of LLMs with the specificity of retrieved examples, RAC bridges the gap between general-purpose models and domain-specific tasks.</p><p>In this case study, RAC significantly improved classification accuracy, particularly for personalized categories that zero-shot LLMs struggled with. The additional context provided by retrieval allows the LLM to make more informed decisions, effectively solving the issue out of training distribution data.</p><p>The ease of implementing RAC with tools like Pinecone and the affordability of LLM API calls make it accessible even for smaller projects. While no system is perfect, RAC offers a pragmatic balance between automation and accuracy.</p><p>I wrote this to share my experiment and to spark inspiration for others to explore the potential of RAC in their own projects. The possibilities with RAC are vast, and I’d love to hear about your use cases!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c28d40391738" width="1" height="1" alt=""><hr><p><a href="https://thequantasticjournal.com/retrieval-augmented-classification-llms-as-classifiers-c28d40391738">Retrieval Augmented Classification — LLMs as Classifiers</a> was originally published in <a href="https://thequantasticjournal.com/">The Quantastic Journal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>