Views
No views yet
bucket_pred ∈ {0, 1, 2, 3} mapped to score = bucket / 3).LayerNorm + Linear (NormedLinear) module rather than a bare Linear, so it doesn't auto-load via from_pretrained. Reattach and copy weights manually:1import glob, os, torch
2import torch.nn as nn
3from safetensors import safe_open
4from transformers import AutoModelForSequenceClassification, AutoTokenizer
5
6class NormedLinear(nn.Module):
7 def __init__(self, hidden_size, num_labels, dtype=torch.bfloat16):
8 super().__init__()
9 self.norm = nn.LayerNorm(hidden_size, dtype=dtype)
10 self.linear = nn.Linear(hidden_size, num_labels, bias=False, dtype=dtype)
11 def forward(self, x):
12 return self.linear(self.norm(x))
13
14MODEL = "DarrenJiaImbue/editlens-qwen3-4b-merged"
15tok = AutoTokenizer.from_pretrained(MODEL)
16if tok.pad_token is None:
17 tok.pad_token = tok.eos_token
18 tok.padding_side = "left"
19
20model = AutoModelForSequenceClassification.from_pretrained(MODEL, dtype=torch.bfloat16).to("cuda")
21n = model.config.num_labels
22model.score = NormedLinear(model.config.hidden_size, n).to("cuda", dtype=torch.bfloat16)
23
24from huggingface_hub import hf_hub_download
25sf = hf_hub_download(MODEL, "model.safetensors")
26with safe_open(sf, framework="pt") as f:
27 model.score.norm.weight.data.copy_(f.get_tensor("score.norm.weight"))
28 model.score.norm.bias.data.copy_(f.get_tensor("score.norm.bias"))
29 model.score.linear.weight.data.copy_(f.get_tensor("score.linear.weight"))
30model.config.pad_token_id = tok.pad_token_id
31model.eval()
32
33text = "The original text..."
34enc = tok(text, return_tensors="pt", truncation=True, max_length=1024).to("cuda")
35with torch.no_grad(), torch.autocast("cuda", dtype=torch.bfloat16):
36 logits = model(**enc).logits
37probs = logits.float().softmax(-1).cpu().numpy()[0]
38bucket = int(probs.argmax())
39score = float(probs @ [0, 1, 2, 3]) / 3
40print(f"bucket={bucket} score={score:.3f}")| 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 |
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 |
1@misc{thai2025editlensquantifyingextentai,
2 title={EditLens: Quantifying the Extent of AI Editing in Text},
3 author={Katherine Thai and Bradley Emi and Elyas Masrour and Mohit Iyyer},
4 year={2025},
5 eprint={2510.03154},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8}