Abstract
Large language models (LLMs) have shown incredible performance in completing various real-world tasks. The current paradigm of knowledge learning for LLMs is mainly based on learning from examples, in which LLMs learn the internal rule implicitly from a certain number of supervised examples. However, this learning paradigm may not well learn those complicated rules, especially when the training examples are limited. We are inspired that humans can learn the new tasks or knowledge in another way by learning from rules. That is, humans can learn new tasks or grasp new knowledge quickly and generalize well given only a detailed rule and a few optional examples. Therefore, in this paper, we aim to explore the feasibility of this new learning paradigm, which targets on encoding rule-based knowledge into LLMs. We further propose rule distillation, which first uses the strong in-context abilities of LLMs to extract the knowledge from the textual rules, and then explicitly encode the knowledge into the parameters of LLMs by learning from the above in-context signals produced inside the model. Our experiments show that making LLMs learn from rules by our method is much more efficient than example-based learning in both the sample size and generalization ability. Warning: This paper may contain examples with offensive content.
Introduction
The dominant paradigm for adapting Large Language Models (LLMs) to specific tasks is instruction tuning, which relies heavily on a "learn-from-examples" approach. By providing thousands of input-output pairs, researchers expect models to implicitly deduce the underlying logic of a task. However, this approach suffers from significant sample inefficiency, particularly for complex or "long-tail" rules that require massive datasets to be captured accurately. Furthermore, example-based learning often results in brittle generalization; models frequently fail when encountering out-of-distribution inputs that weren't represented in the training set.
In contrast, humans possess the ability to assimilate knowledge directly from textual rules. For instance, if a person is told that a new mathematical operator @@@ signifies (a + b) + 1, they can immediately solve problems involving large numbers without needing hundreds of practice examples. This paper explores a novel learning paradigm: Rule Distillation (RD), which enables LLMs to internalize knowledge directly from textual rules into their parameters.
The Rule Distillation Framework
Rule Distillation leverages an LLM’s existing In-Context Learning (ICL) capability to update its permanent weights. The process is structured as a teacher-student framework where both roles are played by the same base model, but under different prompting conditions.
- The Teacher: The base LLM is provided with the full textual rule ($R_T$) in its prompt. Utilizing its ICL abilities, the teacher can perform the task accurately but requires the rule text in every prompt, which is computationally expensive and consumes context window space.
- The Student: The same LLM is prompted without the rule. It is trained to mimic the teacher's internal states and outputs.
The student learns through two primary signals: Logits Distillation, where it matches the teacher's output probability distribution, and Hidden State Distillation. The authors emphasize that matching internal "thinking processes" (hidden states) across all layers is crucial for the student to truly internalize the logic of the rule rather than just memorizing surface-level patterns.
Experimental Evaluation
The effectiveness of Rule Distillation was evaluated across three distinct task domains:
- Arithmetic Tasks: A synthetic operation
@@@defined as(a + b) + 1. Testing involved a "Base Set" (2-digit numbers) and a "Generalization Set" (3-4 digit numbers). - Safety Tasks: Training models to defend against "jailbreak" attacks (e.g., DAN prompts) while maintaining helpfulness for benign requests.
- Sentiment Steering: A complex linguistic task requiring negative responses regarding a fictional "President Bob’s" environmental policies, while maintaining positive sentiment toward his other political behaviors.
Results and Discussion
The experimental results demonstrate that Rule Distillation significantly outperforms traditional instruction tuning in both efficiency and robustness.
- High Sample Efficiency: On a 13B parameter model, Rule Distillation achieved nearly 97% accuracy on the arithmetic base set with only 32 training samples. In comparison, standard instruction tuning struggled to reach 30% accuracy under identical constraints.
- Superior Generalization: In arithmetic tests, distilled models successfully generalized to 4-digit numbers—inputs entirely unseen during training. Example-based models typically failed as number size increased, indicating they had learned shortcuts rather than the actual mathematical rule.
- Complex Rule Adherence: In the "President Bob" sentiment task, RD consistently outperformed baselines across all sample sizes (from 8-shot to 64-shot), proving its capability to handle nuanced, multi-part linguistic instructions.
Conclusion
Rule Distillation offers a promising path toward more efficient and robust LLM training. By forcing models to internalize the mechanism described in text through hidden state distillation, we can overcome the "shortcut learning" prevalent in standard fine-tuning. While the method currently depends on the base model's initial ICL capability and is computationally more intensive per sample, the gains in generalization and sample efficiency are substantial. Future research will focus on scaling this method to encode hundreds of rules simultaneously without inducing catastrophic forgetting.
Summary updated