<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged transformers</title>
<link>https://coderlegion.com/tag/transformers</link>
<description>Powered by Question2Answer</description>
<item>
<title>Transformers.js: Running AI Models Directly in the Browser</title>
<link>https://coderlegion.com/30784/transformers-js-running-ai-models-directly-in-the-browser</link>
<description>&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://huggingface.co/docs/transformers.js/index&quot;&gt;Transformers.js&lt;/a&gt; is an open-source JavaScript library developed by Hugging Face that allows you to run pretrained machine learning models directly in web browsers and JavaScript runtimes such as Node.js, Deno, and Bun.&lt;/p&gt;
&lt;p&gt;It supports a variety of tasks, including text classification, sentiment analysis, image classification, audio processing, and feature extraction. It also allows developers to use many pretrained models from the Hugging Face Hub without having to build an inference backend from scratch.&lt;/p&gt;
&lt;p&gt;One of the most interesting features of Transformers.js is that models can run locally in the browser, depending on the model and available hardware. This can reduce reliance on external inference APIs and allow certain inputs to be processed on the user's device.&lt;/p&gt;
&lt;h3 id=&quot;how-does-transformers-js-work-&quot;&gt;How Does Transformers.js Work?&lt;/h3&gt;
&lt;p&gt;Transformers.js provides a &lt;code&gt;pipeline()&lt;/code&gt; API that simplifies loading a model and running inference for a particular task.&lt;/p&gt;
&lt;p&gt;For example, a text-classification pipeline can analyze a sentence and return a prediction:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;import { pipeline } from '@huggingface/transformers';

const classifier = await pipeline(
  'sentiment-analysis',
  'Xenova/distilbert-base-uncased-finetuned-sst-2-english'
);

const result = await classifier(
  'Transformers.js makes AI more accessible to JavaScript developers.'
);

