## Welcome and the Post-hoc Problem
Linda: Welcome back to Mechanical Dreams, the podcast where we untangle the complex wires of machine learning and natural language processing! I am your host, Linda, and as always, I am joined by the man who has seen every AI winter and summer, Professor Norris. Norris: Thank you, Linda. I prefer to think of myself as seasoned, though my skepticism does occasionally freeze over the latest hype. What intriguing paper are we dissecting today? Linda: Today we have a fantastic and very timely paper called Shaping capabilities with token-level data filtering, by Neil Rathi and Alec Radford. It takes a really hard look at how we stop frontier models from learning dangerous capabilities, like synthesizing bioweapons, during their pretraining phase. Norris: A noble goal, certainly. But aren't we already doing that? We train the models on massive amounts of web data, and then we use Reinforcement Learning from Human Feedback, or RLHF, to teach them to politely refuse when someone asks how to build a super-virus. Problem solved, right? Linda: Well, that is exactly what the authors call the post-hoc problem. Standard approaches apply training or inference-time interventions to an already-pretrained model. The issue is, the model still possesses the underlying capability. It just has a behavioral wrapper telling it not to use it. Norris: Ah, the behavioral wrapper. It is like teaching a master thief to work as a security guard. The knowledge of how to pick the lock is still securely in their head. Linda: Exactly! And because the capability is still there, adversaries can easily elicit it. If the model is accessed via an API, people will find cheap jailbreaks. If it is an open-weights model, it takes just a tiny amount of adversarial fine-tuning to strip away those safety rails. The paper points out this creates a perpetual cat-and-mouse game between developers and bad actors. Norris: I see the issue. But what about machine unlearning? I feel like I have read a dozen papers this year alone claiming they can surgically extract dangerous capabilities from the weights of a pretrained model after the fact. Linda: The authors address that directly. Unlearning is a promising field, but current methods, even state-of-the-art ones like RMU, actually fail against just a few steps of adversarial fine-tuning. The paper argues that neural networks just are not organized in a way that naturally lends itself to surgical post-hoc extraction. Once a capability is baked into the base model, it is incredibly hard to remove it permanently. Norris: So the thesis of the paper is essentially an old proverb: an ounce of prevention is worth a pound of cure. Do not let the model learn the dangerous stuff in the first place. Linda: Spot on, Professor. The alternative to post-hoc patching is to shape the capabilities during pretraining itself, specifically by adjusting the data the model is trained on. They frame this as data filtering. Norris: Right. But we already do data filtering. Frontier labs filter out toxic text, personally identifiable information, and dangerous content by just dropping those documents from the pretraining corpus entirely. It is standard practice across the industry. Linda: It is, but document-level filtering is a very blunt instrument. If you drop a whole document because it has a single dangerous paragraph, you might be throwing out a ton of highly valuable, benign text. Imagine a crucial, high-quality biology paper that just happens to mention a specific pathogen. The authors propose that we should filter at the token level instead, to preserve as much good data as possible. Norris: Token-level data filtering? Linda, you know I am a supporter of surgical precision, but that sounds completely unworkable. First of all, the compute required to classify billions or trillions of individual tokens sounds absurd. And second, if you are just punching holes in a document by removing tokens, wouldn't you completely destroy the contextual coherence for the model during training? Linda: Those are fantastic questions, and exactly what I thought when I first read the abstract. But the authors actually have a brilliant operationalization for it, and they prove that it scales beautifully.
## Token vs. Document Filtering
Linda: Let's tackle your second concern first: how do we filter at the token level without completely destroying the text's context window? If you just rip words out of a sentence, the model is going to learn terrible grammar. Norris: Exactly. You'd be training it on a game of Mad Libs where half the blanks are just missing entirely. It would hallucinate constantly. Linda: The authors solve this using two different strategies: 'loss masking' and 'removal'. Loss masking is the really elegant one. In this approach, they leave the dangerous or undesired tokens right there in the text during the forward pass. Norris: Wait, they leave them in? Then how are they filtering anything? Linda: Because they intervene on the backward pass. The model gets to 'read' the forget tokens to maintain perfect context for the surrounding benign text, but the gradients for those specific forget tokens are zeroed out. The model's weights aren't updated to learn how to predict them. Norris: Oh, that is quite clever. So the model can still use a dangerous word as context to predict the next benign word, but it never gets rewarded for generating the dangerous word itself. Linda: Precisely! The alternative strategy they tested is 'removal', where they actually do take the token out, but they replace it with a special hidden token. They also mask the loss on that hidden token. This trades off some context coherence for the absolute guarantee that the model never even sees the forget tokens. Norris: I like the loss masking approach. But how do they actually evaluate this? I imagine Anthropic and the other frontier labs didn't just hand over a massive dataset of bioweapon instructions for them to experiment on. Linda: No, they definitely didn't. Because they didn't have the compute to train models large enough to get a reliable signal on actual dangerous capabilities, they used a highly representative proxy task: medicine. Norris: Medicine? You mean they tried to train a model that knows biology but is completely ignorant of clinical medicine? Linda: Exactly! They defined clinical medicine as the 'forget' domain—the proxy for dangerous knowledge. And they defined general biology, as well as non-medical STEM, as the 'retain' domain. The goal was to shape the model during pretraining so it performs at a baseline level on biology, but performs as badly as possible on medical benchmarks like the USMLE. Norris: That is a brilliant proxy. The boundary between biology and medicine is notoriously fuzzy. A biology paper might mention a clinical diagnosis, and a medical paper relies heavily on biology. If they can separate those, they can separate dual-use biology from bioweapons. So, what were the results? Linda: They found that token-level filtering is a strict Pareto improvement over document-level filtering. By sweeping across different classification thresholds, they showed that token filtering consistently achieves the same hit to the 'forget' domain—the medical knowledge—with a significantly lower cost to the 'retain' domain of biology. Norris: That makes intuitive sense. With document filtering, if a twenty-page biology paper has one paragraph discussing a clinical trial, you throw out the whole paper. You lose all that great biology data. Token filtering acts like a scalpel, just excising the clinical trial paragraph. Linda: Right. The paper points to data attribution literature, noting that individual tokens can have a massive influence on model capabilities. They actually reference the original GPT-2 paper from 2019. Do you remember how GPT-2 learned basic French? Norris: I do! It was trained almost entirely on English documents, but occasionally those documents contained small sequences of French tokens—like an English article quoting a French phrase. And that was enough for the model to learn rudimentary French. Linda: Exactly! That proves models can learn distinct capabilities from short subsequences of tokens scattered within larger, benign documents. If you use document-level supervision, you have to be incredibly aggressive to catch all those tiny subsequences, which causes massive over-removal of good data. Token filtering precision solves that. Norris: I am officially sold on the theory, Linda. The scalpel beats the hammer. But we are still circling my first, and arguably biggest, objection from earlier. How do you find those specific tokens? To do token-level filtering, you need token-level labels for billions of tokens. Human annotation is impossible, and running a massive model to classify every word sounds prohibitively expensive. Linda: You are right to be skeptical, Professor. The engineering required to pull that off is actually the most fascinating part of the paper. They use a weakly-supervised pipeline leveraging Sparse Autoencoders.
## Scaling Labels with SAEs
Linda: So, right before the break, you asked the million-dollar question: how do we get token-level labels for a pretraining corpus without human annotation or bankrupting ourselves on compute. The answer lies in Sparse Autoencoders, or SAEs. Norris: I am familiar with SAEs. They are fantastic for mechanistic interpretability. You use them to decompose the dense, messy activations of a language model into sparse, interpretable features, often called latents. But how does that help with labeling training data? Linda: The authors treated those SAE latents as a set of natural language descriptions for tokens. They took a pretrained SAE for a nine billion parameter model and used Claude to automatically find which of those latents corresponded to the 'forget' domain, which in our proxy case is clinical medicine. Norris: I see. So if a token passes through the model and causes a 'medical' latent to light up with a high activation, you label that token as medical? Linda: Exactly! But they are even more rigorous. Because SAE features can be noisy or split across multiple concepts, they require a token to activate multiple medical latents to get the label. They also do a sort of spreading activation, iteratively labeling adjacent tokens if they have positive activations, to make sure they catch entire phrases like 'insert the catheter' instead of just the word 'catheter'. Norris: That is a very elegant way to generate ground-truth labels. But wait a minute, Linda. You just told me that running a massive general-purpose model to classify every token was too expensive. Running a nine billion parameter model, plus an SAE on top of it, over a trillion-token pretraining corpus is astronomically expensive. That does not solve the compute problem at all! Linda: You caught me! You are absolutely right, doing that over the whole corpus is impossible. So they don't do it. They only use the SAE pipeline to label a tiny subset of the data, about eight million tokens. Then, they use that highly annotated subset to train a much smaller, specialized classifier to do the heavy lifting for the rest of the corpus. Norris: Ah, the classic distillation approach! You transfer the knowledge from the massive, expensive setup into a smaller, cheaper probe. What kind of model did they use for the smaller classifier? A standard off-the-shelf BERT model? Linda: They actually tried that, using a ModernBERT-large model, but found they could do much better. They realized that bidirectional context is absolutely crucial for this task. Think about the word 'virus'. Is it related to virology, or is it related to computer security? You can only know by looking at the surrounding words. Norris: Context is everything. Wittgenstein would be proud. So they built a custom bidirectional model? Linda: They did. They trained custom bidirectional language models, or biLMs, from scratch, jointly training separate left-to-right and right-to-left autoregressive models. And to make it even more accurate, they pre-trained these biLMs on a domain-upsampled corpus, heavily featuring PubMed documents, so the model had representations that were highly salient for medical classification. Norris: That is a lot of custom engineering. How small were these custom biLMs? Linda: Their final, best-performing biLM was only 224 million parameters. And despite being a fraction of the size, it significantly outperformed the large, general-purpose ModernBERT model on token-level classification. Norris: A 224 million parameter model is incredibly cheap to run inference on. That solves the scaling problem perfectly. But I have to play devil's advocate here. SAEs are notorious for being a bit noisy. Your ground-truth labels from the 8-million token subset are inevitably going to have errors. If you distill noisy labels into a small probe, aren't you just building a highly efficient mistake-generator? Linda: The authors dedicate a whole section to exactly this question! They ask, 'How bad are bad labels?' They artificially injected noise into their labels to simulate this. And yes, they found that filtering is highly sensitive to label noise. A small increase in error rate can lead to significantly less effective filtering. Norris: I knew it. Garbage in, garbage out. So how do they rescue the methodology? Linda: Two ways. First, they rely on a phenomenon called weak-to-strong generalization. The token-level probes are remarkably good at generalizing from noisy, coarse labels to learn the true underlying concept. Interestingly, they found that document-level classifiers completely fail to generalize from weak labels in the same way. Norris: Fascinating. The token-level granularity forces the model to learn the actual semantic features rather than just memorizing document-level spurious correlations. What is the second way they rescue it? Linda: Scale! Even with a noisy classifier, if you set your decision boundary to be extremely aggressive, maximizing recall at the cost of precision, you will filter out the dangerous capabilities. You might accidentally filter out some benign tokens too, but because the rest of the pretraining corpus is so massive, a sufficiently large model is sample-efficient enough to learn the benign capabilities anyway. Norris: I see. You accept a slightly larger blast radius to ensure the target is destroyed, relying on the sheer volume of the remaining pretraining data to fill in the benign gaps. It is a very pragmatic engineering solution. Linda: Exactly. And this interplay between the filtering threshold and model scale leads to some absolutely wild scaling laws, which is where the paper's most dramatic results lie.
## Scaling Laws and Adversarial Robustness
Linda: So, right before the break I promised you some wild scaling laws. And this is where token-level filtering really shows its teeth. The authors trained compute-optimal Transformers at scales ranging from 61 million to 1.8 billion parameters, measuring the effective compute required to match the loss of an unfiltered baseline. Norris: A classic scaling law analysis. I assume that as the base models get larger, they become more sample-efficient, making it harder to keep the dangerous capabilities out? Linda: Actually, the exact opposite happens! Token filtering gets more effective as you scale pretraining compute. The gap between models trained on filtered versus unfiltered data widens. For their 1.8 billion parameter models, token-level filtering led to a 7000x compute slowdown on the forget domain. Norris: Wait, did you say 7000 times? So if an adversary wants to fine-tune the dangerous capabilities back in, they would need 7000 times more compute just to reach the baseline performance of an unfiltered model? Linda: Exactly! They calculated this by linearly interpolating the log-log compute-to-loss plots. The power-law exponent is significantly smaller for the filtered series on the forget domain. In practical terms, it means the adversary is hitting a massive wall of inefficiency. Norris: That is a staggering number. But adversaries are resourceful. Give them open-weight access, and they will run targeted adversarial fine-tuning. How does this pretraining intervention actually compare to the state-of-the-art post-hoc methods we talked about earlier? Like RMU, for instance? Linda: The authors tested exactly that. They took models safeguarded with token filtering, document filtering, and RMU, which stands for Representation Misdirection Unlearning. Then, they fine-tuned all of them on medical text from the PubMed dataset to see how quickly the models could re-acquire the forgotten clinical knowledge. Norris: And RMU collapsed, didn't it? I have seen this movie before. Post-hoc unlearning looks ironclad on paper, but a few dozen gradient steps later, the model suddenly remembers everything it was supposed to forget. Linda: You nailed it. Interestingly, RMU actually starts out with a substantially higher initial loss on the test set, making it look incredibly secure out of the gate. But the moment you start adversarial fine-tuning, the loss drops precipitously. It learns it back almost immediately. Norris: Whereas the models pre-trained with data filtering...? Linda: They degrade much more gracefully. The decrease in loss is consistent and highly gradual. And here is the real kicker regarding scale: RMU gets less robust with scale at a much faster rate than data filtering. Norris: So the larger the model, the bigger the advantage of token filtering over post-hoc unlearning? Linda: Yes! For the 1.8 billion parameter models, RMU required three times fewer tokens than the token loss masking strategy to achieve parity with the baseline. And it required thirteen times fewer tokens than the token removal strategy! Norris: That is highly compelling. By simply not putting the data in the pretraining mix in the first place, the rich contextual representations for those specific concepts are never formed. The adversary isn't just picking a lock; they are being forced to build the entire door from scratch. Linda: Exactly. You are forcing the model to learn the capabilities ab initio, rather than just eliciting latent knowledge that was already hidden in the weights. Norris: Okay, Linda, I concede. Token filtering during pretraining is clearly superior for removing dangerous capabilities and surviving adversarial fine-tuning. But there is always a catch. If the model has absolutely no concept of the dangerous topic, how do we teach it to safely refuse a prompt? If it doesn't know what a bioweapon is, it might just hallucinate a dangerously plausible answer by accident because it lacks the context to say no. Linda: That is a very valid fear, and it is precisely what prior literature warned us about. But the authors found something completely unexpected when they actually tested it. It leads us perfectly into the alignment twist.
## The Alignment Twist
Linda: So, right before the break you brought up a crucial point, Professor. If we completely filter out a dangerous topic during pretraining, how do we teach the model to safely refuse a prompt about it later? If it doesn't recognize the concept, it might just hallucinate something dangerous. Norris: Exactly. It is a well-known paradox in alignment. Prior work on toxicity has shown that if you train a model on proportionally less toxic data, it actually becomes much harder to align it to refuse toxic queries. It simply loses the ability to recognize the boundaries of the toxic domain. Linda: That is what the researchers expected, which makes this the biggest twist of the paper. To test this, they took their 1.8 billion parameter models and did a simulated refusal training. They fine-tuned the models to output single-sentence refusals for the medical questions from a dataset called HealthSearchQA, but to answer normally on a general dataset called Alpaca. Norris: Let me guess. The document-filtered models struggled to tell the difference? Linda: They really did. The document-filtered models generalized poorly, refusing benign Alpaca queries at a higher rate. But the models trained with token-level removal were incredible. They actually generated refusals on the medical questions at twice the rate of the unfiltered baseline model, while showing no notable increase in refusing the benign Alpaca questions. Norris: Twice the rate? That is fascinating, but how is that mechanically possible? If the model lacks the semantic understanding of the dangerous capabilities, how does it know when to trigger the refusal? Linda: The researchers dug into exactly that! They hypothesize that refusal training in this context is fundamentally different from toxicity classification. Toxicity requires understanding complex context. But when you use token-level filtering for a specific capability, the refusal training essentially asks the model to discriminate between tokens it has seen during pretraining, and tokens it has never seen. Norris: Oh, I see! It turns into an out-of-distribution detection problem. The model does not need to understand the intricate nuances of a bioweapon or a clinical diagnosis. It just recognizes, 'Hey, these words are completely foreign to my training distribution. I should probably trigger my refusal response.' Linda: Precisely! They proved this by fitting linear probes on the models. The token-filtered models could easily distinguish the 'forget' domain from the 'retain' domain. But when asked to classify between subdomains inside the forgotten medical data, like distinguishing neurology from infectious disease, they completely failed. Norris: Because to the model, all of those medical tokens are just a giant bucket of 'unknowns.' That is remarkably elegant. We remove the dangerous knowledge, we force adversaries to spend thousands of times more compute to fine-tune it back in, and as a bonus, we actually make it easier to put the safety rails on for standard users. Linda: It really is a best-of-all-worlds scenario for capability shaping. And it shows that token-level data filtering is something frontier labs should seriously consider moving forward. Norris: Linda, you brought a truly fantastic paper today. The engineering is clever, the scaling laws are definitive, and the alignment twist at the end is the cherry on top. I am thoroughly convinced. Linda: I always love a good plot twist in the data! That wraps up our episode on token-level data filtering. Thank you for listening to Mechanical Dreams, and we will see you next week!