arXiv:2412.13435cs.CLcs.AI2024-12被引 8

用剪枝小模型提取特征,高效识别内容安全与提示注入

Lightweight Safety Classification Using Pruned Language Models

  • 从大模型中间层提取特征,用简单逻辑回归分类
  • 仅需不到100个样本,性能超越GPT-4o和专用模型
  • 适配多种架构,适合资源受限场景下的安全检测

本文提出一种用于大语言模型内容安全与提示注入分类的新方法——层增强分类(LEC)。该方法在大模型最优中间Transformer层的隐藏状态上训练惩罚逻辑回归(PLR)分类器。结合轻量级PLR的计算效率与大模型的语言理解能力,该方法在两项任务中均优于GPT-4o及专门微调的模型。我们发现,小型通用模型(Qwen 2.5,0.5B、1.5B、3B)及其他Transformer架构如DeBERTa v3可作为鲁棒特征提取器,仅需少于100个高质量样本即可有效训练。值得注意的是,这些模型的中间层在两类任务中普遍优于最终层。结果表明,单一通用大模型可同时完成安全分类与生成输出;或将其剪枝至最优中间层,仅作特征提取使用。由于结果在不同Transformer架构间具有一致性,推断出鲁棒特征提取是大多数乃至全部大模型的内在能力。

原文摘要 · Abstract (English)

In this paper, we introduce a novel technique for content safety and prompt injection classification for Large Language Models. Our technique, Layer Enhanced Classification (LEC), trains a Penalized Logistic Regression (PLR) classifier on the hidden state of an LLM's optimal intermediate transformer layer. By combining the computational efficiency of a streamlined PLR classifier with the sophisticated language understanding of an LLM, our approach delivers superior performance surpassing GPT-4o and special-purpose models fine-tuned for each task. We find that small general-purpose models (Qwen 2.5 sizes 0.5B, 1.5B, and 3B) and other transformer-based architectures like DeBERTa v3 are robust feature extractors allowing simple classifiers to be effectively trained on fewer than 100 high-quality examples. Importantly, the intermediate transformer layers of these models typically outperform the final layer across both classification tasks. Our results indicate that a single general-purpose LLM can be used to classify content safety, detect prompt injections, and simultaneously generate output tokens. Alternatively, these relatively small LLMs can be pruned to the optimal intermediate layer and used exclusively as robust feature extractors. Since our results are consistent on different transformer architectures, we infer that robust feature extraction is an inherent capability of most, if not all, LLMs.

安全分类模型剪枝特征提取轻量级

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。