console.log(result);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;pipeline()&lt;/code&gt; function loads the selected model and prepares it for the specified task. You can then pass input to the pipeline and receive the model's predictions.&lt;/p&gt;
&lt;p&gt;The first execution may take some time because the model files need to be downloaded. Performance depends on the model size, runtime, and available hardware.&lt;/p&gt;
&lt;h3 id=&quot;what-can-you-build-with-it-&quot;&gt;What Can You Build With It?&lt;/h3&gt;
&lt;p&gt;Transformers.js supports a range of machine learning tasks, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Text:&lt;/strong&gt; sentiment analysis, text classification, and feature extraction.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Images:&lt;/strong&gt; image classification and other supported vision tasks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Audio:&lt;/strong&gt; audio classification and speech-related tasks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Embeddings:&lt;/strong&gt; converting text and other supported inputs into numerical representations for downstream applications.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The exact tasks and models available depend on the library version and model compatibility.&lt;/p&gt;
&lt;h3 id=&quot;things-to-consider&quot;&gt;Things to Consider&lt;/h3&gt;
&lt;p&gt;Running models locally has advantages, but it also comes with limitations. Model files can be large, inference may be slow on some devices, and not every model is suitable for browser execution.&lt;/p&gt;
&lt;p&gt;Local inference can reduce the need to send inputs to an external service, but it doesn't automatically make an entire application private or offline. Those properties also depend on how the application handles data and loads its resources.&lt;/p&gt;
&lt;h3 id=&quot;my-experience-with-transformers-js&quot;&gt;My Experience With Transformers.js&lt;/h3&gt;
&lt;p&gt;I explored Transformers.js while building EchoQuest, a small project that uses a pretrained audio-classification model to analyze recorded sounds in the browser.&lt;/p&gt;
&lt;p&gt;This gave me practical experience with model loading, audio preprocessing, and integrating machine learning into a JavaScript application without making an external inference API a core dependency.&lt;/p&gt;
&lt;p&gt;For JavaScript developers interested in machine learning, Transformers.js is a useful library to explore because it makes pretrained models accessible within familiar web development workflows.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resources &amp;amp; Further Reading&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;EchoQuest:&lt;/strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://echoquest-qk1i.onrender.com/&quot;&gt;https://echoquest-qk1i.onrender.com/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Documentation:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://huggingface.co/docs/transformers.js/index&quot;&gt;https://huggingface.co/docs/transformers.js/index&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/huggingface/transformers.js&quot;&gt;https://github.com/huggingface/transformers.js&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Helpful Article:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.worldline.tech/2026/01/13/transformersjs-intro.html&quot;&gt;An Introduction to Transformers.js&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Image credit: Worldline Tech — &lt;a rel=&quot;nofollow&quot; href=&quot;https://blog.worldline.tech/2026/01/13/transformersjs-intro.html&quot;&gt;An Introduction to Transformers.js&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/30784/transformers-js-running-ai-models-directly-in-the-browser</guid>
<pubDate>Mon, 12 Oct 2026 08:17:37 +0000</pubDate>
</item>
<item>
<title>The Real Vietnamese LLM Tokenizer Cost (It's Not 4.5x)</title>
<link>https://coderlegion.com/26244/the-real-vietnamese-llm-tokenizer-cost-its-not-4-5x</link>
<description>&lt;p&gt;The moment real traffic hits your LLM endpoint, every token turns into a line item on your cloud bill — and that line item doesn't stop growing once the prompt itself stops changing, as I found out the hard way &lt;a rel=&quot;nofollow&quot; href=&quot;https://medium.com/@minhle_0210/why-your-coding-agents-bill-grows-faster-than-the-chat-2d9ecb37423d&quot;&gt;chasing down why a coding agent's bill kept climbing faster than the conversation did&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;A prompt that looks concise in text can balloon once the tokenizer processes it, especially for non-English languages — something I first ran into while &lt;a rel=&quot;nofollow&quot; href=&quot;https://ai.plainenglish.io/i-spent-my-weekend-benchmarking-vietnamese-bert-models-so-you-dont-have-to-0d19aa280736&quot;&gt;benchmarking Vietnamese BERT models&lt;/a&gt;. When building a social listening pipeline that processed thousands of Vietnamese comments per hour, my dashboard costs quickly exceeded initial projections.&lt;/p&gt;
&lt;p&gt;Searching online, I found the number everyone repeats: &lt;strong&gt;Vietnamese requires up to 4.54x more tokens than English.&lt;/strong&gt; &lt;/p&gt;
&lt;p&gt;It sounds scary. It makes for great social media talking points. &lt;/p&gt;
&lt;p&gt;It is also measuring tokenizers from 2019 that nobody uses in production today.&lt;/p&gt;
&lt;p&gt;I benchmarked 13 tokenizers on matched English and Vietnamese text. Modern tokenizers hover between 1.05x and 2.14x (with PhoBERT achieving parity at 0.87x). Upgrading tokenizer generations alone can reduce your token bill by over a third without changing your models.&lt;/p&gt;
&lt;h3 id=&quot;where-the-4-54x-token-tax-number-came-from&quot;&gt;Where the &quot;4.54x Token Tax&quot; Number Came From&lt;/h3&gt;
&lt;p&gt;The 4.54x statistic traces back to blog posts evaluating &lt;strong&gt;GPT-2 and RoBERTa-style tokenizers&lt;/strong&gt;. &lt;/p&gt;
&lt;p&gt;These 2019 byte-pair encoders had English-only vocabularies with zero Vietnamese diacritics. As a result, common words like &lt;em&gt;&quot;được&quot;&lt;/em&gt;, &lt;em&gt;&quot;nghĩa&quot;&lt;/em&gt;, and &lt;em&gt;&quot;những&quot;&lt;/em&gt; were split into multiple sub-byte pieces. &lt;/p&gt;
&lt;p&gt;That wasn't a property of the Vietnamese language. It was a limitation of five-year-old English tokenizers.&lt;/p&gt;
&lt;h3 id=&quot;the-real-numbers-across-13-tokenizers&quot;&gt;The Real Numbers Across 13 Tokenizers&lt;/h3&gt;
&lt;p&gt;I ran a matched paragraph of natural English and Vietnamese through 13 tokenizers across three generations:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Tokenizer &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Category &lt;/th&gt;&lt;th align=&quot;right&quot;&gt;Ratio (VI Tokens / EN Tokens)&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;gpt2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Legacy English-only &lt;/td&gt;&lt;td align=&quot;right&quot;&gt;&lt;strong&gt;4.03x&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;roberta-base &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Legacy English-only &lt;/td&gt;&lt;td align=&quot;right&quot;&gt;&lt;strong&gt;3.98x&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;phobert-base* &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Vietnamese-specific &lt;/td&gt;&lt;td align=&quot;right&quot;&gt;&lt;strong&gt;0.87x&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;gpt2-vietnamese &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Vietnamese-specific &lt;/td&gt;&lt;td align=&quot;right&quot;&gt;&lt;strong&gt;1.05x&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;xlm-roberta-base &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Modern Multilingual &lt;/td&gt;&lt;td align=&quot;right&quot;&gt;&lt;strong&gt;1.14x&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;mmBERT-base &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Modern Multilingual &lt;/td&gt;&lt;td align=&quot;right&quot;&gt;&lt;strong&gt;1.24x&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;qwen2.5-7b &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Modern Multilingual &lt;/td&gt;&lt;td align=&quot;right&quot;&gt;&lt;strong&gt;1.26x&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;qwen3-8b &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Modern Multilingual &lt;/td&gt;&lt;td align=&quot;right&quot;&gt;&lt;strong&gt;1.26x&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;o200k_base (GPT-4o / GPT-4.1) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Modern Multilingual &lt;/td&gt;&lt;td align=&quot;right&quot;&gt;&lt;strong&gt;1.34x&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;deepseek-v3.2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Frontier Reasoning &lt;/td&gt;&lt;td align=&quot;right&quot;&gt;&lt;strong&gt;1.88x&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;cl100k_base (GPT-3.5 / GPT-4) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Modern Multilingual &lt;/td&gt;&lt;td align=&quot;right&quot;&gt;&lt;strong&gt;2.14x&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;llama-3-8b &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Modern Multilingual &lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Gated (no token)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;gemma-2-9b-it &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Modern Multilingual &lt;/td&gt;&lt;td align=&quot;right&quot;&gt;Gated (no token)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;em&gt;\&lt;/em&gt; PhoBERT expects word-segmented input; raw text was fed here, making 0.87x a conservative baseline.*&lt;/p&gt;
&lt;h3 id=&quot;the-37-free-efficiency-win&quot;&gt;The ~37% Free Efficiency Win&lt;/h3&gt;
&lt;p&gt;The most actionable finding is the gap between OpenAI generations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;cl100k_base&lt;/code&gt; (GPT-3.5 and GPT-4): &lt;strong&gt;2.14x&lt;/strong&gt; token ratio.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;o200k_base&lt;/code&gt; (GPT-4o and GPT-4.1): &lt;strong&gt;1.34x&lt;/strong&gt; token ratio.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Switching from a GPT-4 endpoint to a GPT-4o endpoint automatically cuts your Vietnamese token inflation by roughly &lt;strong&gt;37%&lt;/strong&gt;. You don't need to rewrite prompts or change architecture; the tokenizer vocabulary expansion simply covers Vietnamese syllables more efficiently.&lt;/p&gt;
&lt;h3 id=&quot;frontier-does-not-mean-token-efficient&quot;&gt;Frontier Does Not Mean Token-Efficient&lt;/h3&gt;
&lt;p&gt;Another surprise: &lt;code&gt;DeepSeek-V3.2&lt;/code&gt;, a frontier reasoning model, tokenizes Vietnamese at &lt;strong&gt;1.88x&lt;/strong&gt;. &lt;/p&gt;
&lt;p&gt;By contrast, &lt;code&gt;mmBERT&lt;/code&gt; (a smaller multilingual encoder) sits at &lt;strong&gt;1.24x&lt;/strong&gt;, and &lt;code&gt;Qwen3&lt;/code&gt; lands at &lt;strong&gt;1.26x&lt;/strong&gt;. Model intelligence and tokenizer efficiency are completely independent dimensions. &lt;/p&gt;
&lt;p&gt;Meanwhile, Vietnamese-specific tokenizers like PhoBERT and gpt2-vietnamese match or beat English token counts. The &quot;Vietnamese tax&quot; is fundamentally a choice of tokenizer, not an inherent cost of the language — the same vocabulary-design lesson I ran into &lt;a rel=&quot;nofollow&quot; href=&quot;https://ai.plainenglish.io/weekend-nlp-fine-tuning-transformers-for-language-detection-with-huggingface-4041ac9ca20e&quot;&gt;fine-tuning transformers for language detection&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;These numbers align closely with an independent production study published by engineers at Techcombank in Hanoi (&lt;a rel=&quot;nofollow&quot; href=&quot;https://ssrn.com/abstract=7336938&quot;&gt;The Tokenization Tax&lt;/a&gt;), which confirmed that vocabulary coverage, rather than model vendor, dictates production token consumption.&lt;/p&gt;
&lt;h3 id=&quot;benchmark-script&quot;&gt;Benchmark Script&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;try:
    if spec[&quot;loader&quot;] == &quot;hf&quot;:
        from transformers import AutoTokenizer, PreTrainedTokenizerFast
        try:
            tok = AutoTokenizer.from_pretrained(spec[&quot;id&quot;])
        except Exception:
            tok = PreTrainedTokenizerFast.from_pretrained(spec[&quot;id&quot;])
        en_ids = tok.encode(EN_TEXT)
        vi_ids = tok.encode(VI_TEXT)
    else:
        import tiktoken
        enc = tiktoken.get_encoding(spec[&quot;id&quot;])
        en_ids = enc.encode(EN_TEXT)
        vi_ids = enc.encode(VI_TEXT)
    entry[&quot;ratio_vi_over_en&quot;] = round(len(vi_ids) / len(en_ids), 3)
except Exception as e:
    entry[&quot;status&quot;] = &quot;skipped&quot;
    entry[&quot;error&quot;] = str(e)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;experiment&quot;&gt;Experiment&lt;/h3&gt;
&lt;p&gt;Here's the actual run, step by step. The complete script is in the appendix at the end of this post.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Write matched English/Vietnamese paragraphs for this benchmark specifically&lt;/strong&gt; — not lifted from an external source, so token counts reflect genuinely parallel content rather than sentences that just happen to differ in length:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;EN_TEXT = (
    &quot;Running a language model in production is nothing like running it in a &quot;
    &quot;notebook. The moment real traffic hits your endpoint, every token you &quot;
    &quot;send and receive turns into a line item on your bill. ...&quot;
)

