jialinyyzz commited on
Commit
4b31fcb
·
verified ·
1 Parent(s): 7c784d9

humanizer-gemma-4-e4b merged bf16 (SFT + 2x DPO on google/gemma-4-E4B)

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
NOTICE ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ The code in this repository is licensed under Apache-2.0.
2
+
3
+ The released model weights are a fine-tune of google/gemma-4-E4B and are provided under and subject to
4
+ the Gemma Terms of Use (https://ai.google.dev/gemma/terms). By downloading or using the weights you agree
5
+ to those terms. Gemma is provided under and subject to the Gemma Terms of Use found at ai.google.dev/gemma/terms.
README.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: gemma
3
+ base_model: google/gemma-4-E4B
4
+ language:
5
+ - en
6
+ - zh
7
+ tags:
8
+ - text-rewriting
9
+ - humanizer
10
+ - paraphrase
11
+ - gemma
12
+ - mlx
13
+ pipeline_tag: text-generation
14
+ library_name: transformers
15
+ ---
16
+
17
+ # humanizer-gemma-4-e4b
18
+
19
+ Rewrites AI-written drafts so they read like a person wrote them, keeping every fact, number, name and date. Fine-tune of `google/gemma-4-E4B`.
20
+
21
+ **Trained on data that teaches the model how people write. No reinforcement learning or optimisation against any AI detector; it passes detectors naturally, and detector numbers below are only an external check.**
22
+
23
+ ## Training
24
+
25
+ * **SFT, 28.6k pairs** of *(AI draft → real human text)*. The human side is always genuine human writing (scientific abstracts, government reports, student essays, email, forum posts, Chinese prose); the AI side is a draft of the same content written by a current frontier model from the human text.
26
+ * **DPO, 2 rounds, 1,898 pairs.** Candidates written by the model itself; a separate LLM judge grades *fidelity only* (facts kept, meaning unchanged, nothing added, greeting/sign-off kept, not a verbatim copy). Chosen = fidelity-clean with the least verbatim overlap; rejected = critical fidelity error or near-copy. No style, length or detector signal enters selection.
27
+ * **Inference guard:** if a sample copies > 35 % of the draft's 5-grams it is resampled once with a logits penalty on draft n-grams (digits exempt).
28
+
29
+ ## Evaluation (39-case daily-use set, 2 samples each)
30
+
31
+ | 62 English samples | this model | baseline 4B rewriter |
32
+ |---|---|---|
33
+ | samples copying > 35 % of draft | 0 | 33 / 93 |
34
+ | critical fidelity errors (judge) | 10 % | ≈ 30 % |
35
+ | Chinese cases passing judge | 10 / 16 | 4 / 16 |
36
+ | Originality.ai "human" *(external check only)* | 79 % | 57 % |
37
+
38
+ Same weights on a Mac (MLX bf16 and MLX 8-bit) reproduce these numbers within judge noise; plain 4-bit quantisation breaks the model (per-layer embeddings), so no 4-bit build is published yet. Details: `docs/QUALITY.md` in the GitHub repo.
39
+
40
+ Known failure modes: ~1 in 10 outputs has a meaning flip (who did what, ordered vs received, a metric renamed); subject lines/greetings occasionally dropped; Chinese weaker than English; short drafts (< 120 words) less reliable. **Proofread numbers, dates and the direction of every claim.**
41
+
42
+ ## Prompt format (must match exactly)
43
+
44
+ Base-model continuation, not chat. `prompt_format.json` in this repo holds the instruction and separator:
45
+
46
+ ```
47
+ {instr}
48
+
49
+ {draft}
50
+
51
+ ### Rewritten:
52
+
53
+ ```
54
+
55
+ Stop at EOS; temperature 0.85, top-p 0.95.
56
+
57
+ ## Usage
58
+
59
+ ```python
60
+ import json, torch
61
+ from transformers import AutoModelForCausalLM, AutoTokenizer
62
+ from huggingface_hub import hf_hub_download
63
+
64
+ repo = "jialinyyzz/humanizer-gemma-4-e4b"
65
+ pf = json.load(open(hf_hub_download(repo, "prompt_format.json")))
66
+ tok = AutoTokenizer.from_pretrained(repo)
67
+ model = AutoModelForCausalLM.from_pretrained(repo, dtype=torch.bfloat16, device_map="cuda")
68
+ draft = open("draft.txt").read()
69
+ prompt = pf["instr"] + "\n\n" + draft.strip() + pf["sep"]
70
+ ids = tok(prompt, return_tensors="pt").to("cuda")
71
+ out = model.generate(**ids, max_new_tokens=900, do_sample=True, temperature=0.85, top_p=0.95)
72
+ print(tok.decode(out[0][ids["input_ids"].shape[1]:], skip_special_tokens=True))
73
+ ```
74
+
75
+ The full inference path with the anti-copy resample, an MLX server, the evaluation set and the training scripts are on GitHub: `sgaofen/humanizer`.
76
+
77
+ ## Licence
78
+
79
+ Weights derive from Gemma 4 and are provided under and subject to the [Gemma Terms of Use](https://ai.google.dev/gemma/terms). Code: Apache-2.0.
config.json ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Gemma4ForConditionalGeneration"
4
+ ],
5
+ "audio_config": {
6
+ "_name_or_path": "",
7
+ "architectures": null,
8
+ "attention_chunk_size": 12,
9
+ "attention_context_left": 13,
10
+ "attention_context_right": 0,
11
+ "attention_invalid_logits_value": -1000000000.0,
12
+ "attention_logit_cap": 50.0,
13
+ "chunk_size_feed_forward": 0,
14
+ "conv_kernel_size": 5,
15
+ "dtype": "bfloat16",
16
+ "gradient_clipping": 10000000000.0,
17
+ "hidden_act": "silu",
18
+ "hidden_size": 1024,
19
+ "id2label": {
20
+ "0": "LABEL_0",
21
+ "1": "LABEL_1"
22
+ },
23
+ "initializer_range": 0.02,
24
+ "is_encoder_decoder": false,
25
+ "label2id": {
26
+ "LABEL_0": 0,
27
+ "LABEL_1": 1
28
+ },
29
+ "model_type": "gemma4_audio",
30
+ "num_attention_heads": 8,
31
+ "num_hidden_layers": 12,
32
+ "output_attentions": false,
33
+ "output_hidden_states": false,
34
+ "output_proj_dims": 1536,
35
+ "problem_type": null,
36
+ "residual_weight": 0.5,
37
+ "return_dict": true,
38
+ "rms_norm_eps": 1e-06,
39
+ "subsampling_conv_channels": [
40
+ 128,
41
+ 32
42
+ ],
43
+ "use_clipped_linears": true
44
+ },
45
+ "audio_token_id": 258881,
46
+ "boa_token_id": 256000,
47
+ "boi_token_id": 255999,
48
+ "dtype": "bfloat16",
49
+ "eoa_token_id": 258883,
50
+ "eoa_token_index": 258883,
51
+ "eoi_token_id": 258882,
52
+ "image_token_id": 258880,
53
+ "initializer_range": 0.02,
54
+ "model_type": "gemma4",
55
+ "text_config": {
56
+ "attention_bias": false,
57
+ "attention_dropout": 0.0,
58
+ "attention_k_eq_v": false,
59
+ "bos_token_id": 2,
60
+ "dtype": "bfloat16",
61
+ "enable_moe_block": false,
62
+ "eos_token_id": 1,
63
+ "expert_intermediate_size": null,
64
+ "final_logit_softcapping": 30.0,
65
+ "global_head_dim": 512,
66
+ "head_dim": 256,
67
+ "hidden_activation": "gelu_pytorch_tanh",
68
+ "hidden_size": 2560,
69
+ "hidden_size_per_layer_input": 256,
70
+ "initializer_range": 0.02,
71
+ "intermediate_size": 10240,
72
+ "layer_types": [
73
+ "sliding_attention",
74
+ "sliding_attention",
75
+ "sliding_attention",
76
+ "sliding_attention",
77
+ "sliding_attention",
78
+ "full_attention",
79
+ "sliding_attention",
80
+ "sliding_attention",
81
+ "sliding_attention",
82
+ "sliding_attention",
83
+ "sliding_attention",
84
+ "full_attention",
85
+ "sliding_attention",
86
+ "sliding_attention",
87
+ "sliding_attention",
88
+ "sliding_attention",
89
+ "sliding_attention",
90
+ "full_attention",
91
+ "sliding_attention",
92
+ "sliding_attention",
93
+ "sliding_attention",
94
+ "sliding_attention",
95
+ "sliding_attention",
96
+ "full_attention",
97
+ "sliding_attention",
98
+ "sliding_attention",
99
+ "sliding_attention",
100
+ "sliding_attention",
101
+ "sliding_attention",
102
+ "full_attention",
103
+ "sliding_attention",
104
+ "sliding_attention",
105
+ "sliding_attention",
106
+ "sliding_attention",
107
+ "sliding_attention",
108
+ "full_attention",
109
+ "sliding_attention",
110
+ "sliding_attention",
111
+ "sliding_attention",
112
+ "sliding_attention",
113
+ "sliding_attention",
114
+ "full_attention"
115
+ ],
116
+ "max_position_embeddings": 131072,
117
+ "model_type": "gemma4_text",
118
+ "num_attention_heads": 8,
119
+ "num_experts": null,
120
+ "num_global_key_value_heads": null,
121
+ "num_hidden_layers": 42,
122
+ "num_key_value_heads": 2,
123
+ "num_kv_shared_layers": 18,
124
+ "pad_token_id": 0,
125
+ "rms_norm_eps": 1e-06,
126
+ "rope_parameters": {
127
+ "full_attention": {
128
+ "partial_rotary_factor": 0.25,
129
+ "rope_theta": 1000000.0,
130
+ "rope_type": "proportional"
131
+ },
132
+ "sliding_attention": {
133
+ "rope_theta": 10000.0,
134
+ "rope_type": "default"
135
+ }
136
+ },
137
+ "sliding_window": 512,
138
+ "tie_word_embeddings": true,
139
+ "top_k_experts": null,
140
+ "use_bidirectional_attention": null,
141
+ "use_cache": true,
142
+ "use_double_wide_mlp": false,
143
+ "vocab_size": 262144,
144
+ "vocab_size_per_layer_input": 262144
145
+ },
146
+ "tie_word_embeddings": true,
147
+ "transformers_version": "5.5.0.dev0",
148
+ "video_token_id": 258884,
149
+ "vision_config": {
150
+ "_name_or_path": "",
151
+ "architectures": null,
152
+ "attention_bias": false,
153
+ "attention_dropout": 0.0,
154
+ "chunk_size_feed_forward": 0,
155
+ "default_output_length": 280,
156
+ "dtype": "bfloat16",
157
+ "global_head_dim": 64,
158
+ "head_dim": 64,
159
+ "hidden_activation": "gelu_pytorch_tanh",
160
+ "hidden_size": 768,
161
+ "id2label": {
162
+ "0": "LABEL_0",
163
+ "1": "LABEL_1"
164
+ },
165
+ "initializer_range": 0.02,
166
+ "intermediate_size": 3072,
167
+ "is_encoder_decoder": false,
168
+ "label2id": {
169
+ "LABEL_0": 0,
170
+ "LABEL_1": 1
171
+ },
172
+ "max_position_embeddings": 131072,
173
+ "model_type": "gemma4_vision",
174
+ "num_attention_heads": 12,
175
+ "num_hidden_layers": 16,
176
+ "num_key_value_heads": 12,
177
+ "output_attentions": false,
178
+ "output_hidden_states": false,
179
+ "patch_size": 16,
180
+ "pooling_kernel_size": 3,
181
+ "position_embedding_size": 10240,
182
+ "problem_type": null,
183
+ "return_dict": true,
184
+ "rms_norm_eps": 1e-06,
185
+ "rope_parameters": {
186
+ "rope_theta": 100.0,
187
+ "rope_type": "default"
188
+ },
189
+ "standardize": false,
190
+ "use_clipped_linears": true
191
+ },
192
+ "vision_soft_tokens_per_image": 280
193
+ }
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 2,
3
+ "do_sample": true,
4
+ "eos_token_id": 1,
5
+ "pad_token_id": 0,
6
+ "temperature": 1.0,
7
+ "top_k": 64,
8
+ "top_p": 0.95,
9
+ "transformers_version": "5.5.0.dev0"
10
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:519f1a0f586ec262ac70c383d8e2671ebfa57541b2fe6ba14d3dfaf260188a8c
3
+ size 15992596739
processor_config.json ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "audio_ms_per_token": 40,
3
+ "audio_seq_length": 750,
4
+ "feature_extractor": {
5
+ "dither": 0.0,
6
+ "feature_extractor_type": "Gemma4AudioFeatureExtractor",
7
+ "feature_size": 128,
8
+ "fft_length": 512,
9
+ "fft_overdrive": false,
10
+ "frame_length": 320,
11
+ "hop_length": 160,
12
+ "input_scale_factor": 1.0,
13
+ "max_frequency": 8000.0,
14
+ "mel_floor": 0.001,
15
+ "min_frequency": 0.0,
16
+ "padding_side": "right",
17
+ "padding_value": 0.0,
18
+ "per_bin_mean": null,
19
+ "per_bin_stddev": null,
20
+ "preemphasis": 0.0,
21
+ "preemphasis_htk_flavor": true,
22
+ "return_attention_mask": true,
23
+ "sampling_rate": 16000
24
+ },
25
+ "image_processor": {
26
+ "do_convert_rgb": true,
27
+ "do_normalize": false,
28
+ "do_rescale": true,
29
+ "do_resize": true,
30
+ "image_mean": [
31
+ 0.0,
32
+ 0.0,
33
+ 0.0
34
+ ],
35
+ "image_processor_type": "Gemma4ImageProcessor",
36
+ "image_seq_length": 280,
37
+ "image_std": [
38
+ 1.0,
39
+ 1.0,
40
+ 1.0
41
+ ],
42
+ "max_soft_tokens": 280,
43
+ "patch_size": 16,
44
+ "pooling_kernel_size": 3,
45
+ "resample": 3,
46
+ "rescale_factor": 0.00392156862745098
47
+ },
48
+ "image_seq_length": 280,
49
+ "processor_class": "Gemma4Processor",
50
+ "video_processor": {
51
+ "do_convert_rgb": true,
52
+ "do_normalize": true,
53
+ "do_rescale": true,
54
+ "do_resize": true,
55
+ "do_sample_frames": true,
56
+ "image_mean": [
57
+ 0.0,
58
+ 0.0,
59
+ 0.0
60
+ ],
61
+ "image_std": [
62
+ 1.0,
63
+ 1.0,
64
+ 1.0
65
+ ],
66
+ "max_soft_tokens": 70,
67
+ "num_frames": 32,
68
+ "patch_size": 16,
69
+ "pooling_kernel_size": 3,
70
+ "resample": 3,
71
+ "rescale_factor": 0.00392156862745098,
72
+ "return_metadata": false,
73
+ "video_processor_type": "Gemma4VideoProcessor"
74
+ }
75
+ }
prompt_format.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "style": "legacy",
3
+ "sep": "\n\n### Rewritten:\n\n",
4
+ "fingerprint": "cc51d66b4c593fbe",
5
+ "instr": "Rewrite the text below so it reads like a person wrote it, not a language model.\n\nReorganize it as you see fit. Vary sentence length on purpose. Cut hedging,\nthroat-clearing, and any sentence that only announces what comes next.\nPrefer the concrete word over the abstract one. It is fine to sound uneven.\n\nEvery fact, number, unit, date, name and quotation must survive unchanged.",
6
+ "note": "推理时需 instr + draft + sep"
7
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:12bac982b793c44b03d52a250a9f0d0b666813da566b910c24a6da0695fd11e6
3
+ size 32170070
tokenizer_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "audio_token": "<|audio|>",
3
+ "backend": "tokenizers",
4
+ "boa_token": "<|audio>",
5
+ "boi_token": "<|image>",
6
+ "bos_token": "<bos>",
7
+ "eoa_token": "<audio|>",
8
+ "eoc_token": "<channel|>",
9
+ "eoi_token": "<image|>",
10
+ "eos_token": "<eos>",
11
+ "eot_token": "<turn|>",
12
+ "escape_token": "<|\"|>",
13
+ "etc_token": "<tool_call|>",
14
+ "etd_token": "<tool|>",
15
+ "etr_token": "<tool_response|>",
16
+ "extra_special_tokens": [
17
+ "<|video|>"
18
+ ],
19
+ "image_token": "<|image|>",
20
+ "mask_token": "<mask>",
21
+ "model_max_length": 1000000000000000019884624838656,
22
+ "pad_token": "<pad>",
23
+ "padding_side": "left",
24
+ "processor_class": "Gemma4Processor",
25
+ "soc_token": "<|channel>",
26
+ "sot_token": "<|turn>",
27
+ "stc_token": "<|tool_call>",
28
+ "std_token": "<|tool>",
29
+ "str_token": "<|tool_response>",
30
+ "think_token": "<|think|>",
31
+ "tokenizer_class": "GemmaTokenizer",
32
+ "unk_token": "<unk>"
33
+ }