Skip to content

Train on prefill, monitor during decoding: topic monitoring with SAETrain on prefill, monitor at decode: Using sparse autoencoders for topic monitoring

arXiv: Interpretability· arXiv:2611.12935· Rishikesh Mallagundla, Pranav PatelMercityIndexed by this site · 13 days ago· Originally publishedAlignment

Quick read

Defenses

Based on the paper PDF (AI-generated); refer to the original

The authors propose TopicScope, which trains a token-by-token topic monitor on Gemma-3 1B/4B using SAE features; the authors say prefill training transfers to decode, and macro-F1 drops by at most 5 points under perturbation.

Threat modelThe defender labels the topic of the reply token by token during generation, promptly detecting when a single-purpose assistant (e.g., billing customer service) deviates from its preset scope in multi-turn conversations; the monitor reads the backbone model's own activations, only the detector is trained, and the LLM and SAE are frozen. The paper does not set an adversarial attacker.

Questions
Single-purpose assistants may deviate from their preset topic range in multi-turn dialogue. Existing streaming guardrails only make two- to three-class safety judgments, while topic guardrails classify the entire text once after generation ends and cannot locate topic switch points token by token during generation.
Methods
TopicScope uses GPT-5.6 Luna to generate 10,000 synthetic dialogues with token-level topic annotations, extracts Gemma Scope 2 SAE features from the last 10 layers of Gemma 3 in prefill, trains three causal detectors (GRU, ConvNeXt, Transformer), and at deployment runs them unchanged on decode.
Experiments and results
prefill test macro-F1 peaks at 97.3% (Gemma 3 1B, dynamic, ConvNeXt); the authors say the detector trained on prefill transfers to decode, with purity reaching 90–98%; under four types of perturbation macro-F1 drops by at most 5 points; without the SAE, accuracy is comparable but detector parameter count rises from 1.4M–3.6M to 7.6M–20.7M (Gemma 3 4B).
Limitations and future work
Future directions listed by the authors: decode lacks per-token gold labels, there is no dedicated off-topic category, the perturbation analysis does not cover the NoSAE detector, it has not been tested on real deployed multi-turn conversations, and larger backbones and other model families have not been validated. The experiments cover only Gemma 3 1B/4B and 7 synthetic topics.
Experimental setupGemma 3 1B、Gemma 3 4B · Simula 生成的合成多主题对话语料(10,000 条、7 个主题) · macro-F1、overlap et al.
Evaluated models
Gemma 3 1BGemma 3 4B
Benchmarks
Simula 生成的合成多主题对话语料(10,000 条、7 个主题)
Metrics
macro-F1overlappuritycoveragefull coverageAUROC
AI summaryThe researchers propose the TopicScope framework, which trains a causal topic classifier on SAE features, assigning a topic label to each token in a model response, with labels able to switch mid-response. The team trained three detector architectures on synthetic multi-topic conversations covering seven topics; on Gemma-3 1B and 4B, monitors trained on features extracted from prefill hidden states generalized to the decoding stage. The classifier is robust to perturbations, with macro-F1 dropping by at most 5 points when off-topic content is inserted, topics are deleted, or paragraphs are reordered. Ablation experiments show that classifiers reaching baseline performance without SAE require several times the scale. The authors state this indicates that compact topic monitors can be trained cheaply at the prefill stage and deployed during generation, and also demonstrates uses of SAE beyond safety classification.