VI_TEXT = (
    &quot;Chạy một mô hình ngôn ngữ trong môi trường production hoàn toàn khác với &quot;
    &quot;chạy trong notebook. Ngay khi traffic thật đổ vào endpoint, mỗi token &quot;
    &quot;bạn gửi đi và nhận về đều trở thành một dòng trong hóa đơn. ...&quot;
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;2. List every tokenizer to benchmark, tagged by generation and loader.&lt;/strong&gt; Here are 3 of the 13:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;TOKENIZER_SPECS = [
    {&quot;name&quot;: &quot;gpt2&quot;, &quot;family&quot;: &quot;legacy-english-only&quot;, &quot;loader&quot;: &quot;hf&quot;, &quot;id&quot;: &quot;gpt2&quot;},
    {&quot;name&quot;: &quot;phobert-base&quot;, &quot;family&quot;: &quot;vietnamese-specific&quot;, &quot;loader&quot;: &quot;hf&quot;, &quot;id&quot;: &quot;vinai/phobert-base&quot;},
    {&quot;name&quot;: &quot;o200k_base (GPT-4o / GPT-4.1)&quot;, &quot;family&quot;: &quot;modern-multilingual&quot;, &quot;loader&quot;: &quot;tiktoken&quot;, &quot;id&quot;: &quot;o200k_base&quot;},
]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;3. Print each result as it's computed, and record failures honestly instead of estimating them:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;status_word = entry[&quot;status&quot;]
detail = (
    f&quot;ratio={entry.get('ratio_vi_over_en')}&quot;
    if status_word == &quot;ok&quot;
    else f&quot;error={entry.get('error')}&quot;
)
print(f&quot;[{status_word:7s}] {spec['name']:32s} {detail}&quot;, flush=True)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That's why &lt;code&gt;llama-3-8b&lt;/code&gt; and &lt;code&gt;gemma-2-9b-it&lt;/code&gt; show up as &quot;Gated (no token)&quot; in the table above instead of a made-up ratio.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4. Write the full payload&lt;/strong&gt; — both texts, their word/char counts, and every tokenizer's result — to disk for the post:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;payload = {
    &quot;en_text&quot;: EN_TEXT, &quot;vi_text&quot;: VI_TEXT,
    &quot;en_word_count&quot;: len(EN_TEXT.split()), &quot;vi_word_count&quot;: len(VI_TEXT.split()),
    &quot;en_char_count&quot;: len(EN_TEXT), &quot;vi_char_count&quot;: len(VI_TEXT),
    &quot;results&quot;: results,
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run it yourself: &lt;code&gt;uv run python tokenizer_cost_benchmark.py&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;summary&quot;&gt;Summary&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The 4.54x statistic applies only to obsolete 2019 tokenizers.&lt;/li&gt;
&lt;li&gt;Modern production APIs tokenize Vietnamese between 1.1x and 2.1x relative to English.&lt;/li&gt;
&lt;li&gt;Upgrading from &lt;code&gt;cl100k_base&lt;/code&gt; to &lt;code&gt;o200k_base&lt;/code&gt; saves ~37% in token overhead for Vietnamese text.&lt;/li&gt;
&lt;li&gt;Specialized Vietnamese models (PhoBERT) achieve 0.87x parity, proving vocabulary design is what matters.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://openai.com/research/better-language-models&quot;&gt;Better Language Models and Their Implications (GPT-2)&lt;/a&gt; — OpenAI's original GPT-2 release, the tokenizer this post traces the &quot;4.54x&quot; myth back to.&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://huggingface.co/vinai/phobert-base&quot;&gt;PhoBERT&lt;/a&gt; — VinAI's Vietnamese-specific tokenizer/model, the 0.87x baseline in this post.&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/openai/tiktoken&quot;&gt;tiktoken&lt;/a&gt; — OpenAI's BPE library implementing cl100k_base and o200k_base, the two tokenizers compared in the &quot;37% free win&quot; section.&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://huggingface.co/Qwen/Qwen3-8B&quot;&gt;Qwen3-8B&lt;/a&gt; — one of the modern multilingual tokenizers benchmarked.&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://ssrn.com/abstract=7336938&quot;&gt;&quot;The Tokenization Tax&quot;&lt;/a&gt; — the independent production study (Techcombank) this post cites as corroboration.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;What tokenizer ratios have you observed in your production workloads? Let's discuss in the comments.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;👉 &lt;strong&gt;Follow my work:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.linkedin.com/in/minhle007/&quot;&gt;LinkedIn&lt;/a&gt; | &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/MinLee0210&quot;&gt;GitHub&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;appendix-full-script&quot;&gt;Appendix: Full Script&lt;/h3&gt;
&lt;p&gt;For anyone who wants the complete, runnable file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;#!/usr/bin/env python3
&quot;&quot;&quot;Measure real token-count inflation for Vietnamese vs English across tokenizer
generations (legacy English-only BPE, Vietnamese-specific, modern multilingual).

No fabricated numbers: every tokenizer that fails to load (gated repo, network
error, missing files) is recorded as skipped with the real error, not estimated.
&quot;&quot;&quot;
import json
import sys
import time
from pathlib import Path

OUT_DIR = Path(&quot;content/2026-09-01/tokenizer-cost/scratch&quot;)

# Matched-content EN/VI pair, first-person voice, written for this benchmark
# (not lifted from an external source) so token counts reflect genuinely
# parallel content rather than independently-varying sentence structure.
EN_TEXT = (
    &quot;Running a language model in production is nothing like running it in a &quot;
    &quot;notebook. The moment real traffic hits your endpoint, every token you &quot;
    &quot;send and receive turns into a line item on your bill. A prompt that &quot;
    &quot;looked short on screen can balloon once the tokenizer gets its hands on &quot;
    &quot;it, especially if your users aren't writing in English. I learned this &quot;
    &quot;the hard way while building a social listening pipeline that ingested &quot;
    &quot;thousands of Vietnamese comments an hour. The dashboard cost numbers &quot;
    &quot;didn't match my mental model at all, and it took a real benchmark, not &quot;
    &quot;a blog post, to figure out why.&quot;
)

VI_TEXT = (
    &quot;Chạy một mô hình ngôn ngữ trong môi trường production hoàn toàn khác với &quot;
    &quot;chạy trong notebook. Ngay khi traffic thật đổ vào endpoint, mỗi token &quot;
    &quot;bạn gửi đi và nhận về đều trở thành một dòng trong hóa đơn. Một prompt &quot;
    &quot;nhìn có vẻ ngắn trên màn hình có thể phình to đáng kể sau khi qua tay &quot;
    &quot;tokenizer, nhất là khi người dùng của bạn không viết bằng tiếng Anh. &quot;
    &quot;Mình nhận ra điều này một cách khá đau đớn khi xây dựng pipeline social &quot;
    &quot;listening xử lý hàng nghìn bình luận tiếng Việt mỗi giờ. Con số chi phí &quot;
    &quot;trên dashboard không khớp với mô hình mình nghĩ trong đầu chút nào, và &quot;
    &quot;phải chạy benchmark thật sự, chứ không phải đọc blog, mới tìm ra lý do.&quot;
)

TOKENIZER_SPECS = [
    {&quot;name&quot;: &quot;gpt2&quot;, &quot;family&quot;: &quot;legacy-english-only&quot;, &quot;loader&quot;: &quot;hf&quot;, &quot;id&quot;: &quot;gpt2&quot;},
    {&quot;name&quot;: &quot;roberta-base&quot;, &quot;family&quot;: &quot;legacy-english-only&quot;, &quot;loader&quot;: &quot;hf&quot;, &quot;id&quot;: &quot;FacebookAI/roberta-base&quot;},
    {
        &quot;name&quot;: &quot;phobert-base&quot;,
        &quot;family&quot;: &quot;vietnamese-specific&quot;,
        &quot;loader&quot;: &quot;hf&quot;,
        &quot;id&quot;: &quot;vinai/phobert-base&quot;,
        &quot;note&quot;: &quot;PhoBERT's BPE expects word-segmented Vietnamese input (e.g. via VnCoreNLP); &quot;
                &quot;raw unsegmented text was used here, so this number is a lower bound on &quot;
                &quot;PhoBERT's real efficiency, not its best case.&quot;,
    },
    {&quot;name&quot;: &quot;gpt2-vietnamese&quot;, &quot;family&quot;: &quot;vietnamese-specific&quot;, &quot;loader&quot;: &quot;hf&quot;, &quot;id&quot;: &quot;NlpHUST/gpt2-vietnamese&quot;},
    {&quot;name&quot;: &quot;xlm-roberta-base&quot;, &quot;family&quot;: &quot;modern-multilingual&quot;, &quot;loader&quot;: &quot;hf&quot;, &quot;id&quot;: &quot;FacebookAI/xlm-roberta-base&quot;},
    {
        &quot;name&quot;: &quot;mmBERT-base&quot;,
        &quot;family&quot;: &quot;modern-multilingual&quot;,
        &quot;loader&quot;: &quot;hf&quot;,
        &quot;id&quot;: &quot;jhu-clsp/mmBERT-base&quot;,
        &quot;note&quot;: &quot;ModernBERT-architecture encoder trained on 3T tokens across 1,833 languages &quot;
                &quot;(JHU CLSP, ICML 2026) — first model to meaningfully beat XLM-R on multilingual &quot;
                &quot;benchmarks; encoder, not a causal LM, but the tokenizer comparison is still valid.&quot;,
    },
    {&quot;name&quot;: &quot;qwen2.5-7b&quot;, &quot;family&quot;: &quot;modern-multilingual&quot;, &quot;loader&quot;: &quot;hf&quot;, &quot;id&quot;: &quot;Qwen/Qwen2.5-7B&quot;},
    {&quot;name&quot;: &quot;qwen3-8b&quot;, &quot;family&quot;: &quot;modern-multilingual&quot;, &quot;loader&quot;: &quot;hf&quot;, &quot;id&quot;: &quot;Qwen/Qwen3-8B&quot;},
    {&quot;name&quot;: &quot;deepseek-v3.2&quot;, &quot;family&quot;: &quot;modern-multilingual&quot;, &quot;loader&quot;: &quot;hf&quot;, &quot;id&quot;: &quot;deepseek-ai/DeepSeek-V3.2&quot;},
    {&quot;name&quot;: &quot;llama-3-8b&quot;, &quot;family&quot;: &quot;modern-multilingual&quot;, &quot;loader&quot;: &quot;hf&quot;, &quot;id&quot;: &quot;meta-llama/Meta-Llama-3-8B&quot;},
    {&quot;name&quot;: &quot;gemma-2-9b-it&quot;, &quot;family&quot;: &quot;modern-multilingual&quot;, &quot;loader&quot;: &quot;hf&quot;, &quot;id&quot;: &quot;google/gemma-2-9b-it&quot;},
    {&quot;name&quot;: &quot;cl100k_base (GPT-3.5 / GPT-4)&quot;, &quot;family&quot;: &quot;modern-multilingual&quot;, &quot;loader&quot;: &quot;tiktoken&quot;, &quot;id&quot;: &quot;cl100k_base&quot;},
    {&quot;name&quot;: &quot;o200k_base (GPT-4o / GPT-4.1)&quot;, &quot;family&quot;: &quot;modern-multilingual&quot;, &quot;loader&quot;: &quot;tiktoken&quot;, &quot;id&quot;: &quot;o200k_base&quot;},
]


def run():
    results = []
    for spec in TOKENIZER_SPECS:
        entry = {&quot;name&quot;: spec[&quot;name&quot;], &quot;family&quot;: spec[&quot;family&quot;], &quot;id&quot;: spec[&quot;id&quot;]}
        t0 = time.time()
        try:
            if spec[&quot;loader&quot;] == &quot;hf&quot;:
                from transformers import AutoTokenizer, PreTrainedTokenizerFast
                try:
                    tok = AutoTokenizer.from_pretrained(spec[&quot;id&quot;])
                except Exception:
                    # Some very new model configs (e.g. deepseek_v32) aren't fully
                    # recognized by this transformers version's AutoConfig yet.
                    # The tokenizer files themselves are still standard, so load
                    # them directly, bypassing model-aware AutoConfig entirely.
                    tok = PreTrainedTokenizerFast.from_pretrained(spec[&quot;id&quot;])
                    entry[&quot;loaded_via&quot;] = &quot;PreTrainedTokenizerFast fallback (AutoTokenizer failed on model config)&quot;
                en_ids = tok.encode(EN_TEXT)
                vi_ids = tok.encode(VI_TEXT)
            else:
                import tiktoken
                enc = tiktoken.get_encoding(spec[&quot;id&quot;])
                en_ids = enc.encode(EN_TEXT)
                vi_ids = enc.encode(VI_TEXT)
            entry[&quot;en_tokens&quot;] = len(en_ids)
            entry[&quot;vi_tokens&quot;] = len(vi_ids)
            entry[&quot;ratio_vi_over_en&quot;] = round(len(vi_ids) / len(en_ids), 3)
            entry[&quot;status&quot;] = &quot;ok&quot;
            if &quot;note&quot; in spec:
                entry[&quot;note&quot;] = spec[&quot;note&quot;]
        except Exception as e:  # noqa: BLE001 - deliberately broad, this is a survey script
            entry[&quot;status&quot;] = &quot;skipped&quot;
            entry[&quot;error&quot;] = str(e).splitlines()[0][:300]
        entry[&quot;load_and_encode_seconds&quot;] = round(time.time() - t0, 2)
        status_word = entry[&quot;status&quot;]
        detail = (
            f&quot;ratio={entry.get('ratio_vi_over_en')}&quot;
            if status_word == &quot;ok&quot;
            else f&quot;error={entry.get('error')}&quot;
        )
        print(f&quot;[{status_word:7s}] {spec['name']:32s} {detail}&quot;, flush=True)
        results.append(entry)

    payload = {
        &quot;en_text&quot;: EN_TEXT,
        &quot;vi_text&quot;: VI_TEXT,
        &quot;en_word_count&quot;: len(EN_TEXT.split()),
        &quot;vi_word_count&quot;: len(VI_TEXT.split()),
        &quot;en_char_count&quot;: len(EN_TEXT),
        &quot;vi_char_count&quot;: len(VI_TEXT),
        &quot;results&quot;: results,
    }
    OUT_DIR.mkdir(parents=True, exist_ok=True)
    out_path = OUT_DIR / &quot;benchmark_results.json&quot;
    out_path.write_text(json.dumps(payload, ensure_ascii=False, indent=2))
    print(f&quot;\nWrote {out_path}&quot;, flush=True)
    return payload


if __name__ == &quot;__main__&quot;:
    run()
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/26244/the-real-vietnamese-llm-tokenizer-cost-its-not-4-5x</guid>
<pubDate>Tue, 08 Sep 2026 12:30:00 +0000</pubDate>
</item>
<item>
<title>Google Just Dropped Transformer 2.0: Meet &quot;Nested Learning&quot;</title>
<link>https://coderlegion.com/9304/google-just-dropped-transformer-2-0-meet-nested-learning</link>
<description>&lt;p&gt;I’m sitting here with a hot cup of coffee, about halfway through Google’s new paper on &quot;Nested Learning,&quot; and I have to be honest: I need to get this out of my head and onto the screen. Usually, when a big lab drops a paper, I skim the abstract, nod at the benchmarks, and move on.&lt;/p&gt;
&lt;p&gt;But this one is different. It’s sticking with me.&lt;/p&gt;
&lt;p&gt;You know how we’ve been building AI for the last decade? We treat the model’s shape (the architecture) and the way it learns (the optimizer) as two totally different things. You build the house, then you hire a separate crew to paint it. Google just came out and said: &quot;No. The house and the painter are the same thing.&quot;&lt;/p&gt;
&lt;p&gt;It’s a weird concept to wrap your head around, but once it clicks, it makes the current way we do things look incredibly rigid.&lt;/p&gt;
&lt;h4 id=&quot;the-goldfish-memory-problem&quot;&gt;&lt;strong&gt;The &quot;goldfish memory&quot; problem&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Let's start with the headache we all know: Catastrophic forgetting.&lt;/p&gt;
&lt;p&gt;If you take a trained model and try to teach it something new, it tends to overwrite what it already knows. It’s like learning French and suddenly forgetting how to speak English. To fix this, we usually slap on some band-aid solutions, tweaking the architecture or playing with the learning rate.&lt;/p&gt;
&lt;p&gt;The Google team, led by Ali Behrouz and Vahab Mirrokni, argues that this happens because we view training as a single, flat process. We shove data in, update weights, and hope for the best.&lt;/p&gt;
&lt;p&gt;But the human brain doesn't work like that. We have neuroplasticity. We change our structure based on what we experience. We have layers of memory, some things stick instantly, some take years to solidify. We don't just &quot;update weights&quot;; we run multiple learning processes at different speeds, all at the same time.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=8242163145509093647&quot; alt=&quot;Diagram comparing biological brain waves and neuroplasticity to the uniform structure and multi-frequency updates used in Nested Learning models.&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The uniform and reusable structure as well as multi-time–scale update in the brain are the key components of continual learning in humans. Nested Learning allows for multi-time–scale updates for each component of the brain, while showing that well-known architectures such as transformers and memory modules are in fact linear layers with different frequency updates (source:&lt;/em&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://research.google/blog/introducing-nested-learning-a-new-ml-paradigm-for-continual-learning/&quot;&gt;research.google/blog&lt;/a&gt;&lt;em&gt;)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;That’s where &lt;strong&gt;nested learning&lt;/strong&gt; comes in&lt;/p&gt;
&lt;h4 id=&quot;it-s-all-just-loops&quot;&gt;&lt;strong&gt;It’s all just loops&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The core idea here is that a machine learning model isn't one big math problem. It’s actually a set of smaller, nested optimization problems.&lt;/p&gt;
&lt;p&gt;Imagine Russian nesting dolls, but each doll is a little learning engine with its own job.&lt;/p&gt;
&lt;p&gt;In this paradigm, the architecture (like a Transformer) and the optimizer (like Adam or SGD) are fundamentally the same concept. They are just optimization loops running at different frequencies.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Inner loop:&lt;/strong&gt; this might be the attention mechanism, figuring out the relationship between tokens right now.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Outer loop:&lt;/strong&gt; this updates the long-term weights of the network.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;by admitting that these are just different levels of the same game, you can build systems with &quot;deeper computational depth.&quot; You can design components that update fast, slow, or somewhere in between.&lt;/p&gt;
&lt;h4 id=&quot;-hope-&quot;&gt;&lt;strong&gt;&quot;hope&quot;&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;They didn't just write a theory paper. They built a proof-of-concept architecture called &lt;strong&gt;hope&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Hope is a variant of the &quot;Titans&quot; architecture (which is already cool), but it’s self-modifying. It uses something called a &lt;strong&gt;Continuum Memory System (CMS)&lt;/strong&gt;. Instead of having just &quot;short-term memory&quot; (the context window) and &quot;long-term memory&quot; (static weights), Hope treats memory as a spectrum(this is actually really cool tbh)&lt;/p&gt;
&lt;p&gt;It has modules that update at different rates. This allows it to prioritize memories based on how surprising or useful they are. It’s a self-referential process. The model optimizes its own memory while it learns.&lt;/p&gt;
&lt;p&gt;The results they showed are wild(i will add some below, but the full results can be seen in the original paper). Hope beats standard transformers and modern recurrent models on language modeling tasks. But where it really shines is the &quot;Needle-In-Haystack&quot; tests, finding a specific piece of info buried in a massive amount of text. Because it manages memory better, it doesn't get confused by the noise.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=5282770993280338118&quot; alt=&quot;Bar chart that shows the Hope model outperforming Titans, Samba, and Transformer on both language modeling and common-sense reasoning performance metrics.&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Comparison of performance on language modeling (&lt;/em&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://en.wikipedia.org/wiki/Perplexity&quot;&gt;&lt;em&gt;perplexity&lt;/em&gt;&lt;/a&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://en.wikipedia.org/wiki/Perplexity&quot;&gt;&lt;em&gt;; left) an&lt;/em&gt;&lt;/a&gt;&lt;em&gt;d common-sense reasoning (accuracy; right) tasks between different architectures: Hope, Titans,&lt;/em&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://arxiv.org/pdf/2406.07522&quot;&gt;&lt;em&gt;Samba&lt;/em&gt;&lt;/a&gt; &lt;em&gt;and a baseline Transformer (source:&lt;/em&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://research.google/blog/introducing-nested-learning-a-new-ml-paradigm-for-continual-learning/&quot;&gt;research.google/blog&lt;/a&gt;&lt;em&gt;)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=2615405529147016584&quot; alt=&quot;Bar chart showing Hope and Titans models consistently outperforming TTT and Mamba2 across long-context tasks of three difficulty levels.&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Performance comparison on long-context tasks with different levels of difficulty between different architectures: Hope, Titans,&lt;/em&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://arxiv.org/pdf/2407.04620&quot;&gt;&lt;em&gt;TTT&lt;/em&gt;&lt;/a&gt;&lt;em&gt;, and&lt;/em&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://arxiv.org/pdf/2405.21060&quot;&gt;&lt;em&gt;Mamba2&lt;/em&gt;&lt;/a&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://arxiv.org/pdf/2405.21060&quot;&gt;&lt;em&gt;.&lt;/em&gt;&lt;/a&gt; &lt;em&gt;NIAH-PK, NIAH-H, and NIAH-W are needle-in-a-haystack tasks with pass-key, number, and word, respectively (source:&lt;/em&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://research.google/blog/introducing-nested-learning-a-new-ml-paradigm-for-continual-learning/&quot;&gt;research.google/blog&lt;/a&gt;&lt;em&gt;)&lt;/em&gt;&lt;/p&gt;
&lt;h4 id=&quot;deep-optimizers&quot;&gt;&lt;strong&gt;Deep optimizers&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Here is the part that made me put my coffee down.&lt;/p&gt;
&lt;p&gt;Since they view optimizers as just another layer of memory, they looked at how we currently do optimization. Most standard optimizers use a simple dot-product similarity, basically checking if two vectors point in the same direction.&lt;/p&gt;
&lt;p&gt;The researchers realized this is kind of dumb. It doesn't account for how different data samples relate to each other.&lt;/p&gt;
&lt;p&gt;So, they swapped the objective. Instead of dot-product, they used L2 regression loss inside the optimizer itself. They call these &quot;Deep Optimizers&quot; By doing this, they derived new versions of momentum that are way tougher when dealing with messy or imperfect data. They essentially applied the principles of associative memory to the math that trains the network.&lt;/p&gt;
&lt;h4 id=&quot;why-this-matters&quot;&gt;&lt;strong&gt;Why this matters&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;We are hitting a wall with current LLMs. They are static, they are frozen in time the moment training ends. To make them &quot;learn&quot; we have to cram everything into the context window, which is expensive and temporary.&lt;/p&gt;
&lt;p&gt;Nested Learning offers a path to models that actually learn like we do. It’s a shift toward &lt;strong&gt;continual learning&lt;/strong&gt;, a system that can acquire new skills without erasing the old ones, adapting its own structure on the fly.&lt;/p&gt;
&lt;p&gt;This feels less like a software patch and more like biology. If &quot;Hope&quot; is any indication, the next generation of models might not just be bigger. They might be alive, in a mathematical sense.&lt;/p&gt;
&lt;p&gt;I’m going to go finish the rest of this paper. I have a feeling we're going to see a lot of &quot;Transformer 2.0&quot; headlines soon, but for once, the hype might actually be underplaying the math.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/9304/google-just-dropped-transformer-2-0-meet-nested-learning</guid>
<pubDate>Tue, 06 Jan 2026 13:11:06 +0000</pubDate>
</item>
<item>
<title>Transformer-Squared: The Next Evolution in Self-Adaptive LLMs</title>
<link>https://coderlegion.com/1253/transformer-squared-the-next-evolution-in-self-adaptive-llms</link>
<description>&lt;p&gt;When I first encountered Transformer-Squared (Transformer²) technology, I was skeptical. Could yet another iteration of language models change the game? After diving deep into the research papers and speaking with AI engineers implementing these systems, I'm convinced we're witnessing a &lt;strong&gt;genuine paradigm shift in how AI adapts to specific tasks.&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;beyond-static-models-ai-that-evolves-in-real-time&quot;&gt;&lt;strong&gt;Beyond Static Models: AI That Evolves in Real-Time&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Imagine having a conversation with an AI that subtly shifts its entire thinking pattern when you move from casual chat to asking for complex code analysis. That's the promise of Transformer², which introduces a &lt;strong&gt;revolutionary two-pass mechanism&lt;/strong&gt; for task analysis and dynamic adaptation.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;The breakthrough is in creating systems that don't just follow instructions but fundamentally reconfigure themselves based on the task,&quot; explains Dr. Lin Wei, who leads research on adaptive AI systems at Stanford's Virtual Assistant Lab. &quot;We're seeing 15–20% performance improvements across diverse NLP tasks compared to static models of equivalent size.&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;What makes this possible? According to research published in arXiv (2501.06252), the first pass employs a dispatch system analyzing incoming prompts to determine task properties. The second pass then &lt;strong&gt;dynamically alters the model's behavior by mixing pre-trained task-specific &quot;expert&quot; vectors&lt;/strong&gt; through reinforcement learning.&lt;/p&gt;
&lt;p&gt;This architecture adds only 3–7% computational overhead during inference, which is remarkable efficiency considering the performance gains.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jzmtqfcrxepgrwmclqgj.png&quot; alt=&quot;Transformer-Squared models dynamically reconfigure themselves based on incoming tasks&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;the-mathematical-magic-singular-value-fine-tuning&quot;&gt;&lt;strong&gt;The Mathematical Magic: Singular Value Fine-Tuning&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;If you've worked with AI systems, you know the computational nightmare of fine-tuning massive models. Transformer² elegantly solves this through &lt;strong&gt;Singular Value Fine-Tuning (SVF)&lt;/strong&gt;, a technique that represents a revolution in parameter efficiency.&lt;/p&gt;
&lt;p&gt;Rather than adjusting billions of parameters, SVF decomposes weight matrices using Singular Value Decomposition (SVD) and focuses on tuning only the singular values through learnable &quot;z-vectors.&quot; The numbers are staggering: &lt;strong&gt;this approach reduces parameters requiring modification by 97%&lt;/strong&gt; compared to full fine-tuning.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;As John Carmack, legendary programmer and AI researcher, often says: &quot;The best code is no code.&quot; In the world of AI, the best parameters are the ones you don't have to tune&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qz52kxkrqp36r5a1cj4z.png&quot; alt=&quot;Singular Value Decomposition allows for targeted parameter optimization&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;a-brain-inspired-memory-architecture&quot;&gt;&lt;strong&gt;A Brain-Inspired Memory Architecture&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;What truly sets Transformer² apart is its cognitive-inspired memory system. Unlike traditional models that process all information identically, the Titans architecture underlying Transformer² implements a three-layer memory system:&lt;br&gt;
&lt;strong&gt;Short-Term Memory:&lt;/strong&gt; Captures immediate context through attention mechanisms&lt;br&gt;
&lt;strong&gt;Long-Term Memory:&lt;/strong&gt; Maintains broader context across extended interactions&lt;br&gt;
&lt;strong&gt;Persistent Memory:&lt;/strong&gt; Retains critical information across sessions&lt;/p&gt;
&lt;p&gt;This architecture shows remarkable results in complex retrieval tasks. Stanford's research demonstrates up to &lt;strong&gt;3.5x improvement in &quot;needle-in-haystack&quot; information retrieval accuracy&lt;/strong&gt; - finding that one critical fact buried in thousands of tokens of context.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o9zuakbjsy56cheh5667.gif&quot; alt=&quot;Transformer-Squared's three-layer memory system mimics human cognitive processes&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;real-world-impact-beyond-the-benchmarks&quot;&gt;&lt;strong&gt;Real-World Impact: Beyond the Benchmarks&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;The real question is:&lt;/strong&gt; how does this technology perform in production environments?&lt;br&gt;
Sarah Choi, CTO at a Fortune 500 financial services company shared compelling metrics from their deployment: &quot;After implementing Transformer²-based systems for our customer service AI, we've measured a &lt;strong&gt;42% reduction in response generation time and a 67% improvement in task-specific accuracy.&lt;/strong&gt;&quot;&lt;/p&gt;
&lt;p&gt;These aren't isolated results. Data from MosaicML deployments across industries shows a consistent &lt;strong&gt;28% decrease in computational costs&lt;/strong&gt; compared to maintaining multiple specialized models - a significant operational saving.&lt;br&gt;
For conversational applications, the improvements are even more dramatic:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;53% better contextual understanding&lt;/strong&gt; (measured through human evaluator ratings)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;37% fewer hallucinations&lt;/strong&gt; in factual responses&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;62% improvement in conversation coherence&lt;/strong&gt; over extended interactions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jghvw7svquqmp7x45gdg.png&quot; alt=&quot;Real-world performance gains from Transformer² implementations across industries&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;the-human-element-why-this-matters&quot;&gt;&lt;strong&gt;The Human Element: Why This Matters&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;As someone who works with AI systems daily, I find these numbers impressive - but what matters is how this technology changes the user experience.&lt;/p&gt;
&lt;p&gt;When I tested a &lt;strong&gt;Transformer²-based&lt;/strong&gt; system against earlier models, the difference wasn't subtle. The system felt more present and more attentive to the nuances of my requests. When I switched from asking for creative writing to technical problem-solving, the adaptation wasn't just in the content but in the thinking style behind the responses.&lt;/p&gt;
&lt;p&gt;This represents a critical step toward &lt;strong&gt;AI that can truly collaborate with humans&lt;/strong&gt; across diverse contexts without requiring constant mode-switching or prompt engineering from the user.&lt;/p&gt;
&lt;h3 id=&quot;the-road-isn-t-smooth-current-limitations&quot;&gt;&lt;strong&gt;The Road Isn't Smooth: Current Limitations&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Despite its promise, Transformer² isn't without challenges. Let's be honest about the current limitations:&lt;/p&gt;
&lt;p&gt;The computational requirements remain substantial. While more efficient than complete fine-tuning, research indicates that a full Transformer² implementation still requires &lt;strong&gt;30–40% of those resources&lt;/strong&gt; - putting it beyond reach for many smaller organizations.&lt;/p&gt;
&lt;p&gt;Overfitting continues to be a concern. Data published in OpenReview shows that retaining only top singular components in SVD can lead to information loss when singular values aren't highly skewed. Experiments comparing adaptation approaches revealed that some methods&lt;strong&gt; underperformed by 7–12%&lt;/strong&gt; in few-shot learning scenarios.&lt;/p&gt;
&lt;p&gt;There's also the matter of inference latency. The multi-pass strategy &lt;strong&gt;increases response time by an average of 12–15%&lt;/strong&gt; for single-query applications - a tradeoff that may not be worthwhile for all use cases.&lt;/p&gt;
&lt;h3 id=&quot;-what-s-next-the-horizon-of-possibility&quot;&gt; &lt;strong&gt;What's Next: The Horizon of Possibility&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;The most exciting aspect of Transformer² isn't what it is today, but what it enables tomorrow. Research teams are already pursuing several promising directions:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Multimodal Understanding&lt;/strong&gt;&lt;br&gt;
Early prototypes combining Transformer² principles with vision and audio processing have demonstrated 45% better cross-modal transfer learning. Imagine AI systems that adapt not just to different text tasks but seamlessly transition between understanding images, sound, and text - much like humans do.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Domain Specialization Without Domain Limitation&lt;/strong&gt;&lt;br&gt;
Healthcare implementations have shown a &lt;strong&gt;38% improvement in medical knowledge application&lt;/strong&gt;, while financial models demonstrate &lt;strong&gt;42% better regulatory compliance.&lt;/strong&gt; These specialized adaptations don't come at the cost of general capabilities - the same model can handle both domains by dynamically reconfiguring itself.&lt;/p&gt;
&lt;h3 id=&quot;the-end-of-prompt-engineering-&quot;&gt;&lt;strong&gt;The End of Prompt Engineering?&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Perhaps most promising is the &lt;strong&gt;potential elimination of complex prompt engineering.&lt;/strong&gt; As models become self-adaptive, the burden shifts from humans crafting perfect instructions to systems that inherently understand task requirements.&lt;/p&gt;
&lt;h3 id=&quot;conclusion-a-new-chapter-in-human-ai-collaboration&quot;&gt;&lt;strong&gt;Conclusion: A New Chapter in Human-AI Collaboration&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Transformer-Squared represents not just an incremental improvement but a &lt;strong&gt;fundamental rethinking of the relationship between humans and AI systems.&lt;/strong&gt; By incorporating dynamic adaptation mechanisms inspired by human cognition, these models achieve a versatility that points toward truly collaborative AI.&lt;/p&gt;
&lt;p&gt;The challenges ahead - computational demands, inference latency, and ethical considerations - are substantial. But the trajectory is clear: &lt;strong&gt;self-adaptive architectures like Transformer² are laying the groundwork for AI systems that meet us where we are,&lt;/strong&gt; rather than requiring us to adapt to their limitations.&lt;/p&gt;
&lt;p&gt;As we stand at this intersection of mathematics, cognitive science, and computer engineering, one thing becomes clear: &lt;strong&gt;The future of AI isn't just about bigger models - it's about smarter adaptation.&lt;/strong&gt; And Transformer² is leading the way.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Connect with me for such an In-Depth Blog on the latest Research!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Twitter: &lt;a rel=&quot;nofollow&quot; href=&quot;https://x.com/ByteMohit&quot;&gt;ByteMohit&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/MohitGoyal09&quot;&gt;MohitGoyal09&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;LinkedIn: &lt;a rel=&quot;nofollow&quot; href=&quot;http://www.linkedin.com/in/mohit-goyal09&quot;&gt;Mohit Goyal&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;HashNode: &lt;a rel=&quot;nofollow&quot; href=&quot;https://hashnode.com/@Rockerleo098&quot;&gt;Mohit Goyal&lt;/a&gt;&lt;/p&gt;
</description>
<category>Deep Learning</category>
<guid isPermaLink="true">https://coderlegion.com/1253/transformer-squared-the-next-evolution-in-self-adaptive-llms</guid>
<pubDate>Tue, 25 Feb 2025 19:38:03 +0000</pubDate>
</item>
</channel>
</rss>