SA-Yur-or commited on
Commit
74b2b85
1 Parent(s): 507dc96

[doc]: update examples of usage the model

Browse files
Files changed (1) hide show
  1. README.md +34 -8
README.md CHANGED
@@ -73,10 +73,13 @@ We are pleased to achieve the following state of model calibration and high accc
73
 
74
  **Pre-requirements**: \
75
  Install *generated_text_detector* \
76
- Run following command: ```pip install git+https://github.com/superannotateai/generated_text_detector.git@v1.0.0```
 
 
77
 
78
  ```python
79
  from generated_text_detector.utils.model.roberta_classifier import RobertaClassifier
 
80
  from transformers import AutoTokenizer
81
  import torch.nn.functional as F
82
 
@@ -84,16 +87,20 @@ import torch.nn.functional as F
84
  model = RobertaClassifier.from_pretrained("SuperAnnotate/ai-detector")
85
  tokenizer = AutoTokenizer.from_pretrained("SuperAnnotate/ai-detector")
86
 
 
 
87
  text_example = "It's not uncommon for people to develop allergies or intolerances to certain foods as they get older. It's possible that you have always had a sensitivity to lactose (the sugar found in milk and other dairy products), but it only recently became a problem for you. This can happen because our bodies can change over time and become more or less able to tolerate certain things. It's also possible that you have developed an allergy or intolerance to something else that is causing your symptoms, such as a food additive or preservative. In any case, it's important to talk to a doctor if you are experiencing new allergy or intolerance symptoms, so they can help determine the cause and recommend treatment."
88
 
 
 
89
  tokens = tokenizer.encode_plus(
90
- text_example,
91
- add_special_tokens=True,
92
- max_length=512,
93
- padding='longest',
94
- truncation=True,
95
- return_token_type_ids=True,
96
- return_tensors="pt"
97
  )
98
 
99
  _, logits = model(**tokens)
@@ -103,6 +110,25 @@ proba = F.sigmoid(logits).squeeze(1).item()
103
  print(proba)
104
  ```
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  ## Training Detailes
107
 
108
  A custom architecture was chosen for its ability to perform binary classification while providing a single model output, as well as for its customizable settings for smoothing integrated into the loss function.
 
73
 
74
  **Pre-requirements**: \
75
  Install *generated_text_detector* \
76
+ Run following command: ```pip install git+https://github.com/superannotateai/generated_text_detector.git@v1.1.0```
77
+
78
+ ### Native Usage
79
 
80
  ```python
81
  from generated_text_detector.utils.model.roberta_classifier import RobertaClassifier
82
+ from generated_text_detector.utils.preprocessing import preprocessing_text
83
  from transformers import AutoTokenizer
84
  import torch.nn.functional as F
85
 
 
87
  model = RobertaClassifier.from_pretrained("SuperAnnotate/ai-detector")
88
  tokenizer = AutoTokenizer.from_pretrained("SuperAnnotate/ai-detector")
89
 
90
+ model.eval()
91
+
92
  text_example = "It's not uncommon for people to develop allergies or intolerances to certain foods as they get older. It's possible that you have always had a sensitivity to lactose (the sugar found in milk and other dairy products), but it only recently became a problem for you. This can happen because our bodies can change over time and become more or less able to tolerate certain things. It's also possible that you have developed an allergy or intolerance to something else that is causing your symptoms, such as a food additive or preservative. In any case, it's important to talk to a doctor if you are experiencing new allergy or intolerance symptoms, so they can help determine the cause and recommend treatment."
93
 
94
+ text_example = preprocessing_text(text_example)
95
+
96
  tokens = tokenizer.encode_plus(
97
+ text_example,
98
+ add_special_tokens=True,
99
+ max_length=512,
100
+ padding='longest',
101
+ truncation=True,
102
+ return_token_type_ids=True,
103
+ return_tensors="pt"
104
  )
105
 
106
  _, logits = model(**tokens)
 
110
  print(proba)
111
  ```
112
 
113
+ ### Usage in Detector Wrapper
114
+
115
+ ```python
116
+ from generated_text_detector.utils.text_detector import GeneratedTextDetector
117
+
118
+
119
+ detector = GeneratedTextDetector(
120
+ "SuperAnnotate/ai-detector",
121
+ device="cuda",
122
+ preprocessing=True
123
+ )
124
+
125
+ text_example = "It's not uncommon for people to develop allergies or intolerances to certain foods as they get older. It's possible that you have always had a sensitivity to lactose (the sugar found in milk and other dairy products), but it only recently became a problem for you. This can happen because our bodies can change over time and become more or less able to tolerate certain things. It's also possible that you have developed an allergy or intolerance to something else that is causing your symptoms, such as a food additive or preservative. In any case, it's important to talk to a doctor if you are experiencing new allergy or intolerance symptoms, so they can help determine the cause and recommend treatment."
126
+
127
+ res = detector.detect_report(text_example)
128
+
129
+ print(res)
130
+ ```
131
+
132
  ## Training Detailes
133
 
134
  A custom architecture was chosen for its ability to perform binary classification while providing a single model output, as well as for its customizable settings for smoothing integrated into the loss function.