---
title: ai-text-detector-distilbert-lora
canonical_url: "https://www.modelscope.cn/models/AI-ModelScope/ai-text-detector-distilbert-lora"
md_url: "https://www.modelscope.cn/models/AI-ModelScope/ai-text-detector-distilbert-lora.md"
repository: AI-ModelScope/ai-text-detector-distilbert-lora
last_updated: 2026-08-12
license: apache-2.0
pipeline_tag: text-classification
tasks:
  - text-classification
base_model:
  - distilbert/distilbert-base-uncased
base_model_relation: adapter
parameters: 739586
tensor_type:
  - F32
library_name:
  - pytorch
  - transformer
  - lora
  - peft
  - safetensors
frameworks:
  - pytorch
language:
  - en
downloads: 16
stars: 0
tags:
  - ai-text-detection
  - binary-classification
  - lora
  - peft
---

# ai-text-detector-distilbert-lora

> ai-text-detector-distilbert-lora - AI-ModelScope 在 ModelScope 开源的模型。LoRA-Tuned DistilBERT AI-Text Detector

AI-ModelScope/ai-text-detector-distilbert-lora 是 ModelScope 魔搭社区上的 739586 参数text-classification模型，采用 apache-2.0 许可，基于 distilbert/distilbert-base-uncased 构建。

- **Repository**: AI-ModelScope/ai-text-detector-distilbert-lora
- **License**: apache-2.0
- **Tasks**: text-classification
- **Parameters**: 739586
- **Base model**: distilbert/distilbert-base-uncased
- **Tags**: ai-text-detection, binary-classification, lora, peft
- **Downloads**: 16
- **Stars**: 0
- **Last updated**: 2026-08-12

Source: https://www.modelscope.cn/models/AI-ModelScope/ai-text-detector-distilbert-lora

---

# LoRA-Tuned DistilBERT AI-Text Detector

This repository contains a LoRA adapter for classifying human-written and AI-generated text with DistilBERT. It was trained on [`rasbt/human-vs-ai-50k`](https://huggingface.co/datasets/rasbt/human-vs-ai-50k). Human-written text has label 0 and AI-generated text has label 1.

The adapter uses rank 8 and targets the query and value projection layers. It uses a maximum sequence length of 512 tokens and temperature scaling during inference. The recorded best validation accuracy was 99.65%.

&nbsp;
## Download and use

```bash
hf download rasbt/ai-text-detector-distilbert-lora \
  --local-dir models/ai-text-detector-distilbert-lora
```

```python
import json
from pathlib import Path

import torch
from peft import AutoPeftModelForSequenceClassification
from transformers import AutoTokenizer


model_dir = Path("models/ai-text-detector-distilbert-lora")
metadata = json.loads(
    (model_dir / "detector-config.json").read_text(encoding="utf-8")
)
tokenizer = AutoTokenizer.from_pretrained(model_dir)
model = AutoPeftModelForSequenceClassification.from_pretrained(model_dir)
model.eval()

text = "Paste the text to classify here."
inputs = tokenizer(
    text,
    truncation=True,
    max_length=metadata["max_length"],
    return_tensors="pt",
)

with torch.inference_mode():
    logits = model(**inputs).logits / metadata["temperature"]
    probabilities = logits.float().softmax(dim=-1)

ai_index = metadata["label_mapping"]["ai"]
ai_probability = probabilities[0, ai_index].item()
print({"score": round(100 * ai_probability, 4)})
```

&nbsp;
## Test-set confusion matrix

![LoRA-tuned DistilBERT test-set confusion matrix](figures/confusion-matrix.svg)

`detector-config.json` contains the adapter, calibration, and training metadata. The recommended inference implementation is provided in the [`rasbt/ai-detector`](https://github.com/rasbt/ai-detector) repository.

&nbsp;
## Related models

- [TF-IDF logistic regression](https://huggingface.co/rasbt/ai-text-detector-logreg)
- [DistilBERT](https://huggingface.co/rasbt/ai-text-detector-distilbert)
- [DistilBERT with MiCA](https://huggingface.co/rasbt/ai-text-detector-distilbert-mica)
- [ModernBERT](https://huggingface.co/rasbt/ai-text-detector-modernbert)
- [GPT-2 with a fixed-position readout](https://huggingface.co/rasbt/ai-text-detector-gpt2-fixed)
- [GPT-2 with a variable-position readout](https://huggingface.co/rasbt/ai-text-detector-gpt2-variable)
- [Qwen3 0.6B with a fixed-position readout](https://huggingface.co/rasbt/ai-text-detector-qwen3-0.6b-fixed)
- [Qwen3 0.6B with a variable-position readout](https://huggingface.co/rasbt/ai-text-detector-qwen3-0.6b-variable)

&nbsp;
## Limitations

Performance may change for text from generators, domains, languages, and editing workflows not represented in the training set. Short or partly AI-assisted text may also be harder to classify. The score should not be treated as definitive evidence that a person did or did not write a text.
