yilunzhang commited on
Commit
f9cdb14
·
verified ·
1 Parent(s): ff9d126

Upload 11 files

Browse files
README.md CHANGED
@@ -1,3 +1,60 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ base_model:
6
+ - FacebookAI/roberta-base
7
+ pipeline_tag: text-classification
8
+ library_name: transformers
9
+ ---
10
+
11
+ # RoBERTa-base AI Text Detector
12
+
13
+ Finetuned RoBERTa-base model for detecting AI generated English texts.
14
+
15
+ See [FakespotAILabs/ApolloDFT](https://github.com/FakespotAILabs/ApolloDFT) for more details and a technical report of the model and experiments we conducted.
16
+
17
+ ## How to use
18
+
19
+ You can use this model directly with a pipeline.
20
+
21
+ For better performance, you should apply the `clean_text` function in [utils.py](utils.py).
22
+
23
+ ```python
24
+ from transformers import pipeline
25
+ from utils import clean_text
26
+
27
+ classifier = pipeline(
28
+ "text-classification",
29
+ model="fakespot-ai/roberta-base-ai-text-detection-v1"
30
+ )
31
+
32
+ # single text
33
+ text = "text 1"
34
+ classifier(clean_text(text))
35
+ [
36
+ {
37
+ 'label': str,
38
+ 'score': float
39
+ }
40
+ ]
41
+
42
+ # list of texts
43
+ texts = ["text 1", "text 2"]
44
+ classifier([clean_text(t) for t in texts])
45
+ [
46
+ {
47
+ 'label': str,
48
+ 'score': float
49
+ },
50
+ {
51
+ 'label': str,
52
+ 'score': float
53
+ }
54
+ ]
55
+ ```
56
+
57
+ ## Disclaimer
58
+
59
+ - The model's score represents an estimation of the likelihood of the input text being AI-generated or human-written, rather than indicating the proportion of the text that is AI-generated or human-written.
60
+ - The accuracy and performance of the model generally improve with longer text inputs.
config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "FacebookAI/roberta-base",
3
+ "architectures": [
4
+ "RobertaForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "classifier_dropout": null,
9
+ "eos_token_id": 2,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout_prob": 0.1,
12
+ "hidden_size": 768,
13
+ "id2label": {
14
+ "0": "Human",
15
+ "1": "AI"
16
+ },
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 3072,
19
+ "label2id": {
20
+ "AI": 1,
21
+ "Human": 0
22
+ },
23
+ "layer_norm_eps": 1e-05,
24
+ "max_position_embeddings": 514,
25
+ "model_type": "roberta",
26
+ "num_attention_heads": 12,
27
+ "num_hidden_layers": 12,
28
+ "pad_token_id": 1,
29
+ "position_embedding_type": "absolute",
30
+ "problem_type": "single_label_classification",
31
+ "torch_dtype": "float32",
32
+ "transformers_version": "4.46.3",
33
+ "type_vocab_size": 1,
34
+ "use_cache": true,
35
+ "vocab_size": 50265
36
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:adc87ded15a8fbea26dec51a747adfd59ad1e9021073287e7e5e29209564e56c
3
+ size 498612824
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e8624aaf898074697c13a698ddcfe404a2b5fa5f275f6412343f2b0f946e4b7d
3
+ size 498669998
special_tokens_map.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "mask_token": {
6
+ "content": "<mask>",
7
+ "lstrip": true,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "pad_token": "<pad>",
13
+ "sep_token": "</s>",
14
+ "unk_token": "<unk>"
15
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "0": {
5
+ "content": "<s>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "1": {
13
+ "content": "<pad>",
14
+ "lstrip": false,
15
+ "normalized": true,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "2": {
21
+ "content": "</s>",
22
+ "lstrip": false,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "3": {
29
+ "content": "<unk>",
30
+ "lstrip": false,
31
+ "normalized": true,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "50264": {
37
+ "content": "<mask>",
38
+ "lstrip": true,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ }
44
+ },
45
+ "bos_token": "<s>",
46
+ "clean_up_tokenization_spaces": false,
47
+ "cls_token": "<s>",
48
+ "eos_token": "</s>",
49
+ "errors": "replace",
50
+ "mask_token": "<mask>",
51
+ "model_max_length": 512,
52
+ "pad_token": "<pad>",
53
+ "sep_token": "</s>",
54
+ "tokenizer_class": "RobertaTokenizer",
55
+ "trim_offsets": true,
56
+ "unk_token": "<unk>"
57
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:22a1d8262404d459ac805c652c9b1c7b4f04481defe45a801fc449884f996ef3
3
+ size 5240
utils.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from html import unescape
3
+
4
+
5
+ def clean_text(t):
6
+ t = clean_markdown(t)
7
+ t = t.replace("\n"," ")
8
+ t = t.replace("\t"," ")
9
+ t = t.replace("^M"," ")
10
+ t = t.replace("\r"," ")
11
+ t = t.replace(" ,", ",")
12
+ t = re.sub(" +", " ", t)
13
+ return t
14
+
15
+ def clean_markdown(md_text):
16
+ # Remove code blocks
17
+ md_text = re.sub(r'```.*?```', '', md_text, flags=re.DOTALL)
18
+ # Remove inline code
19
+ md_text = re.sub(r'`[^`]*`', '', md_text)
20
+ # Remove images
21
+ md_text = re.sub(r'!\[.*?\]\(.*?\)', '', md_text)
22
+ # Remove links but keep link text
23
+ md_text = re.sub(r'\[([^\]]+)\]\(.*?\)', r'\1', md_text)
24
+ # Remove bold and italic (groups of *, _)
25
+ md_text = re.sub(r'(\*\*|__)(.*?)\1', r'\2', md_text)
26
+ md_text = re.sub(r'(\*|_)(.*?)\1', r'\2', md_text)
27
+ # Remove headings
28
+ md_text = re.sub(r'#+ ', '', md_text)
29
+ # Remove blockquotes
30
+ md_text = re.sub(r'^>.*$', '', md_text, flags=re.MULTILINE)
31
+ # Remove list markers
32
+ md_text = re.sub(r'^(\s*[-*+]|\d+\.)\s+', '', md_text, flags=re.MULTILINE)
33
+ # Remove horizontal rules
34
+ md_text = re.sub(r'^\s*[-*_]{3,}\s*$', '', md_text, flags=re.MULTILINE)
35
+ # Remove tables
36
+ md_text = re.sub(r'\|.*?\|', '', md_text)
37
+ # Remove raw HTML tags
38
+ md_text = re.sub(r'<.*?>', '', md_text)
39
+ # Decode HTML entities
40
+ md_text = unescape(md_text)
41
+ return md_text
vocab.json ADDED
The diff for this file is too large to render. See raw diff