Instructions to use wangkevin02/AI_Detect_Model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use wangkevin02/AI_Detect_Model with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="wangkevin02/AI_Detect_Model")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("wangkevin02/AI_Detect_Model", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172# AI Detect Model## Model DescriptionThe **AI Detect Model** is a binary classification model designed to determine whether a given text is AI-generated (label=1) or written by a human (label=0). This model plays a crucial role in providing AI detection rewards, helping to prevent reward hacking during Reinforcement Learning with Cycle Consistency (RLCC). For more details, please refer to [our paper](https://tongyi.aliyun.com/qianwen/?sessionId=ea3bbcf36a2346a0a7819b06fcb36a1c#).This model is built upon the [Longformer](https://huggingface.co/allenai/longformer-base-4096) architecture and trained using our proprietary [LMSYS-USP](https://huggingface.co/datasets/wangkevin02/LMSYS-USP) dataset. Specifically, in a dialogue context, texts generated by the assistant are labeled as AI-generated (label=1), while user-generated texts are assigned the opposite label (label=0).> *Note*: Our model is subject to the following constraints:>> 1. **Maximum Context Length**: Supports up to **4,096 tokens**. Exceeding this may degrade performance; keep inputs within this limit for best results.> 2. **Language Limitation**: Optimized for English. Non-English performance may vary due to limited training data.## Quick StartYou can utilize our AI detection model as demonstrated below:```pythonfrom transformers import LongformerTokenizer, LongformerForSequenceClassificationimport torchimport torch.nn.functional as Fclass AIDetector:def __init__(self, model_name="allenai/longformer-base-4096", max_length=4096):"""Initialize the AIDetector with a pretrained Longformer model and tokenizer.Args:model_name (str): The name or path of the pretrained Longformer model.max_length (int): The maximum sequence length for tokenization."""self.tokenizer = LongformerTokenizer.from_pretrained(model_name)self.model = LongformerForSequenceClassification.from_pretrained(model_name)self.model.eval()self.max_length = max_lengthself.tokenizer.padding_side = "right"@torch.no_grad()def get_probability(self, texts):inputs = self.tokenizer(texts, padding=True, truncation=True, max_length=self.max_length, return_tensors='pt')outputs = self.model(**inputs)probabilities = F.softmax(outputs.logits, dim=1)return probabilities# Example usageif __name__ == "__main__":classifier = AIDetector(model_name="/path/to/ai_detector")target_text = ["I am thinking about going away for vacation","How can I help you today?"]result = classifier.get_probability(target_text)print(result)# >>> Expected Output:# >>> tensor([[0.9954, 0.0046],# >>> [0.0265, 0.9735]])```## CitationIf you find this model useful, please cite:```plaintext[Authors], "[Paper Title]," [Venue], [Year], [URL or DOI].```1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980---license: mitdatasets:- wangkevin02/LMSYS-USPlanguage:- enmetrics:- accuracybase_model:- allenai/longformer-base-4096---# AI Detect Model## Model DescriptionThe **AI Detect Model** is a binary classification model designed to determine whether a given text is AI-generated (label=1) or written by a human (label=0). This model plays a crucial role in providing AI detection rewards, helping to prevent reward hacking during Reinforcement Learning with Cycle Consistency (RLCC). For more details, please refer to [our paper](https://tongyi.aliyun.com/qianwen/?sessionId=ea3bbcf36a2346a0a7819b06fcb36a1c#).This model is built upon the [Longformer](https://huggingface.co/allenai/longformer-base-4096) architecture and trained using our proprietary [LMSYS-USP](https://huggingface.co/datasets/wangkevin02/LMSYS-USP) dataset. Specifically, in a dialogue context, texts generated by the assistant are labeled as AI-generated (label=1), while user-generated texts are assigned the opposite label (label=0).> *Note*: Our model is subject to the following constraints:>> 1. **Maximum Context Length**: Supports up to **4,096 tokens**. Exceeding this may degrade performance; keep inputs within this limit for best results.> 2. **Language Limitation**: Optimized for English. Non-English performance may vary due to limited training data.## Quick StartYou can utilize our AI detection model as demonstrated below:```pythonfrom transformers import LongformerTokenizer, LongformerForSequenceClassificationimport torchimport torch.nn.functional as Fclass AIDetector:def __init__(self, model_name="allenai/longformer-base-4096", max_length=4096):"""Initialize the AIDetector with a pretrained Longformer model and tokenizer.Args:model_name (str): The name or path of the pretrained Longformer model.max_length (int): The maximum sequence length for tokenization."""self.tokenizer = LongformerTokenizer.from_pretrained(model_name)self.model = LongformerForSequenceClassification.from_pretrained(model_name)self.model.eval()self.max_length = max_lengthself.tokenizer.padding_side = "right"@torch.no_grad()def get_probability(self, texts):inputs = self.tokenizer(texts, padding=True, truncation=True, max_length=self.max_length, return_tensors='pt')outputs = self.model(**inputs)probabilities = F.softmax(outputs.logits, dim=1)return probabilities# Example usageif __name__ == "__main__":classifier = AIDetector(model_name="/path/to/ai_detector")target_text = ["I am thinking about going away for vacation","How can I help you today?"]result = classifier.get_probability(target_text)print(result)# >>> Expected Output:# >>> tensor([[0.9954, 0.0046],# >>> [0.0265, 0.9735]])```## CitationIf you find this model useful, please cite:```plaintext[Authors], "[Paper Title]," [Venue], [Year], [URL or DOI].```
README.md+80-72