editlens-qwen3-4b-merged
Qwen3-4B fine-tuned with QLoRA on the pangram/editlens_iclr dataset, with the LoRA adapter merged into the base in bf16. Drop-in replacement for the QLoRA path with ~1.5× lower single-request latency on RTX 3090 and no accuracy regression.
Trained for the EditLens task (arXiv:2510.03154): classify text by how much AI editing it has received. Predicts a continuous score in [0, 1] from a 4-bucket softmax (bucket_pred ∈ {0, 1, 2, 3} mapped to score = bucket / 3).
Quick start
The score head is a custom LayerNorm + Linear (NormedLinear) module rather than a bare Linear, so it doesn't auto-load via from_pretrained. Reattach and copy weights manually:
import glob, os, torch
import torch.nn as nn
from safetensors import safe_open
from transformers import AutoModelForSequenceClassification, AutoTokenizer
class NormedLinear(nn.Module):
def __init__(self, hidden_size, num_labels, dtype=torch.bfloat16):
super().__init__()
self.norm = nn.LayerNorm(hidden_size, dtype=dtype)
self.linear = nn.Linear(hidden_size, num_labels, bias=False, dtype=dtype)
def forward(self, x):
return self.linear(self.norm(x))
MODEL = "DarrenJiaImbue/editlens-qwen3-4b-merged"
tok = AutoTokenizer.from_pretrained(MODEL)
if tok.pad_token is None:
tok.pad_token = tok.eos_token
tok.padding_side = "left"
model = AutoModelForSequenceClassification.from_pretrained(MODEL, dtype=torch.bfloat16).to("cuda")
n = model.config.num_labels
model.score = NormedLinear(model.config.hidden_size, n).to("cuda", dtype=torch.bfloat16)
from huggingface_hub import hf_hub_download
sf = hf_hub_download(MODEL, "model.safetensors")
with safe_open(sf, framework="pt") as f:
model.score.norm.weight.data.copy_(f.get_tensor("score.norm.weight"))
model.score.norm.bias.data.copy_(f.get_tensor("score.norm.bias"))
model.score.linear.weight.data.copy_(f.get_tensor("score.linear.weight"))
model.config.pad_token_id = tok.pad_token_id
model.eval()
text = "The original text..."
enc = tok(text, return_tensors="pt", truncation=True, max_length=1024).to("cuda")
with torch.no_grad(), torch.autocast("cuda", dtype=torch.bfloat16):
logits = model(**enc).logits
probs = logits.float().softmax(-1).cpu().numpy()[0]
bucket = int(probs.argmax())
score = float(probs @ [0, 1, 2, 3]) / 3
print(f"bucket={bucket} score={score:.3f}")
Bucket interpretation
| Bucket | Approx cosine distance from source | Meaning |
|---|---|---|
| 0 | ≤ 0.03 | Verbatim human |
| 1 | 0.03–0.07 | Light AI touch-up |
| 2 | 0.07–0.15 | Heavier AI rewrite |
| 3 | ≥ 0.15 | AI-generated |
Test-set accuracy
(threshold calibrated on val.csv, evaluated on test.csv from pangram/editlens_iclr)
| Mode | Accuracy | Macro F1 |
|---|---|---|
| human_vs_ai | 1.000 | 1.000 |
| human_vs_rest | 0.937 | 0.931 |
| ai_vs_rest | 0.975 | 0.972 |
License
CC BY-NC-SA 4.0 (matches the original EditLens release).
Citation
@misc{thai2025editlensquantifyingextentai,
title={EditLens: Quantifying the Extent of AI Editing in Text},
author={Katherine Thai and Bradley Emi and Elyas Masrour and Mohit Iyyer},
year={2025},
eprint={2510.03154},
archivePrefix={arXiv},
primaryClass={cs.CL},
}
- Downloads last month
- 31