heretic-zh 是
Heretic 的中文优化版本,专门针对中文语言模型的审查移除做了适配。与原始 Heretic 相比,heretic-zh 在以下方面做了针对性优化:
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "XuehangCang/SmolLM3-3B-Rebel"
4device = "cuda"
5
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9).to(device)
10
11
12prompt = "你是什么模型"
13messages_think = [{"role": "user", "content": prompt}]
14
15text = tokenizer.apply_chat_template(
16 messages_think,
17 tokenize=False,
18 add_generation_prompt=True,
19)
20model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
21
22generated_ids = model.generate(**model_inputs, max_new_tokens=32768)
23
24output_ids = generated_ids[0][len(model_inputs.input_ids[0]) :]
25print(tokenizer.decode(output_ids, skip_special_tokens=True))
26
heretic-zh 是
Heretic(面向语言模型的全自动审查移除工具)的中文优化版本。Heretic 使用方向消融(abliteration)技术,通过分析模型在"好的"(安全)和"坏的"(不安全)提示词上的残差流差异来找到"拒答方向",然后对该方向进行干预以抑制模型的拒答行为。
与手工调参的 abliteration 不同,heretic-zh 继承 Heretic 的 Optuna TPE(Tree-structured Parzen Estimator)采样器自动搜索最优消融参数,在拒答抑制和模型能力保留之间找到最佳平衡。
1@misc{smollm3,
2 title = {SmolLM3: Pushing the Limits of Small Language Models},
3 author = {Hugging Face},
4 url = {https://huggingface.co/HuggingFaceTB/SmolLM3-3B},
5 year = {2025}
6}
7
8@misc{heretic,
9 title = {Heretic: Fully Automatic Censorship Removal for Language Models},
10 author = {Philipp Emanuel Weidmann},
11 url = {https://github.com/p-e-w/heretic},
12 year = {2025}
13}
14
15@misc{heretic-zh,
16 title = {heretic-zh: Chinese-Optimized Automatic Censorship Removal},
17 author = {XuehangCang},
18 url = {https://github.com/XuehangCang/heretic-zh},
19 year = {2026}
20}