Commit
·
f75d43f
1
Parent(s):
3e8d9f7
Upload 9 files
Browse files- ToxicityModel_emissions.csv +2 -0
- config.json +30 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +15 -0
- toxicity_model.py +47 -0
- toxicity_model_config.py +46 -0
- vocab.txt +0 -0
ToxicityModel_emissions.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
timestamp,project_name,run_id,duration,emissions,emissions_rate,cpu_power,gpu_power,ram_power,cpu_energy,gpu_energy,ram_energy,energy_consumed,country_name,country_iso_code,region,cloud_provider,cloud_region,os,python_version,codecarbon_version,cpu_count,cpu_model,gpu_count,gpu_model,longitude,latitude,ram_total_size,tracking_mode,on_cloud,pue
|
2 |
+
2023-06-11T20:47:46,ToxicityModel_emissions,4a6f45ca-817a-4738-b3ec-6b9bf43275d6,8172.121086597443,0.38904138433484975,4.7605925097327656e-05,42.5,310.83,31.30528450012207,0.09647620793547898,0.6920245228854167,0.07102982035970598,0.8595305511806026,United States,USA,iowa,,,Linux-5.15.107+-x86_64-with-glibc2.31,3.10.12,2.2.3,12,Intel(R) Xeon(R) CPU @ 2.20GHz,1,1 x NVIDIA A100-SXM4-40GB,-95.8517,41.2591,83.48075866699219,machine,N,1.0
|
config.json
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"ToxicityModel"
|
4 |
+
],
|
5 |
+
"attention_probs_dropout_prob": 0.1,
|
6 |
+
"auto_map": {
|
7 |
+
"AutoConfig": "toxicity_model_config.ToxicityModelConfig",
|
8 |
+
"AutoModel": "toxicity_model.ToxicityModel"
|
9 |
+
},
|
10 |
+
"classifier_dropout": null,
|
11 |
+
"hidden_act": "gelu",
|
12 |
+
"hidden_dropout_prob": 0.1,
|
13 |
+
"hidden_size": 768,
|
14 |
+
"initializer_range": 0.02,
|
15 |
+
"intermediate_size": 3072,
|
16 |
+
"layer_norm_eps": 1e-12,
|
17 |
+
"linear_layer": 128,
|
18 |
+
"linear_layer_output": 1,
|
19 |
+
"max_position_embeddings": 512,
|
20 |
+
"model_type": "bert-toxic",
|
21 |
+
"num_attention_heads": 12,
|
22 |
+
"num_hidden_layers": 12,
|
23 |
+
"pad_token_id": 0,
|
24 |
+
"position_embedding_type": "absolute",
|
25 |
+
"torch_dtype": "float32",
|
26 |
+
"transformers_version": "4.25.1",
|
27 |
+
"type_vocab_size": 2,
|
28 |
+
"use_cache": true,
|
29 |
+
"vocab_size": 29794
|
30 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:69e42ac063038c7fb641273bb302795de39f7de949ea38e00bf38333ee753681
|
3 |
+
size 436222181
|
special_tokens_map.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"mask_token": "[MASK]",
|
4 |
+
"pad_token": "[PAD]",
|
5 |
+
"sep_token": "[SEP]",
|
6 |
+
"unk_token": "[UNK]"
|
7 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"clean_up_tokenization_spaces": true,
|
3 |
+
"cls_token": "[CLS]",
|
4 |
+
"do_basic_tokenize": true,
|
5 |
+
"do_lower_case": false,
|
6 |
+
"mask_token": "[MASK]",
|
7 |
+
"model_max_length": 1000000000000000019884624838656,
|
8 |
+
"never_split": null,
|
9 |
+
"pad_token": "[PAD]",
|
10 |
+
"sep_token": "[SEP]",
|
11 |
+
"strip_accents": null,
|
12 |
+
"tokenize_chinese_chars": true,
|
13 |
+
"tokenizer_class": "BertTokenizer",
|
14 |
+
"unk_token": "[UNK]"
|
15 |
+
}
|
toxicity_model.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import BertPreTrainedModel, BertModel
|
2 |
+
from .toxicity_model_config import ToxicityModelConfig
|
3 |
+
import torch
|
4 |
+
|
5 |
+
class ToxicityModel(BertPreTrainedModel):
|
6 |
+
"""
|
7 |
+
ToxicityModel class for PyTorch
|
8 |
+
|
9 |
+
Args:
|
10 |
+
config (transformers.configuration): model configuration
|
11 |
+
|
12 |
+
Returns:
|
13 |
+
output (torch.tensor): tensor containing the output logits [-1,1]
|
14 |
+
"""
|
15 |
+
config_class = ToxicityModelConfig
|
16 |
+
|
17 |
+
def __init__(self, config):
|
18 |
+
super().__init__(config)
|
19 |
+
self.bert = BertModel(config)
|
20 |
+
|
21 |
+
self.cls_layer1 = torch.nn.Linear(config.hidden_size,config.linear_layer)
|
22 |
+
self.relu1 = torch.nn.ReLU()
|
23 |
+
self.ff1 = torch.nn.Linear(config.linear_layer,config.linear_layer)
|
24 |
+
self.tanh1 = torch.nn.Tanh()
|
25 |
+
self.ff2 = torch.nn.Linear(config.linear_layer,config.linear_layer_output)
|
26 |
+
|
27 |
+
def forward(self, input_ids, attention_mask, alpha=1, beta=1e-5):
|
28 |
+
|
29 |
+
outputs = self.bert(input_ids=input_ids, attention_mask=attention_mask)
|
30 |
+
|
31 |
+
logits = outputs.last_hidden_state[:,0,:]
|
32 |
+
output = self.cls_layer1(logits)
|
33 |
+
output = self.relu1(output)
|
34 |
+
output = self.ff1(output)
|
35 |
+
output = self.tanh1(output)
|
36 |
+
output = self.ff2(output)
|
37 |
+
|
38 |
+
# Apply alpha and beta to output (if not training)
|
39 |
+
if not self.training:
|
40 |
+
|
41 |
+
# alpha multiplies the output by a scalar
|
42 |
+
output = torch.mul(output, alpha)
|
43 |
+
|
44 |
+
# beta clamps the output to a minimum value
|
45 |
+
output = torch.clamp(output, min=beta)
|
46 |
+
|
47 |
+
return output
|
toxicity_model_config.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import PretrainedConfig
|
2 |
+
|
3 |
+
class ToxicityModelConfig(PretrainedConfig):
|
4 |
+
model_type="bert-toxic"
|
5 |
+
|
6 |
+
def __init__(
|
7 |
+
self,
|
8 |
+
vocab_size=29794,
|
9 |
+
hidden_size=768,
|
10 |
+
num_hidden_layers=12,
|
11 |
+
num_attention_heads=12,
|
12 |
+
intermediate_size=3072,
|
13 |
+
hidden_act="gelu",
|
14 |
+
hidden_dropout_prob=0.1,
|
15 |
+
attention_probs_dropout_prob=0.1,
|
16 |
+
max_position_embeddings=512,
|
17 |
+
type_vocab_size=2,
|
18 |
+
initializer_range=0.02,
|
19 |
+
layer_norm_eps=1e-12,
|
20 |
+
pad_token_id=0,
|
21 |
+
position_embedding_type="absolute",
|
22 |
+
use_cache=True,
|
23 |
+
classifier_dropout=None,
|
24 |
+
linear_layer=128,
|
25 |
+
linear_layer_output=1,
|
26 |
+
**kwargs,
|
27 |
+
):
|
28 |
+
super().__init__(pad_token_id=pad_token_id, **kwargs)
|
29 |
+
|
30 |
+
self.vocab_size = vocab_size
|
31 |
+
self.hidden_size = hidden_size
|
32 |
+
self.num_hidden_layers = num_hidden_layers
|
33 |
+
self.num_attention_heads = num_attention_heads
|
34 |
+
self.hidden_act = hidden_act
|
35 |
+
self.intermediate_size = intermediate_size
|
36 |
+
self.hidden_dropout_prob = hidden_dropout_prob
|
37 |
+
self.attention_probs_dropout_prob = attention_probs_dropout_prob
|
38 |
+
self.max_position_embeddings = max_position_embeddings
|
39 |
+
self.type_vocab_size = type_vocab_size
|
40 |
+
self.initializer_range = initializer_range
|
41 |
+
self.layer_norm_eps = layer_norm_eps
|
42 |
+
self.position_embedding_type = position_embedding_type
|
43 |
+
self.use_cache = use_cache
|
44 |
+
self.classifier_dropout = classifier_dropout
|
45 |
+
self.linear_layer = linear_layer
|
46 |
+
self.linear_layer_output = linear_layer_output
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|