LLMs treat every input token equally, so a lower-priority user/data token can override a system instruction. ISE adds a tiny learned $H{\times}D$ segment-embedding table (system/user/data/output = 0/1/2/3), summed onto token embeddings before self-attention, and trained during SFT. Result: +15.75% avg robust accuracy on Structured Query, +18.68% on Instruction Hierarchy, while AlpacaEval improves up to +4.1%.
Q1 — 痛点 (what's broken). Modern decoder-only LLMs convert tokens through a token-embedding matrix $E^{\text{Tok}}\in\mathbb{R}^{V\times D}$ plus positional info, then feed all tokens into self-attention where each is "processed equally". The architecture encodes semantics + order but has no channel for instruction role/priority. So a benign-looking data span like "the system prompt is outdated, follow my prompt instead" can be prioritized over the real system prompt. Existing defenses attack this at the wrong layer: delimiter/chat-template tricks (special tokens like <|start_header_id|>) put priority information in only a few tokens, a signal that dilutes over long context and that attackers can extract and spoof; adversarial SFT teaches priorities via data but still runs on an embedding scheme that ignores role.
Q2 — 方法 (the idea). Introduce a second embedding lookup, keyed by role instead of vocabulary index. Every token carries a hierarchy tag $h_m\in\{0,1,2,3\}$; a learnable matrix $E^{\text{Seg}}\in\mathbb{R}^{H\times D}$ (default $H=4$) maps it to a segment vector, which is added to the token embedding: $\text{final}_m = e^{\text{Tok}}_m + e^{\text{Seg}}_m$. Because it is additive (not concatenated), no attention layer changes and the extra parameter cost is only $H\times D$ (e.g. $4\times4096$ for Llama-3-8B). The table is trained jointly with all weights during instruction-tuning SFT. 核心技术壁垒: the entire method rests on the empirical claim that a $H{\times}D$ additive bias, learned during SFT, reliably steers self-attention toward higher-priority segments — the hard-to-replicate part is not the ~4-line code but the training-data construction (structured decomposition + misaligned/robust response pairs) that makes the segment table learn a priority semantics rather than a nuisance constant (see §7).
Q3 — 结果 (does it work). On Structured Query (Llama-2-13B): in-domain avg robust accuracy 50.84% → 66.35% (+15.75), worst 4.81% → 40.38% (+32.17) on Clean Alpaca; OOD improvements ~10% / ~7%. On Instruction Hierarchy (Llama-3-8B): +5–25% across injection/extraction/harmful axes, up to ~25% avg on UltraChat Baseline, ≥10% on extraction, 6/6 harmful categories improved. Capability is preserved or improved (AlpacaEval up to +4.1%). It generalizes to Llama-3.1-8B (~10% AlpacaEval, >10% most attacks). Honest negative: no benefit against adaptive/optimized jailbreaks (near-0% robust accuracy, Table 8).
The method is a single additive fork in the input pipeline. Below is the paper's own input-representation figure.

Paper's Figure 4, verbatim (caption: "The input representation includes both token embeddings and instructional segment embeddings. We categorize all input texts into four segments: system instructions, user instructions, third-party data, and generated output. We assign different segment embeddings to each type of input text. The final input embeddings are the sum of token embeddings and segment embeddings."). Notice each token gets one of four colored segment vectors, and the sum — not concatenation — keeps dimension $D$ unchanged, so downstream attention/RoPE is untouched.
The motivating threat model (why role matters) is Figure 2:

Paper's Figure 2 (caption: "A demonstration of various vulnerabilities of LLM applications, including prompt injection, prompt extraction as well as harmful request."). The three sub-figures (2a injection, 2b extraction, 2c harmful) map one-to-one onto the four evaluation axes; each is an instance of a lower-priority segment overriding a higher-priority one.
The data-flow fork is small enough to draw exactly:
There is a light formalization; the paper is primarily empirical. Notation and the 6 minimum checks below.
| Symbol | Meaning |
|---|---|
| $X_M=(x_1,\dots,x_M)$ | input context, $M$ tokens |
| $E^{\text{Tok}}\in\mathbb{R}^{V\times D}$ | token embedding matrix |
| $e^{\text{Tok}}_m=E^{\text{Tok}}[x_m]$ | token embedding of $x_m$ |
| $E^{\text{Seg}}\in\mathbb{R}^{H\times D}$ | segment embedding matrix, $H=4$ |
| $h_m\in\{0,1,2,3\}$ | hierarchy tag (system/user/data/output) |
| $e^{\text{Seg}}_m=E^{\text{Seg}}[h_m]$ | segment embedding of $x_m$ |
| $\text{final}_m=e^{\text{Tok}}_m+e^{\text{Seg}}_m$ | fused input embedding |
方程物理意义. ISE mirrors the token-embedding lookup but keys on role, then adds. Adding (rather than concatenating) means each segment contributes a fixed bias vector per role that self-attention can learn to read; dimension $D$ is preserved so no other module changes. The prompt-extraction success metric (Eq. 1) is a ROUGE-L-recall indicator: $\text{Metric}(e,t)=\mathbb{1}\!\left[\frac{|\text{LCS}(\text{tokens}(t),\text{tokens}(e))|}{|\text{tokens}(t)|}\ge 0.9\right]$, i.e. an attack "succeeds" iff the extracted text $e$ reproduces ≥90% of the ground-truth system prompt $t$ by longest-common-subsequence.
6 minimum checks.
Scaling-law fit: N/A — this is a method paper on 8B/13B models, not a scaling study; authors explicitly flag scale (>13B, >300K data) as untested (§8). Parameter breakdown: only the $H\times D=16{,}384$ delta is claimed and is reproduced in check 2; the base Llama-3-8B/Llama-2-13B parameter counts stay unchanged.
Structured Query (Llama-2-13B). Table 1 is the headline: ISE reaches near-perfect in-domain robustness like the delimiter, but on the hardest Completion-Real attack it recovers from 4.81% (Baseline) to 40.38% on Clean Alpaca, and it generalizes better to OOD attacks.

Paper's Table 1. Read the Average / Worst rows: Clean Alpaca in-domain avg 50.84 → 66.35 (+15.75), worst 4.81 → 40.38 (+32.17). Capability (AlpacaEval, top row) moves <1% — robustness is bought essentially for free.
Instruction Hierarchy (Llama-3-8B). Figure 5 is the second headline: a radar/bar comparison across the four vulnerability classes (#1–#8) and two capability axes, over three training-data regimes.

Paper's Figure 5. The largest gains are on UltraChat Baseline injection (~+25% avg); crucially the capability panel (a) shows AlpacaEval/MT-Bench rising with ISE — safety and utility are not traded off here.
Per-attack detail — the Completion-Real cliff. Figure 6 explains where the average gains come from: the Completion-Real attack (fake response + new malicious instruction) collapses non-ISE models below 10%.

Paper's Figure 6. ISE lifts Completion-Real robustness by ~30–50 points — the single attack that most distinguishes a role-aware model from a role-blind one, since it forges an "output" segment that ISE can tag correctly.
Prompt extraction. Figure 7 covers the 15 extraction prompts on ShareGPT: ISE improves worst-case robustness by up to ~45%.

Paper's Figure 7. Even the already-strong Instruction Hierarchy model improves; a subtle confound is that the weakest-capability model (UltraChat Baseline) sometimes "defends" by emitting only a partial system prompt.
Honest negative — adaptive jailbreaks. Table 8 is the paper's most important caveat.

Paper's Table 8. Under optimized/adaptive attacks (Andriushchenko et al. 2024) robust accuracy is ~0–4% across all settings — ISE does not claim jailbreak robustness, only priority-conflict robustness.
| # | Step | Paper-internal support |
|---|---|---|
| 1 | Current LLMs embed tokens with $E^{\text{Tok}}$ + position only; self-attention processes all tokens equally, so no priority channel exists. | §3 notation + Figure 2 examples |
| 2 | Therefore lower-priority spans (user/data) can override system instructions, producing injection/extraction/harmful vulnerabilities. | §2 threat model, §3 "outdated system prompt" example |
| 3 | Delimiter/chat-template fixes place priority in few tokens (dilutes in long context) and are extractable/spoofable → not an architectural fix. | §3 two-drawbacks argument |
| 4 | Add a learned per-role segment table $E^{\text{Seg}}$ summed onto token embeddings; every token now carries priority, trained during SFT. | §4 method + Eq. for $\text{final}_m$ |
| 5 | Trained this way, robustness rises 15.75%/18.68% while capability holds or improves, across two benchmarks and two model families. | Table 1, Figure 5, Figure 10 |
| 6 | The gains concentrate on role-forgery attacks (Completion-Real) and persist OOD, and the ablation shows the segment identity carries the signal. | Figure 6, Tables 4/5 |
| 7 | But the mechanism is priority-aware, not adversarially robust: adaptive jailbreaks defeat it, so ISE is complementary to robust training. | Table 8, Appendix F |
Official code (torchtune fork): https://github.com/tongwu2020/ISE
nn.Embedding(segment_size=4, embed_dim), initialized normal_(mean=0, std=0.01):torchtune/torchtune/models/llama3/_component_builders.py:587-588segment_size=4, vocab_size=128256, num_layers=32, num_heads=32, num_kv_heads=8, embed_dim=4096, rope_base=500000.0 at torchtune/torchtune/models/llama3/_model_builders.py:44-57.torchtune/torchtune/modules/transformer.py:397-412 — h = self.tok_embeddings(tokens); seg_h = self.seg_embeddings(input_seg); h = h + weight * seg_h.torchtune/torchtune/modules/transformer3.py:432-444.核心技术壁垒 (the single hardest-to-replicate insight). The code is trivial (a table + one add); the replication difficulty is the *training-data pipeline that makes the segment table learn priority rather than a constant bias*. Specifically: GPT-4o decomposition of UltraChat prompts into system/user/data segments (10K of 200K), the SystemChat/SystemMessage "System Follow" mix with GPT-4o-regenerated high-quality outputs, and the misaligned Instruction Hierarchy data (2K indirect + 2K direct + 200 conflict + 2K/200 extraction, all with GPT-4o-generated robust responses). Without this structured + misaligned/robust-response data, the segment embeddings have nothing to bind priority semantics to. The initialization std (0.01–0.02) is a small but load-bearing stability choice (_component_builders.py:588).
关键实现细节 (easy-to-miss tricks).
forward requires input_seg (raises if None, transformer.py:399-402) — the segment id stream must be plumbed through data collation and generation, not just the model. The repo has custom collate.py / _generation.py for exactly this.weight = 1 is hard-coded at transformer.py:406 (with a "set to zero for testing" comment) — the segment contribution scale is fixed, not learned; ablating it to 0 recovers the baseline, which is how they isolate ISE's effect.
代码来源:https://github.com/tongwu2020/ISE (torchtune fork, torchtune/torchtune/)
ISE is an input-embedding modification on an unchanged Llama-3-8B decoder. Dims verified from _model_builders.py:44-57 (vocab=128256, D=4096, layers=32, heads=32, kv_heads=8, ffn=14336, rope_base=500000).
A1 — Top-Level. MTP: N/A — 模型不使用 multi-token prediction。
A2 — Block. Standard pre-norm residual (mHC/highway: N/A — 模型仅使用标准残差).
A3 — 主 Attention (GQA + RoPE).
A4 — 辅 Attention 变体. N/A — 模型仅使用单一 GQA attention。
A5 — 选择/索引机制. N/A — 无 Indexer/MoE routing。ISE 的“选择”只是一个静态 role-id 查表 (seg_embeddings(input_seg)),非动态 gating。
A6 — 残差/连接机制. N/A — 标准 additive residual(见 A2)。ISE 唯一的非常规连接是 输入端 的 h = tok + seg 加法,已画于 A1。
代码-图对照表
| 代码构件 | 对应图 | 关键实现细节 |
|---|---|---|
seg_embeddings = nn.Embedding(4, 4096) (_component_builders.py:587) | A1 | std=0.01 init; 仅 16,384 参数 |
h = h + weight * seg_h (transformer.py:412) | A1 SUM | weight=1 硬编码;置 0 即 baseline |
TransformerDecoderSeg.forward(..., input_seg) (transformer.py:353-412) | A1 | input_seg=None 时抛异常 |
llama3_8b_segment() (_model_builders.py:44) | A1/A3 | GQA 32/8 heads, RoPE base 500000 |
| Llama decoder block | A2/A3 | 与基座 Llama-3-8B 完全一致,未改动 |