模型简介
模型特点
模型能力
使用案例
🚀 desklib/ai-text-detector-academic-v1.01
这是Desklib开发的一款AI生成文本检测模型,专门针对学术相关数据进行了微调。它能够将英文文本分类为人写文本或AI生成文本。该模型基于microsoft/deberta - v3 - large进行微调,采用基于Transformer的架构,具有较高的准确性。它十分强大,能很好地应对学术场景中的各种对抗攻击。此模型在学术诚信、内容审核以及确保学术写作真实性等应用场景中尤为有用。Desklib提供基于AI的个性化学习和学习辅助工具,该模型是Desklib为学生、教育工作者和大学提供的众多工具之一。
在线试用该模型!:Desklib AI Detector
🚀 快速开始
本模型由Desklib开发,专门针对学术相关数据进行微调,用于将英文文本分类为人写或AI生成。它基于microsoft/deberta - v3 - large微调,采用Transformer架构,准确性高,能应对学术场景中的对抗攻击,在学术诚信、内容审核等方面很有用。
✨ 主要特性
- 针对性微调:专门针对学术相关数据进行微调,适用于学术场景。
- 高精度分类:利用Transformer架构,能准确分类英文文本是人类编写还是AI生成。
- 强大鲁棒性:能很好地处理学术场景中的各种对抗攻击。
- 应用广泛:可用于学术诚信、内容审核以及确保学术写作真实性等。
📦 安装指南
文档未提及具体安装步骤,可参考Hugging Face transformers库的安装方法来使用该模型。
💻 使用示例
基础用法
import torch
import torch.nn as nn
from transformers import AutoTokenizer, AutoConfig, AutoModel, PreTrainedModel
class DesklibAIDetectionModel(PreTrainedModel):
config_class = AutoConfig
def __init__(self, config):
super().__init__(config)
# Initialize the base transformer model.
self.model = AutoModel.from_config(config)
# Define a classifier head.
self.classifier = nn.Linear(config.hidden_size, 1)
# Initialize weights (handled by PreTrainedModel)
self.init_weights()
def forward(self, input_ids, attention_mask=None, labels=None):
# Forward pass through the transformer
outputs = self.model(input_ids, attention_mask=attention_mask)
last_hidden_state = outputs[0]
# Mean pooling
input_mask_expanded = attention_mask.unsqueeze(-1).expand(last_hidden_state.size()).float()
sum_embeddings = torch.sum(last_hidden_state * input_mask_expanded, dim=1)
sum_mask = torch.clamp(input_mask_expanded.sum(dim=1), min=1e-9)
pooled_output = sum_embeddings / sum_mask
# Classifier
logits = self.classifier(pooled_output)
loss = None
if labels is not None:
loss_fct = nn.BCEWithLogitsLoss()
loss = loss_fct(logits.view(-1), labels.float())
output = {"logits": logits}
if loss is not None:
output["loss"] = loss
return output
def predict_single_text(text, model, tokenizer, device, max_len=768, threshold=0.5):
encoded = tokenizer(
text,
padding='max_length',
truncation=True,
max_length=max_len,
return_tensors='pt'
)
input_ids = encoded['input_ids'].to(device)
attention_mask = encoded['attention_mask'].to(device)
model.eval()
with torch.no_grad():
outputs = model(input_ids=input_ids, attention_mask=attention_mask)
logits = outputs["logits"]
probability = torch.sigmoid(logits).item()
label = 1 if probability >= threshold else 0
return probability, label
def main():
# --- Model and Tokenizer Directory ---
model_directory = "desklib/ai-text-detector-academic-v1.01"
# --- Load tokenizer and model ---
tokenizer = AutoTokenizer.from_pretrained(model_directory)
model = DesklibAIDetectionModel.from_pretrained(model_directory)
# --- Set up device ---
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
# --- Example Input text ---
text = "AI detection refers to the process of identifying whether a given piece of content, such as text, images, or audio, has been generated by artificial intelligence. This is achieved using various machine learning techniques, including perplexity analysis, entropy measurements, linguistic pattern recognition, and neural network classifiers trained on human and AI-generated data. Advanced AI detection tools assess writing style, coherence, and statistical properties to determine the likelihood of AI involvement. These tools are widely used in academia, journalism, and content moderation to ensure originality, prevent misinformation, and maintain ethical standards. As AI-generated content becomes increasingly sophisticated, AI detection methods continue to evolve, integrating deep learning models and ensemble techniques for improved accuracy."
# --- Run prediction ---
probability, predicted_label = predict_single_text(text, model, tokenizer, device)
print(f"Probability of being AI generated: {probability:.4f}")
print(f"Predicted label: {'AI Generated' if predicted_label == 1 else 'Not AI Generated'}")
if __name__ == "__main__":
main()
📚 详细文档
模型架构
该模型基于微调后的microsoft/deberta - v3 - large Transformer架构构建,核心组件包括:
- Transformer基础模型:预训练的microsoft/deberta - v3 - large模型作为基础。该模型采用DeBERTa(具有解耦注意力的解码增强BERT),它是BERT和RoBERTa的改进版本,结合了解耦注意力和增强的掩码解码器,以实现更好的性能。
- 均值池化:均值池化层聚合Transformer的隐藏状态,创建输入文本的固定大小表示。此方法对标记嵌入进行平均,由注意力掩码加权,以捕获整体语义含义。
- 分类器头:线性层作为分类器,接受池化后的表示并输出单个对数。该对数表示模型对输入文本是AI生成的置信度。对对数应用Sigmoid激活函数以产生概率。
局限性
- 适用范围有限:该模型针对学术相关数据进行微调,在通用或创意写作文本上可能无法达到最佳性能。可查看我们的标准AI检测器:https://huggingface.co/desklib/ai-text-detector-v1.01
- 对抗攻击应对能力:未针对高级对抗攻击进行微调,但能较好地应对基本的对抗操作。
- 需定期更新:由于AI生成文本检测是一个不断发展的领域,该模型可能需要定期更新以适应新的AI文本生成模型。
🔧 技术细节
该模型基于Transformer架构,利用预训练的microsoft/deberta - v3 - large模型,结合均值池化和线性分类器头进行文本分类。通过解耦注意力和增强的掩码解码器,提高了模型性能。均值池化用于聚合隐藏状态,线性层输出对数,经过Sigmoid激活得到概率。
📄 许可证
本模型采用MIT许可证。
属性 | 详情 |
---|---|
模型类型 | 文本分类模型 |
训练数据 | 学术相关数据 |
⚠️ 重要提示
该模型针对学术相关数据进行微调,在通用或创意写作文本上可能无法达到最佳性能。可查看标准AI检测器:https://huggingface.co/desklib/ai-text-detector-v1.01
💡 使用建议
由于AI生成文本检测领域不断发展,建议定期更新模型以适应新的AI文本生成模型。








