XiangJinYu commited on
Commit
ee1ebb7
·
verified ·
1 Parent(s): 1b800a6

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +106 -0
README.md ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - zh
4
+ license: apache-2.0
5
+ base_model: unsloth/Qwen3.5-9B
6
+ tags:
7
+ - lora
8
+ - peft
9
+ - dpo
10
+ - text-generation
11
+ - chinese
12
+ - humanization
13
+ - academic-writing
14
+ pipeline_tag: text-generation
15
+ ---
16
+
17
+ # Qwen3.5-9B Humanize DPO v20
18
+
19
+ LoRA adapter fine-tuned with **DPO** on Qwen3.5-9B for Chinese text humanization. This is the **latest and most capable version**, especially strong on academic and technical Chinese text. It uses v18-75 model outputs as rejected samples, teaching the model to correct its own remaining weaknesses.
20
+
21
+ ## Model Details
22
+
23
+ | Item | Value |
24
+ |---|---|
25
+ | Base model | `unsloth/Qwen3.5-9B` |
26
+ | Starting point | DPO v18, checkpoint-75 |
27
+ | Fine-tuning method | DPO |
28
+ | LoRA rank | 16 |
29
+ | Training data | 2000 pairs (chosen = CSL human text, rejected = v18-75 model outputs) |
30
+ | Training steps | 250 steps (2 epochs) |
31
+ | Final loss | 0.34 |
32
+ | Final margin | ~1.5–2.5 |
33
+ | Final accuracy | ~93–100% |
34
+
35
+ ## What It Does
36
+
37
+ The most natural-sounding version in the series, particularly on academic and technical texts:
38
+
39
+ - **Academic papers**: rewrites while preserving all numbers, model names, formulas, and technical terms — verified on 10 academic scenarios with 3 samples each
40
+ - **Technical reports**: maintains technical register without sounding robotic
41
+ - **Daily text**: more concise and natural than previous versions
42
+
43
+ ## Usage
44
+
45
+ ```python
46
+ from unsloth import FastLanguageModel
47
+ from peft import PeftModel
48
+
49
+ base_model, proc = FastLanguageModel.from_pretrained(
50
+ "unsloth/Qwen3.5-9B", max_seq_length=2048, load_in_4bit=False,
51
+ )
52
+ tokenizer = proc.tokenizer if hasattr(proc, "tokenizer") else proc
53
+
54
+ model = PeftModel.from_pretrained(
55
+ base_model, "XiangJinYu/Qwen3.5-9B-Humanize-DPO-v20", is_trainable=False,
56
+ )
57
+ if hasattr(model, "config") and getattr(model.config, "model_type", "") == "qwen3_5":
58
+ model.config.model_type = "qwen3"
59
+ FastLanguageModel.for_inference(model)
60
+
61
+ instruction = "请将下面文本改写得更像自然人写作,保持原意与事实,不要加标题或说明。"
62
+ text = "本文提出了一种基于U-Net改进的医学影像分割方法,Dice系数达到0.923,较基线方法提升了4.7个百分点,推理速度提升约30%。"
63
+ messages = [{"role": "user", "content": [{"type": "text", "text": f"{instruction}\n\n原文:{text}"}]}]
64
+ prompt = tokenizer.apply_chat_template(
65
+ messages, tokenize=False, add_generation_prompt=True, enable_thinking=False
66
+ )
67
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
68
+ # Recommended: temperature=0.6-0.65 for academic texts to avoid rare term substitution errors
69
+ outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.65,
70
+ top_p=0.9, do_sample=True, repetition_penalty=1.1)
71
+ gen = outputs[0][inputs["input_ids"].shape[1]:]
72
+ print(tokenizer.decode(gen, skip_special_tokens=True))
73
+ ```
74
+
75
+ ## Training Details
76
+
77
+ - **DPO data**: 2000 pairs — chosen = CSL human academic text, rejected = v18-75 model outputs (pure self-play, no casual mixing)
78
+ - **Reference model**: v18 checkpoint-75 (same as starting point)
79
+ - **β**: 0.2, lr=5e-7 (half of v19), 2 epochs (250 steps)
80
+ - **Key design choices**:
81
+ - Lower LR (5e-7 vs 1e-6 in v19) for more stable convergence
82
+ - Pure self-play rejected (no casual text mixing) eliminates gradient variance from mixed data types
83
+ - Rejected reward stayed negative and decreasing throughout all 250 steps — no training instability
84
+
85
+ ## Academic Test Results
86
+
87
+ Tested on 10 academic scenarios (3 samples each), all key numbers preserved:
88
+
89
+ | Scenario | Numbers verified |
90
+ |---|---|
91
+ | NLP paper abstract | BLEU +3.2%, complexity -15% ✅ |
92
+ | Medical image segmentation | Dice 0.923, +4.7%, speed +30% ✅ |
93
+ | Graph neural network | O(n log n), F1 +2.8%, time -40% ✅ |
94
+ | SPWM inverter | 83.9%, 81.9%, 6~18V, IEC 61000-4-2 ✅ |
95
+ | Embedded system test | ±0.5LSB, 8ms, 28mW, 0.6mW ✅ |
96
+
97
+ > **Note**: Use temperature 0.60–0.65 for academic texts. Higher temperatures occasionally cause rare technical term substitutions.
98
+
99
+ ## Model Series
100
+
101
+ | Model | Type | Recommended for |
102
+ |---|---|---|
103
+ | [SFT v15](https://huggingface.co/XiangJinYu/Qwen3.5-9B-Humanize-SFT-v15) | SFT | Foundation |
104
+ | [v16](https://huggingface.co/XiangJinYu/Qwen3.5-9B-Humanize-DPO-v16) | DPO | General use, balanced |
105
+ | [v18](https://huggingface.co/XiangJinYu/Qwen3.5-9B-Humanize-DPO-v18) | DPO | Stable clean baseline |
106
+ | **This model** | DPO | ✅ Academic/technical, latest |