Abuzaid01 commited on
Commit
37ea438
·
verified ·
1 Parent(s): 372f20f

Upload AI vs Human Text Detector model

Browse files
README.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ library: pytorch
5
+ datasets:
6
+ - custom
7
+ tags:
8
+ - text-classification
9
+ - ai-text-detection
10
+ - roberta
11
+ widget:
12
+ - text: "The impact of artificial intelligence on modern society has been profound and far-reaching, transforming industries and reshaping how we live and work."
13
+ - text: "The quantum mechanics principle demonstrates that particles can exist in multiple states simultaneously until observed, a phenomenon known as superposition."
14
+ ---
15
+
16
+ # AI vs Human Text Detector
17
+
18
+ This model can detect whether a text was written by a human or generated by AI.
19
+
20
+ ## Model description
21
+
22
+ This AI text detector is built by fine-tuning RoBERTa-base on a dataset containing both human-written and AI-generated text samples.
23
+ The model has been trained with data augmentation techniques to improve its robustness.
24
+
25
+ ## Performance
26
+
27
+ The model achieves the following performance on the validation set:
28
+ - Accuracy: 0.9999
29
+ - F1-Score (Human): 1.0000
30
+ - F1-Score (AI): 0.9999
31
+
32
+ ## How to use
33
+
34
+ ```python
35
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
36
+ import torch
37
+
38
+ # Load model and tokenizer
39
+ model_name = "Abuzaid01/Ai_Human_Text_Detector"
40
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
41
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
42
+
43
+ # Prepare text for classification
44
+ text = "Your text to classify goes here."
45
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512, padding=True)
46
+
47
+ # Run inference
48
+ with torch.no_grad():
49
+ outputs = model(**inputs)
50
+ logits = outputs.logits
51
+
52
+ # Get the predicted class and probabilities
53
+ probabilities = torch.nn.functional.softmax(logits, dim=1)
54
+ predicted_class_idx = torch.argmax(probabilities, dim=1).item()
55
+ confidence = probabilities[0][predicted_class_idx].item()
56
+
57
+ # Map class index to label
58
+ labels = ["Human-written", "AI-generated"]
59
+ predicted_label = labels[predicted_class_idx]
60
+
61
+ print(f"Prediction: {predicted_label}")
62
+ print(f"Confidence: {confidence:.4f}")
63
+ ```
config.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "RobertaForSequenceClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "bos_token_id": 0,
7
+ "classifier_dropout": null,
8
+ "eos_token_id": 2,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-05,
15
+ "max_position_embeddings": 514,
16
+ "model_type": "roberta",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 1,
20
+ "position_embedding_type": "absolute",
21
+ "problem_type": "single_label_classification",
22
+ "torch_dtype": "float32",
23
+ "transformers_version": "4.51.1",
24
+ "type_vocab_size": 1,
25
+ "use_cache": true,
26
+ "vocab_size": 50265
27
+ }
inference.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+
5
+ def classify_text(text, model_path=None):
6
+ # Load model and tokenizer
7
+ model_path = model_path or "."
8
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
9
+ model = AutoModelForSequenceClassification.from_pretrained(model_path)
10
+
11
+ # Prepare the text for the model
12
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512, padding=True)
13
+
14
+ # Run inference
15
+ with torch.no_grad():
16
+ outputs = model(**inputs)
17
+ logits = outputs.logits
18
+
19
+ # Get the predicted class and probabilities
20
+ probabilities = torch.nn.functional.softmax(logits, dim=1)
21
+ predicted_class_idx = torch.argmax(probabilities, dim=1).item()
22
+ confidence = probabilities[0][predicted_class_idx].item()
23
+
24
+ # Map class index to label
25
+ labels = ["Human-written", "AI-generated"]
26
+ predicted_label = labels[predicted_class_idx]
27
+
28
+ return predicted_label, confidence
29
+
30
+ if __name__ == "__main__":
31
+ # Example usage
32
+ text = "Enter your text here to test if it's AI-generated or human-written."
33
+ result, confidence = classify_text(text)
34
+ print(f"This text appears to be: {result}")
35
+ print(f"Confidence: {confidence:.4f}")
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:c1f89a54999e6ab4b9a153081aaf5afc1df7776b52f1501ee9b275770ac43931
3
+ size 498612824
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,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "extra_special_tokens": {},
51
+ "mask_token": "<mask>",
52
+ "model_max_length": 512,
53
+ "pad_token": "<pad>",
54
+ "sep_token": "</s>",
55
+ "tokenizer_class": "RobertaTokenizer",
56
+ "trim_offsets": true,
57
+ "unk_token": "<unk>"
58
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff