Save the first version of the model
Browse files- .gitattributes +1 -0
- config.json +15 -0
- config.py +22 -0
- model.py +39 -0
- pytorch_model.bin +3 -0
- sentencepiece.bpe.model +3 -0
- special_tokens_map.json +15 -0
- tokenizer.json +3 -0
- tokenizer_config.json +21 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
config.json
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"AutextificationMTLModel"
|
4 |
+
],
|
5 |
+
"auto_map": {
|
6 |
+
"AutoConfig": "config.AutextificationMTLConfig",
|
7 |
+
"AutoModel": "model.AutextificationMTLModel"
|
8 |
+
},
|
9 |
+
"hidden_nodes": 64,
|
10 |
+
"model_type": "custom-text-classifier",
|
11 |
+
"threshold": 0.9919,
|
12 |
+
"torch_dtype": "float32",
|
13 |
+
"transformer_name": "xlm-roberta-base",
|
14 |
+
"transformers_version": "4.25.1"
|
15 |
+
}
|
config.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import PretrainedConfig
|
2 |
+
|
3 |
+
|
4 |
+
class AutextificationMTLConfig(PretrainedConfig):
|
5 |
+
model_type = "custom-text-classifier"
|
6 |
+
|
7 |
+
def __init__(
|
8 |
+
self,
|
9 |
+
transformer_name: str = "xlm-roberta-base",
|
10 |
+
hidden_nodes: int = 64,
|
11 |
+
threshold: float = 0.9919,
|
12 |
+
**kwargs,
|
13 |
+
):
|
14 |
+
if hidden_nodes <= 0:
|
15 |
+
raise ValueError(
|
16 |
+
f"`hidden_size` must be a positive number, got {hidden_nodes}."
|
17 |
+
)
|
18 |
+
|
19 |
+
self.transformer_name = transformer_name
|
20 |
+
self.hidden_nodes = hidden_nodes
|
21 |
+
self.threshold = threshold
|
22 |
+
super().__init__(**kwargs)
|
model.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.nn.functional as F
|
3 |
+
from transformers import AutoModel, PreTrainedModel
|
4 |
+
|
5 |
+
from .config import AutextificationMTLConfig
|
6 |
+
|
7 |
+
|
8 |
+
class AutextificationMTLModel(PreTrainedModel):
|
9 |
+
config_class = AutextificationMTLConfig
|
10 |
+
|
11 |
+
def __init__(self, config: AutextificationMTLConfig):
|
12 |
+
super().__init__(config)
|
13 |
+
|
14 |
+
self.encoder = AutoModel.from_pretrained(config.transformer_name)
|
15 |
+
embedding_size = self.encoder.config.hidden_size
|
16 |
+
self.hidden = torch.nn.Linear(embedding_size, config.hidden_nodes)
|
17 |
+
self.out_generated = torch.nn.Linear(config.hidden_nodes, 1)
|
18 |
+
self.out_language = torch.nn.Linear(config.hidden_nodes, 1)
|
19 |
+
|
20 |
+
self.threshold = config.threshold
|
21 |
+
|
22 |
+
def forward(self, tensor):
|
23 |
+
output = self.encoder(
|
24 |
+
input_ids=tensor["input_ids"],
|
25 |
+
attention_mask=tensor["attention_mask"],
|
26 |
+
return_dict=True
|
27 |
+
)
|
28 |
+
pooler_output = output["pooler_output"]
|
29 |
+
|
30 |
+
out = F.relu(self.hidden(pooler_output))
|
31 |
+
out_generated = torch.sigmoid(self.out_generated(out))
|
32 |
+
out_language = torch.sigmoid(self.out_language(out))
|
33 |
+
out_verdict = out_generated > self.threshold
|
34 |
+
|
35 |
+
return {
|
36 |
+
"is_bot": out_verdict,
|
37 |
+
"bot_prob": out_generated,
|
38 |
+
"english_prob": out_language,
|
39 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:334a26950a52e078f3ae977657a385f1ad3355987fc1db67630882d9fa1e2155
|
3 |
+
size 1112443781
|
sentencepiece.bpe.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cfc8146abe2a0488e9e2a0c56de7952f7c11ab059eca145a0a727afce0db2865
|
3 |
+
size 5069051
|
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
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:62c24cdc13d4c9952d63718d6c9fa4c287974249e16b7ade6d5a85e7bbb75626
|
3 |
+
size 17082660
|
tokenizer_config.json
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": "<s>",
|
3 |
+
"cls_token": "<s>",
|
4 |
+
"eos_token": "</s>",
|
5 |
+
"mask_token": {
|
6 |
+
"__type": "AddedToken",
|
7 |
+
"content": "<mask>",
|
8 |
+
"lstrip": true,
|
9 |
+
"normalized": true,
|
10 |
+
"rstrip": false,
|
11 |
+
"single_word": false
|
12 |
+
},
|
13 |
+
"model_max_length": 512,
|
14 |
+
"name_or_path": "xlm-roberta-base",
|
15 |
+
"pad_token": "<pad>",
|
16 |
+
"sep_token": "</s>",
|
17 |
+
"special_tokens_map_file": null,
|
18 |
+
"strip_accents": false,
|
19 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
20 |
+
"unk_token": "<unk>"
|
21 |
+
}
|