模型概述
模型特點
模型能力
使用案例
🚀 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文本生成模型。








