wangkevin02 commited on
Commit
e838bd2
·
verified ·
1 Parent(s): 64b4244

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +80 -72
README.md CHANGED
@@ -1,72 +1,80 @@
1
- # AI Detect Model
2
-
3
- ## Model Description
4
-
5
- The **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#).
6
-
7
- 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).
8
-
9
- > *Note*: Our model is subject to the following constraints:
10
- >
11
- > 1. **Maximum Context Length**: Supports up to **4,096 tokens**. Exceeding this may degrade performance; keep inputs within this limit for best results.
12
- > 2. **Language Limitation**: Optimized for English. Non-English performance may vary due to limited training data.
13
-
14
-
15
-
16
- ## Quick Start
17
-
18
- You can utilize our AI detection model as demonstrated below:
19
-
20
- ```python
21
- from transformers import LongformerTokenizer, LongformerForSequenceClassification
22
- import torch
23
- import torch.nn.functional as F
24
-
25
- class AIDetector:
26
- def __init__(self, model_name="allenai/longformer-base-4096", max_length=4096):
27
- """
28
- Initialize the AIDetector with a pretrained Longformer model and tokenizer.
29
-
30
- Args:
31
- model_name (str): The name or path of the pretrained Longformer model.
32
- max_length (int): The maximum sequence length for tokenization.
33
- """
34
- self.tokenizer = LongformerTokenizer.from_pretrained(model_name)
35
- self.model = LongformerForSequenceClassification.from_pretrained(model_name)
36
- self.model.eval()
37
- self.max_length = max_length
38
- self.tokenizer.padding_side = "right"
39
-
40
- @torch.no_grad()
41
- def get_probability(self, texts):
42
- inputs = self.tokenizer(texts, padding=True, truncation=True, max_length=self.max_length, return_tensors='pt')
43
- outputs = self.model(**inputs)
44
- probabilities = F.softmax(outputs.logits, dim=1)
45
- return probabilities
46
-
47
- # Example usage
48
- if __name__ == "__main__":
49
- classifier = AIDetector(model_name="/path/to/ai_detector")
50
- target_text = [
51
- "I am thinking about going away for vacation",
52
- "How can I help you today?"
53
- ]
54
- result = classifier.get_probability(target_text)
55
- print(result)
56
- # >>> Expected Output:
57
- # >>> tensor([[0.9954, 0.0046],
58
- # >>> [0.0265, 0.9735]])
59
- ```
60
-
61
-
62
-
63
- ## Citation
64
-
65
- If you find this model useful, please cite:
66
-
67
- ```plaintext
68
- [Authors], "[Paper Title]," [Venue], [Year], [URL or DOI].
69
- ```
70
-
71
-
72
-
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ datasets:
4
+ - wangkevin02/LMSYS-USP
5
+ language:
6
+ - en
7
+ metrics:
8
+ - accuracy
9
+ base_model:
10
+ - allenai/longformer-base-4096
11
+ ---
12
+ # AI Detect Model
13
+
14
+ ## Model Description
15
+
16
+ The **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#).
17
+
18
+ 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).
19
+
20
+ > *Note*: Our model is subject to the following constraints:
21
+ >
22
+ > 1. **Maximum Context Length**: Supports up to **4,096 tokens**. Exceeding this may degrade performance; keep inputs within this limit for best results.
23
+ > 2. **Language Limitation**: Optimized for English. Non-English performance may vary due to limited training data.
24
+
25
+
26
+
27
+ ## Quick Start
28
+
29
+ You can utilize our AI detection model as demonstrated below:
30
+
31
+ ```python
32
+ from transformers import LongformerTokenizer, LongformerForSequenceClassification
33
+ import torch
34
+ import torch.nn.functional as F
35
+
36
+ class AIDetector:
37
+ def __init__(self, model_name="allenai/longformer-base-4096", max_length=4096):
38
+ """
39
+ Initialize the AIDetector with a pretrained Longformer model and tokenizer.
40
+
41
+ Args:
42
+ model_name (str): The name or path of the pretrained Longformer model.
43
+ max_length (int): The maximum sequence length for tokenization.
44
+ """
45
+ self.tokenizer = LongformerTokenizer.from_pretrained(model_name)
46
+ self.model = LongformerForSequenceClassification.from_pretrained(model_name)
47
+ self.model.eval()
48
+ self.max_length = max_length
49
+ self.tokenizer.padding_side = "right"
50
+
51
+ @torch.no_grad()
52
+ def get_probability(self, texts):
53
+ inputs = self.tokenizer(texts, padding=True, truncation=True, max_length=self.max_length, return_tensors='pt')
54
+ outputs = self.model(**inputs)
55
+ probabilities = F.softmax(outputs.logits, dim=1)
56
+ return probabilities
57
+
58
+ # Example usage
59
+ if __name__ == "__main__":
60
+ classifier = AIDetector(model_name="/path/to/ai_detector")
61
+ target_text = [
62
+ "I am thinking about going away for vacation",
63
+ "How can I help you today?"
64
+ ]
65
+ result = classifier.get_probability(target_text)
66
+ print(result)
67
+ # >>> Expected Output:
68
+ # >>> tensor([[0.9954, 0.0046],
69
+ # >>> [0.0265, 0.9735]])
70
+ ```
71
+
72
+
73
+
74
+ ## Citation
75
+
76
+ If you find this model useful, please cite:
77
+
78
+ ```plaintext
79
+ [Authors], "[Paper Title]," [Venue], [Year], [URL or DOI].
80
+ ```