194 lines
5.8 KiB
Markdown
194 lines
5.8 KiB
Markdown
|
|
---
|
|||
|
|
language:
|
|||
|
|
- en
|
|||
|
|
license: apache-2.0
|
|||
|
|
base_model: Qwen/Qwen2.5-3B-Instruct
|
|||
|
|
tags:
|
|||
|
|
- text-generation
|
|||
|
|
- humanizer
|
|||
|
|
- rewriter
|
|||
|
|
- qwen2.5
|
|||
|
|
- qlora
|
|||
|
|
- merged
|
|||
|
|
- conversational
|
|||
|
|
pipeline_tag: text-generation
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
# Qwen2.5-3B AI Text Humanizer (Merged)
|
|||
|
|
|
|||
|
|
A fine-tuned version of **Qwen/Qwen2.5-3B-Instruct** that rewrites AI-generated text to sound natural and human-written. This is the **fully merged** model — the LoRA adapter weights have been baked directly into the base model, making it compatible with fast inference engines like **vLLM**.
|
|||
|
|
|
|||
|
|
> ⚠️ This is a **private model**. You need a HuggingFace token with read access to load it.
|
|||
|
|
|
|||
|
|
## Model Details
|
|||
|
|
|
|||
|
|
| Property | Value |
|
|||
|
|
|---|---|
|
|||
|
|
| Base model | `Qwen/Qwen2.5-3B-Instruct` |
|
|||
|
|
| Fine-tuning method | QLoRA (r=64, α=128) |
|
|||
|
|
| Training dataset | `qwertyuiopasdfg/English_humanize` (20k rows) |
|
|||
|
|
| Adapter repo | `arshaan-nazir/qwen2.5-3b-humanizer-qlora` |
|
|||
|
|
| Model type | Causal LM — merged weights |
|
|||
|
|
| Language | English |
|
|||
|
|
| License | Apache 2.0 |
|
|||
|
|
|
|||
|
|
## What It Does
|
|||
|
|
|
|||
|
|
Takes AI-generated text as input and rewrites it to:
|
|||
|
|
- Sound natural and conversational
|
|||
|
|
- Use contractions where appropriate
|
|||
|
|
- Vary sentence length and structure
|
|||
|
|
- Avoid stiff, formal phrasing
|
|||
|
|
- Preserve all original facts
|
|||
|
|
|
|||
|
|
## How to Use
|
|||
|
|
|
|||
|
|
### With Transformers
|
|||
|
|
|
|||
|
|
```python
|
|||
|
|
import torch
|
|||
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|||
|
|
|
|||
|
|
HF_TOKEN = "hf_YOUR_TOKEN_HERE" # needs read access to this repo
|
|||
|
|
|
|||
|
|
print("Loading tokenizer...")
|
|||
|
|
tokenizer = AutoTokenizer.from_pretrained(
|
|||
|
|
"arshaan-nazir/qwen2.5-3b-humanizer-merged",
|
|||
|
|
token=HF_TOKEN,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
print("Loading model...")
|
|||
|
|
model = AutoModelForCausalLM.from_pretrained(
|
|||
|
|
"arshaan-nazir/qwen2.5-3b-humanizer-merged",
|
|||
|
|
torch_dtype=torch.bfloat16,
|
|||
|
|
device_map="auto",
|
|||
|
|
token=HF_TOKEN,
|
|||
|
|
)
|
|||
|
|
model.eval()
|
|||
|
|
|
|||
|
|
SYSTEM = """You are a helpful editor.
|
|||
|
|
|
|||
|
|
Rewrite the input so it sounds natural, clear, and conversational while preserving every fact.
|
|||
|
|
Rules:
|
|||
|
|
- Vary sentence length and structure (mix short and long).
|
|||
|
|
- Use contractions where natural.
|
|||
|
|
- Avoid stiff/overly formal phrases.
|
|||
|
|
- No bullet points, headings, or numbered lists.
|
|||
|
|
- Keep paragraphs reasonable (no more than 5 sentences per paragraph).
|
|||
|
|
- Output ONLY the rewritten text (no preamble, no labels).
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
def humanize(text):
|
|||
|
|
msgs = [
|
|||
|
|
{"role": "system", "content": SYSTEM},
|
|||
|
|
{"role": "user", "content": f"Rewrite the following so it sounds fully human-written.\n\nTEXT:\n{text}\n\nREWRITE:"}
|
|||
|
|
]
|
|||
|
|
prompt = tokenizer.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
|
|||
|
|
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(model.device)
|
|||
|
|
|
|||
|
|
with torch.no_grad():
|
|||
|
|
output = model.generate(
|
|||
|
|
input_ids,
|
|||
|
|
max_new_tokens=512,
|
|||
|
|
do_sample=True,
|
|||
|
|
temperature=0.75,
|
|||
|
|
top_p=0.92,
|
|||
|
|
repetition_penalty=1.08,
|
|||
|
|
eos_token_id=tokenizer.eos_token_id,
|
|||
|
|
pad_token_id=tokenizer.eos_token_id,
|
|||
|
|
)
|
|||
|
|
return tokenizer.decode(output[0, input_ids.shape[1]:], skip_special_tokens=True)
|
|||
|
|
|
|||
|
|
text = "The utilization of artificial intelligence has resulted in significant advancements."
|
|||
|
|
print(humanize(text))
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### With vLLM (recommended — fastest)
|
|||
|
|
|
|||
|
|
```python
|
|||
|
|
from vllm import LLM, SamplingParams
|
|||
|
|
from transformers import AutoTokenizer
|
|||
|
|
|
|||
|
|
HF_TOKEN = "hf_YOUR_TOKEN_HERE"
|
|||
|
|
|
|||
|
|
tokenizer = AutoTokenizer.from_pretrained(
|
|||
|
|
"arshaan-nazir/qwen2.5-3b-humanizer-merged",
|
|||
|
|
token=HF_TOKEN,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
llm = LLM(
|
|||
|
|
model="arshaan-nazir/qwen2.5-3b-humanizer-merged",
|
|||
|
|
dtype="bfloat16",
|
|||
|
|
gpu_memory_utilization=0.90,
|
|||
|
|
max_model_len=4096,
|
|||
|
|
enforce_eager=True,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
sampling_params = SamplingParams(
|
|||
|
|
temperature=0.75,
|
|||
|
|
top_p=0.92,
|
|||
|
|
repetition_penalty=1.08,
|
|||
|
|
max_tokens=1024,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
SYSTEM = """You are a helpful editor.
|
|||
|
|
|
|||
|
|
Rewrite the input so it sounds natural, clear, and conversational while preserving every fact.
|
|||
|
|
Rules:
|
|||
|
|
- Vary sentence length and structure (mix short and long).
|
|||
|
|
- Use contractions where natural.
|
|||
|
|
- Avoid stiff/overly formal phrases.
|
|||
|
|
- No bullet points, headings, or numbered lists.
|
|||
|
|
- Keep paragraphs reasonable (no more than 5 sentences per paragraph).
|
|||
|
|
- Output ONLY the rewritten text (no preamble, no labels).
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
text = "Your AI-generated text here..."
|
|||
|
|
|
|||
|
|
msgs = [
|
|||
|
|
{"role": "system", "content": SYSTEM},
|
|||
|
|
{"role": "user", "content": f"Rewrite the following so it sounds fully human-written.\n\nTEXT:\n{text}\n\nREWRITE:"}
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
prompt = tokenizer.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
|
|||
|
|
outputs = llm.generate([prompt], sampling_params)
|
|||
|
|
print(outputs[0].outputs[0].text.strip())
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## Recommended Inference Settings
|
|||
|
|
|
|||
|
|
| Parameter | Value |
|
|||
|
|
|---|---|
|
|||
|
|
| `temperature` | 0.75 |
|
|||
|
|
| `top_p` | 0.92 |
|
|||
|
|
| `repetition_penalty` | 1.08 |
|
|||
|
|
| `max_new_tokens` | 512–1024 |
|
|||
|
|
|
|||
|
|
## Training Details
|
|||
|
|
|
|||
|
|
- **Base model:** `Qwen/Qwen2.5-3B-Instruct`
|
|||
|
|
- **Method:** QLoRA with 4-bit NF4 quantization during training
|
|||
|
|
- **LoRA rank:** 64, alpha: 128
|
|||
|
|
- **Target modules:** `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj`
|
|||
|
|
- **Dataset:** `qwertyuiopasdfg/English_humanize` — 20k (input, output) pairs of AI-generated vs human-written text
|
|||
|
|
- **Epochs:** 3
|
|||
|
|
- **Optimizer:** paged_adamw_8bit
|
|||
|
|
- **Learning rate:** 2e-4 with cosine schedule
|
|||
|
|
|
|||
|
|
## Difference from Adapter Repo
|
|||
|
|
|
|||
|
|
| | [`qwen2.5-3b-humanizer-qlora`](https://huggingface.co/arshaan-nazir/qwen2.5-3b-humanizer-qlora) | This repo |
|
|||
|
|
|---|---|---|
|
|||
|
|
| Type | LoRA adapter only | Fully merged model |
|
|||
|
|
| Requires base model | ✅ Yes | ❌ No |
|
|||
|
|
| vLLM compatible | ❌ No | ✅ Yes |
|
|||
|
|
| Size | ~120 MB | ~6 GB |
|
|||
|
|
| Load time | Slower (loads base + adapter) | Faster (single model) |
|
|||
|
|
|
|||
|
|
## Live Demo
|
|||
|
|
|
|||
|
|
Try it at: [arshaan-nazir/ai-text-humanizer](https://huggingface.co/spaces/arshaan-nazir/ai-text-humanizer-1771785713)
|
|||
|
|
|
|||
|
|
## Developer
|
|||
|
|
|
|||
|
|
**arshaan-nazir** — [HuggingFace Profile](https://huggingface.co/arshaan-nazir)
|