ch0fas commited on
Commit
384bac5
·
1 Parent(s): d1b7d16

Grandes cosas sucediendo

Browse files
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import json
4
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
5
+
6
+ MODEL_PATH = "./model"
7
+
8
+ def load_model():
9
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, use_fast=False)
10
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_PATH)
11
+ model.eval()
12
+
13
+ with open(f"{MODEL_PATH}/label_mapping.json") as f:
14
+ label_mapping = json.load(f)
15
+
16
+ return tokenizer, model, label_mapping
17
+
18
+ tokenizer, model, label_mapping = load_model()
19
+
20
+ def predict(text: str):
21
+ if not text.strip():
22
+ return {}
23
+
24
+ inputs = tokenizer(
25
+ text,
26
+ return_tensors="pt",
27
+ padding="max_length",
28
+ truncation=True,
29
+ max_length=128,
30
+ )
31
+ with torch.no_grad():
32
+ logits = model(**inputs).logits
33
+
34
+ probs = torch.softmax(logits, dim=-1).squeeze()
35
+ scores = {label_mapping[str(i)]: float(probs[i]) for i in range(len(probs))}
36
+ return scores
37
+
38
+ demo = gr.Interface(
39
+ fn=predict,
40
+ inputs=gr.Textbox(
41
+ lines=5,
42
+ placeholder="Write something",
43
+ label="Example Tweet"
44
+ ),
45
+ outputs=gr.Label(
46
+ num_top_classes=len(label_mapping),
47
+ label="Predicted Label"
48
+ ),
49
+ title="Radical Speech Detector",
50
+ description="Enter a text and the model will classify it into one of the radical speech categories.\n\n\nBy Sofia Maldonado, Viviana Toledo & Oscar Rocha",
51
+ )
52
+
53
+ demo.launch()
model/added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "<mask>": 64000
3
+ }
model/bpe.codes ADDED
The diff for this file is too large to render. See raw diff
 
model/config.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_cross_attention": false,
3
+ "architectures": [
4
+ "RobertaForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "classifier_dropout": null,
9
+ "dtype": "float32",
10
+ "eos_token_id": 2,
11
+ "gradient_checkpointing": false,
12
+ "hidden_act": "gelu",
13
+ "hidden_dropout_prob": 0.1,
14
+ "hidden_size": 768,
15
+ "id2label": {
16
+ "0": "LABEL_0",
17
+ "1": "LABEL_1",
18
+ "2": "LABEL_2",
19
+ "3": "LABEL_3",
20
+ "4": "LABEL_4",
21
+ "5": "LABEL_5"
22
+ },
23
+ "initializer_range": 0.02,
24
+ "intermediate_size": 3072,
25
+ "is_decoder": false,
26
+ "label2id": {
27
+ "LABEL_0": 0,
28
+ "LABEL_1": 1,
29
+ "LABEL_2": 2,
30
+ "LABEL_3": 3,
31
+ "LABEL_4": 4,
32
+ "LABEL_5": 5
33
+ },
34
+ "layer_norm_eps": 1e-05,
35
+ "max_position_embeddings": 130,
36
+ "model_type": "roberta",
37
+ "num_attention_heads": 12,
38
+ "num_hidden_layers": 12,
39
+ "pad_token_id": 1,
40
+ "problem_type": "single_label_classification",
41
+ "tie_word_embeddings": true,
42
+ "tokenizer_class": "BertweetTokenizer",
43
+ "transformers_version": "5.8.0",
44
+ "type_vocab_size": 1,
45
+ "use_cache": false,
46
+ "vocab_size": 64001
47
+ }
model/label_mapping.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"0": "Dangerous Speech", "1": "Enraged Speech", "2": "Extreme Speech", "3": "Hate Grammar", "4": "Hate Speech", "5": "Horror Grammar"}
model/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e1793b6c2a2081de4b4c59fba90509e99bc84efc8a70a22b328c65c4d05afa61
3
+ size 539642472
model/tokenizer_config.json ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "64000": {
36
+ "content": "<mask>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "backend": "custom",
45
+ "bos_token": "<s>",
46
+ "cls_token": "<s>",
47
+ "eos_token": "</s>",
48
+ "is_local": false,
49
+ "local_files_only": false,
50
+ "mask_token": "<mask>",
51
+ "model_max_length": 1000000000000000019884624838656,
52
+ "normalization": false,
53
+ "pad_token": "<pad>",
54
+ "sep_token": "</s>",
55
+ "tokenizer_class": "BertweetTokenizer",
56
+ "unk_token": "<unk>"
57
+ }
model/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6878f3da261338741aea81d888c67104a7be7587802d32fe22ca71a57cdb933d
3
+ size 5265
model/vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch
4
+ sentencepiece