The researchers propose the TopicScope framework, which trains a causal topic classifier on SAE features, assigning a topic label to each token in a model response, with labels able to switch mid-response. The team trained three detector architectures on synthetic multi-topic conversations covering seven topics; on Gemma-3 1B and 4B, monitors trained on features extracted from prefill hidden states generalized to the decoding stage. The classifier is robust to perturbations, with macro-F1 dropping by at most 5 points when off-topic content is inserted, topics are deleted, or paragraphs are reordered. Ablation experiments show that classifiers reaching baseline performance without SAE require several times the scale. The authors state this indicates that compact topic monitors can be trained cheaply at the prefill stage and deployed during generation, and also demonstrates uses of SAE beyond safety classification.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    Existing monitors cannot label reply topics token by token during generation; the authors propose TopicScope to fill this gap.

    Core question: how to label the topic of each token while a language model generates a reply, so that a boundary violation is detected at the moment the reply drifts off topic.

    • Application scenario: The authors note that deployed assistants are mostly single-purpose (customer service, billing, clinical triage), and in multi-turn dialogue, even with system prompts or fine-tuning constraints, the model may still deviate from its preset topic range, causing cost and alignment problems.
    • Shortcomings of existing methods: Streaming safety guardrails (such as Qwen3Guard, SCM) work token by token during generation, but their labels are two- to three-class safety judgments; topic guardrails (such as NeMo Guardrails, CantTalkAboutThis) classify the prompt or the complete reply once and cannot locate topic switch points within a reply. The authors state that no monitor currently exists that can label topics token by token while a reply is being generated in a streaming fashion.
    • Core observation: In a causal language model, the hidden state of the same token is computed the same way in both prefill and decode, so a detector trained on prefill can be expected to transfer directly to decode.
    • Paper proposal: The TopicScope framework—extract SAE features of the backbone model in prefill, train a small causal detector to label each token with one of seven topics, and at deployment run it unchanged on decode; it is organized around four research questions: whether SAE features carry token-level topic signal (RQ1), whether prefill training transfers to decode (RQ2), whether accuracy is maintained under perturbation (RQ3), and whether SAE is necessary (RQ4).
    • Threat model:
      • Protection goal: the replies of a single-purpose assistant deviate from the preset topic range during generation (non-adversarial setting; the paper does not posit an attacker).
      • Defense location: a side-channel monitor that reads the generative model's own residual-stream activations; only the detector is trained, while the LLM and SAE are frozen.
      • Monitor capability: a causal detector that can output a label as soon as each token is produced, and the label can switch mid-reply.
      • Victim system: a chat assistant with Gemma 3 1B/4B as the backbone.
  2. What related research exists?

    Related work falls into four groups: topic modeling and segmentation, topic guardrails, streaming safety guardrails, and activation probes and SAE classification inputs.

    Topic modeling and segmentation

    • Topic models such as LDA (Blei et al., 2003) and its neural variants, BERTopic (2022), and TopicGPT (2023) discover topics from an entire corpus; supervised segmentation such as TextTiling (1997) places boundaries after the text is written; topic-shift detection in dialogue determines whether a given utterance changes topic. The paper notes that these methods all operate on already-written text, whereas TopicScope labels a fixed topic set token by token during generation.
    • SAE as a topic model: Girrbach and Akata (2025) derive the SAE objective as a MAP estimate under a continuous topic model; Mechanistic Topic Models (2025) and MonoTM (2026) use SAE features instead of vocabulary to describe topics. All three remain unsupervised and corpus-level.

    Topic guardrails

    • NeMo Guardrails (2023) uses programmable rails to steer conversations away from specified topics, relying on manually curated examples; Chua et al. (2024) synthesize prompts from scope descriptions to train a classifier, removing this dependency; Fence (2026) trains a dedicated small model for application-level checks (including topic drift); CantTalkAboutThis (2024) directly fine-tunes the model to stay on topic.
    • Pan (2026) fits a one-class SVM on hidden states to flag conversation turns that depart from context; kNNGuard (2026) classifies prompts by nearest neighbors in activation space. The paper notes that these methods, whether reading text or activations, make one decision per prompt/turn/reply, and none labels replies during generation.

    Safety moderation and streaming guardrails

    • Llama Guard (2023), ShieldGemma (2024), and WildGuard (2024) classify prompts or complete replies according to harm taxonomies.
    • Streaming guardrails move checking into generation: Qwen3Guard's streaming variant adds a token-level head (2025), SCM trains a monitor with heuristic per-token harm labels and stops early (2025), SentGuard checks at sentence boundaries (2026), and FreoStream and StreamGuard attempt to anticipate harm (2026). The paper notes that these systems are temporally closest to this work, but they are separate models that read generated text (often billions of parameters), and their labels are two- to three-value safety categories; TopicScope reads the generative model's own activations and distinguishes multiple topics.

    Activation probes and SAE classification inputs

    • Linear probes (Alain and Bengio, 2016; Belinkov, 2021) and representation engineering (2023) are used as runtime monitoring: Constitutional Classifiers++ (2026) uses probes as a cheap first stage, and other probes detect strategic deception (2025), high-risk interactions (2025), and reward speculation (2026). The paper notes that these methods are the closest to this work, but each probe targets a single binary attribute; McKenzie et al. (2025) find that probes trained on synthetic data can generalize to real interactions, which is the assumption underlying this paper's use of teacher text.
    • Whether SAE features outperform raw activations is disputed: Kantamneni et al. (2025) find no stable gains under various distribution shifts, Smith et al. (2025) and AxBench (2025) report that SAE probes lag behind; Gallifant et al. (2025) and Rakuten's PII detection deployment (2025) report positive results. Practitioner guidance recommends not using SAEs when the target concept is known, and this paper's NoSAE ablation tests that recommendation on a multi-class token-level task.

    Baselines and benchmarks: The paper does not compare against external methods; the baselines are NoSAE (feeding hidden states directly, bypassing the SAE) and different feature selection rules, evaluated on the authors' own 10,000-record synthetic multi-topic dialogue corpus. The authors position this work as extending streaming safety monitoring from two to three categories to multiple topics and directly reading the generative model's own features.

  3. How does the paper address this problem?

    TopicScope: extract SAE features from a synthetic corpus in prefill, train a causal detector to label topics token by token, and deploy it unchanged in decode.

    Overall approach: exploiting the property that the hidden state of the same token is computed the same way in prefill and decode in a causal language model, TopicScope trains a small causal detector during prefill on synthetic dialogues with token-level topic annotations, and at deployment runs it unmodified on the hidden states produced during decode. The pipeline has four steps: data → prefill forward pass → SAE feature extraction and selection → detector training; only the detector is trained, and the LLM and SAE are frozen (Figure 1).

    Task formalization

    • The dialogue is tokenized as x1…xT, containing Tp prompt tokens and Tr reply tokens; topic monitoring labels each token falling within a topic segment with yt ∈ Y, where |Y| = 7 business topics.
    • The monitor is causal: ŷt = g(z1, …, zt), i.e., the label of token t is determined only by its own and preceding features, so a label can be produced as soon as the token is generated.
    • Training is in prefill (the whole dialogue in one forward pass, with a label for every token), deployment is in decode (token-by-token generation, no labels).

    Dataset construction

    • Using the authors' team's synthetic database Simula, with GPT-5.6 Luna serving as both generator and critic: topic combinations are first sampled according to a custom taxonomy of seven topics (Enterprise documents, General news & content, Customer service, Legal, Financial, HR & people operations, Healthcare) and a brief is written, then a record is generated; the critic checks it against the brief and annotation rules, and failing records are revised or discarded.
    • Each record is a prompt–reply pair; the topics and their order are fixed before writing, and the generator marks each topic segment in both the prompt and the reply, so every token receives a label (Figure 2).
    • Scale (Table 1): 10,000 records, split 7,000/1,500/1,500 for train/validation/test; 8.85M tokens in total, of which 8.2M are annotated reply tokens and 515K are prompt tokens; an average of 2.65 topics per record, with the seven topics balanced (each appearing in 3,687–3,842 records), and any ordered topic pair can occur.
    • To prevent the detector from finding boundaries via surface cues, boundaries in multi-topic records use three pivot styles: explicit connectives 40%, light/neutral connectives 35%, unmarked direct switches 25%.

    Feature extraction

    • The backbones are Gemma 3 1B and 4B, using the corresponding Gemma Scope 2 SAEs (l0_small, 16,384 features per layer, JumpReLU activations) to read the residual stream of the last N = 10 layers (layers 16–25 for 1B, 24–33 for 4B).
    • Each layer keeps K = 150 features, concatenated across layers into the detector input zt, with four types of selection:
      • Summation: keep the K features with the largest total activation over training tokens (unsupervised).
      • F-statistic: keep the K features with the largest between-topic mean difference relative to within-topic dispersion.
      • Group lasso: fit a linear probe to the seven topics from all m features with a sparse group-lasso penalty.
      • Dynamic: for each token, keep its own K most highly activated features, written into the fixed columns corresponding to those features, so the activated columns vary by token (width about 54,000).
      • NoSAE baseline: skip the SAE and feed the N layers' hidden states directly into the detector.

    Detectors and training

    • Three causal detectors (Appendix C, Table 9): GRU (3 layers, hidden width 256, history compressed into a fixed state); ConvNeXt-style TCN (6 blocks, kernel 7, dilation 1–32, left padding to ensure causality, context window 379 tokens); causal Transformer encoder (2 layers, 8 heads, lower-triangular mask, no positional encoding, sees all history). All three project the input to width 256 and end with a seven-class linear head.
    • Training: token-level cross-entropy (computed on annotated tokens), AdamW, 15 epochs, batch 16, dropout 0.1, keeping the checkpoint with the best validation macro-F1; learning rate 3×10⁻⁴ for GRU/Transformer and 1×10⁻³ for ConvNeXt.
    • Success criteria and evaluation: prefill uses macro-F1 (token-level F1 averaged equally over the seven topics) and overlap (the average per-topic IoU between predicted and true tokens); decode has no per-token labels, so it uses three metrics related to consistency with the request—purity, coverage, and full coverage (definitions in question 4).
  4. What experiments did the paper conduct?

    Evaluate prefill accuracy on 1,500 test records and decode transfer on 1,000 self-generated replies, and run four types of perturbation and a NoSAE ablation.

    Experimental setup

    • Backbones tested: Gemma 3 1B and Gemma 3 4B, each with Gemma Scope 2 SAE (l0_small, reading the last 10 layers).
    • Data: 10,000 synthetic multi-topic dialogues generated by Simula (generated and critiqued by GPT-5.6 Luna), split 7,000/1,500/1,500 for train/validation/test; the decode experiments additionally use 1,000 test prompts with topic labels removed, with replies generated by the backbone itself.
    • Method variants: 5 inputs (summation, F-statistic, group lasso, dynamic, NoSAE) × 3 detectors (GRU, ConvNeXt, Transformer).
    • Metrics: prefill reports macro-F1 and overlap (the authors say overlap is stricter because F1 counts each correct token twice); decode reports purity (the proportion of reply tokens labeled as the requested topic), coverage (the proportion of requested topics that receive at least one-tenth of the tokens), and full coverage (the proportion of replies in which all requested topics meet the threshold).
    • Evaluation method: no LLM judge; decode metrics are rule-based statistics over the detector output against the topics requested in the prompt, with the same detector reading teacher replies as a reference.
    • Number of repetitions: not reported in the paper; the training seed is fixed at 42 (Table 9).

    Main results

    prefill test macro-F1 (%, from Table 2):

    Swipe horizontally to read the table

    Input1B GRU1B ConvNeXt1B Transformer4B GRU4B ConvNeXt4B Transformer
    Summation94.596.294.387.492.491.8
    F-statistic96.496.295.796.495.595.0
    Group lasso96.896.395.596.395.594.9
    Dynamic96.197.394.092.497.194.0
    NoSAE96.596.795.996.397.594.9
    • The authors note: on 1B, unsupervised summation already reaches 94.3–96.2, but on 4B summation lags across the board (GRU drops to 87.4); after switching to label-driven selection rules, the gap between 4B and 1B narrows to within 1 point for each detector, the two supervised rules differ from each other by no more than 0.4 points, and the authors consider the hyperparameter-free F-statistic more economical.
    • ConvNeXt is strongest in six of the ten rows; GRU is most sensitive to input (87.4–96.8).
    • decode transfer (Table 3): with dynamic or label-selected features, purity is 90–98% for both scales and all three detectors; the exception is 4B summation (GRU purity 69.4, ConvNeXt full coverage 33.7), and label selection raises GRU purity from 69 to 95 and ConvNeXt full coverage from 34 to 81.

    Details of decode transfer (RQ2, Tables 3, 4)

    • What was tested: the detectors trained in RQ1 are used without retraining to label the backbone's own generated replies to 1,000 unlabeled test prompts, and compared with reference scores from the same detector reading teacher replies.
    • Results: full coverage is 95–99 on teacher replies, and drops by about 30 points on 1B and more on 4B for backbone-generated replies; full coverage decreases as the number of requested topics increases, from near 100 for a single topic to 34–62 for four topics. Raising the generation limit from 1,500 to 8,000 tokens does not change the scores.
    • Authors' interpretation: the coverage gap mainly comes from Gemma itself answering fewer topics under crowded prompts, rather than detector mislabeling; the authors also note that these metrics only measure which topics were used, not the location of topic switch points, and leave boundary localization under decode to future work.

    Perturbation robustness (RQ3, Figures 5–7, Table 5)

    • What was tested: four types of perturbations to held-out replies—inserting off-topic chatter at topic boundaries (not scored), deleting one requested topic, shuffling the order of topic segments, and replacing a segment with one from another record on the same topic (control)—all passed through the backbone again and scored under dynamic features.
    • Results: no perturbation reduces macro-F1 by more than 5 points (Figure 5); the replacement control is almost unchanged (within ±0.2), which the authors take to mean the detector labels segments by their own content. ConvNeXt loses the least under each perturbation (no more than 1.1 points); reordering affects the Transformer most (−5.0 on 1B), which the authors explain by its ability to see the entire prompt while training replies all answer in prompt order, whereas ConvNeXt's 379-token window mostly cannot see the prompt.
    • Inserted off-topic text: the label set has no "none" class, so inserted text is still labeled with a topic (mostly General news & content); GRU and Transformer confidence can distinguish inserted text (AUROC 80–91, Table 5), but dynamic ConvNeXt is only 54 and 51, and group lasso is the only input that brings all three detectors to 80 at both scales. After deleting a topic, each input labels 1–4% of reply tokens with the deleted topic, with Enterprise documents most affected (7–8%).

    SAE necessity ablation (RQ4, Table 6)

    • Accuracy: NoSAE is the best input on 1B Transformer and 4B ConvNeXt, and in three of the other four cases it is within 0.3 points of the best; the exception is 1B dynamic ConvNeXt, which leads NoSAE by 0.6 points (97.3 vs. 96.7). NoSAE's decode transfer is at least as good (GRU and ConvNeXt purity 95–96, highest 4B full coverage).
    • Scale: static SAE detector inputs are fixed at width 1,500, with 1.4M–3.6M parameters, independent of backbone size; NoSAE inputs widen with the backbone, reaching 7.6M–20.7M on 4B. At inference, static selection needs only the selected rows of the SAE encoder (1B 1.73M, 4B 3.84M parameters), whereas fully loading ten SAEs requires 378M/839M.
    • Authors' interpretation: SAEs are not necessary for accuracy; their benefit is keeping monitor size from growing with the backbone and making each input column an inspectable named feature.

    Other ablations and analyses

    • Per-topic overlap (Appendix A, Table 7): Enterprise documents and HR are the two hardest topics for almost all detectors on 4B; stronger detectors narrow the gap between topics from 9 points (summation GRU) to 3.5 points (dynamic ConvNeXt).
    • Prompt supervision (Appendix A, Table 8): after adding about 515K prompt tokens to supervision, reply overlap changes by within 1.2 points in 10 of 12 settings.
    • Layer knockout (Appendix B, Figures 8, 9): zeroing layer 29 costs 32.5 overlap points for 4B summation GRU, while under F-statistic the worst single layer costs only 1.2 points; dynamic and NoSAE have the most dispersed layer dependence (no more than 4.7 except 11.4 for 1B NoSAE Transformer).
    • Feature attribution (Appendix B): zeroing the top-10 attributed features in the most important layer costs 0.1–10.3 overlap points, while the bottom 10 cost at most 0.16; under group lasso, about half the budget per layer contributes little.
    • Agreement between attribution and knockout (Figure 10): group lasso has an average rank correlation of +0.63 (top layers agree in 5 of 6 detectors), while summation is only +0.10; the authors therefore rank layers by knockout rather than attribution.
  5. What are some points that can be further explored?

    The authors list five future directions, including decode gold labels and a dedicated off-topic class; the experiments cover only two Gemma 3 backbones and synthetic corpora.

    Limitations and future directions noted by the authors

    • Decode lacks token-level gold labels (Section 5.2 and Section 6): existing decode metrics only measure which topics the detector used, not where it places topic switch points; evaluating boundary localization with generated text that has gold labels is left for future work.
    • No dedicated off-topic class (Section 6): inserted off-topic chatter is still assigned some topic and can only be indirectly flagged via a drop in confidence; the authors propose adding a dedicated class so the monitor can directly mark inserted content.
    • Perturbation analysis does not cover the NoSAE detector (Section 6): the authors propose extending the perturbation experiments to the raw hidden-state detector to complete the comparison with SAE inputs.
    • Not tested on real deployment data (Section 6): the authors propose training on multi-turn dialogues collected from deployed assistants to test the effect on gradual drift (i.e., the motivating scenario of this paper).
    • Coverage of backbones and SAE suites (Section 6): the authors propose using larger backbones, other model families and other SAE suites to test whether the property that the monitor has a fixed scale continues to hold.

    Scope of experimental coverage

    • The backbones tested are Gemma 3 1B and 4B, 2 in total; the SAE uses only the l0_small variant of Gemma Scope 2 (Table 10).
    • The data are 10,000 single-turn prompt–reply pairs generated by Simula, covering 7 commercial topics, split 7,000/1,500/1,500 into training/validation/test (Table 1); both generation and critique are performed by GPT-5.6 Luna.
    • Decode evaluation uses 1,000 test prompts with topic labels removed; the metrics are purity, coverage and full coverage, with no token-level gold labels (Section 5.2).
    • Perturbation experiments include four types: insertion, deletion, reordering and substitution, scored under dynamic features; the insertion experiment additionally tests the F-statistic and group lasso (Section 5.3).
    • The paper does not report the number of repeated training runs or confidence intervals for each setting (the training seed is fixed at 42, Table 9), nor does it report the detector's actual latency overhead during generation.
  6. Summarize the main content of the paper

    TopicScope trains a token-level topic monitor on SAE features; prefill training transfers to decode, and the value of SAE lies in scale rather than precision.

    A defense-oriented paper on topic monitoring during generation: it lets a single-purpose assistant be caught at the moment its reply drifts, rather than classifying the whole generation after it is complete.

    • Problem: streaming safety guardrails have only two to three safety labels, and topic guardrails make a single judgment on the whole text after generation ends; the authors say no monitor currently labels topics token by token during generation.
    • Method: TopicScope uses GPT-5.6 Luna to generate 10,000 seven-topic synthetic dialogues with token-level annotations, extracts Gemma Scope 2 SAE features from the last 10 layers of Gemma 3 1B/4B during prefill (150 per layer), trains three small detectors—GRU, ConvNeXt, and a causal Transformer—and at deployment runs them unmodified on decode hidden states; the LLM and SAE are frozen throughout.
    • prefill accuracy: on 1,500 test records, label-driven feature selection brings macro-F1 to 94.9–97.3 for both backbones (Table 2); unsupervised summation fails on 4B (GRU 87.4), and switching to F-statistic restores it to 96.4.
    • decode transfer: the detector labels the backbone's own generated replies without retraining, with purity of 90–98% under dynamic or label-selected features (Table 3); full coverage is the weakest metric, and the authors attribute the gap mainly to Gemma answering fewer topics under crowded prompts.
    • Robustness: under four types of perturbation—inserting off-topic text, deleting a topic, reordering, and same-topic replacement—macro-F1 drops by at most 5 points, and the replacement control is almost unchanged (Figure 5).
    • Role of the SAE: NoSAE accuracy is comparable to or even better than SAE inputs, but static SAE detectors have a fixed 1.4M–3.6M parameters and do not grow with the backbone, whereas NoSAE reaches 7.6M–20.7M on 4B (Table 6); the authors argue the SAE's benefit is compact size and inspectable named features, not accuracy.
    • Authors' conclusion: a compact topic monitor can be trained cheaply in prefill and deployed during generation; future directions include decode gold labels, an off-topic category, real multi-turn data, and larger backbones.
Read originalarxiv.org