CHIPP-AI commited on
Commit
090ab98
·
verified ·
1 Parent(s): 5adeac4

Upload folder using huggingface_hub

Browse files
added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "[MASK]": 128000
3
+ }
config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_attn_implementation_autoset": true,
3
+ "model_type": "ensemble-deberta",
4
+ "num_models": 3,
5
+ "transformers_version": "4.47.1"
6
+ }
model_0/config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/content/drive/MyDrive/DeBERTa-final-65-10-25",
3
+ "architectures": [
4
+ "DebertaV2ForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "hidden_act": "gelu",
8
+ "hidden_dropout_prob": 0.1,
9
+ "hidden_size": 768,
10
+ "id2label": {
11
+ "0": "LABEL_0",
12
+ "1": "LABEL_1",
13
+ "2": "LABEL_2"
14
+ },
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 3072,
17
+ "label2id": {
18
+ "LABEL_0": 0,
19
+ "LABEL_1": 1,
20
+ "LABEL_2": 2
21
+ },
22
+ "layer_norm_eps": 1e-07,
23
+ "legacy": true,
24
+ "max_position_embeddings": 512,
25
+ "max_relative_positions": -1,
26
+ "model_type": "deberta-v2",
27
+ "norm_rel_ebd": "layer_norm",
28
+ "num_attention_heads": 12,
29
+ "num_hidden_layers": 12,
30
+ "pad_token_id": 0,
31
+ "pooler_dropout": 0,
32
+ "pooler_hidden_act": "gelu",
33
+ "pooler_hidden_size": 768,
34
+ "pos_att_type": [
35
+ "p2c",
36
+ "c2p"
37
+ ],
38
+ "position_biased_input": false,
39
+ "position_buckets": 256,
40
+ "relative_attention": true,
41
+ "share_att_key": true,
42
+ "torch_dtype": "float32",
43
+ "transformers_version": "4.47.1",
44
+ "type_vocab_size": 0,
45
+ "vocab_size": 128100
46
+ }
model_0/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a9c7119d4c575e04ab37dae654818346d4ae5b8432eb33fccf16f681ba04595e
3
+ size 737722356
model_1/config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/content/drive/MyDrive/DeBERTa-final-50-20-30",
3
+ "architectures": [
4
+ "DebertaV2ForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "hidden_act": "gelu",
8
+ "hidden_dropout_prob": 0.1,
9
+ "hidden_size": 768,
10
+ "id2label": {
11
+ "0": "LABEL_0",
12
+ "1": "LABEL_1",
13
+ "2": "LABEL_2"
14
+ },
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 3072,
17
+ "label2id": {
18
+ "LABEL_0": 0,
19
+ "LABEL_1": 1,
20
+ "LABEL_2": 2
21
+ },
22
+ "layer_norm_eps": 1e-07,
23
+ "legacy": true,
24
+ "max_position_embeddings": 512,
25
+ "max_relative_positions": -1,
26
+ "model_type": "deberta-v2",
27
+ "norm_rel_ebd": "layer_norm",
28
+ "num_attention_heads": 12,
29
+ "num_hidden_layers": 12,
30
+ "pad_token_id": 0,
31
+ "pooler_dropout": 0,
32
+ "pooler_hidden_act": "gelu",
33
+ "pooler_hidden_size": 768,
34
+ "pos_att_type": [
35
+ "p2c",
36
+ "c2p"
37
+ ],
38
+ "position_biased_input": false,
39
+ "position_buckets": 256,
40
+ "relative_attention": true,
41
+ "share_att_key": true,
42
+ "torch_dtype": "float32",
43
+ "transformers_version": "4.47.1",
44
+ "type_vocab_size": 0,
45
+ "vocab_size": 128100
46
+ }
model_1/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:500d186382a08fe21b98b4ad1b92bcbdfc2f00cd3e61de5d421e516bc0b3ec97
3
+ size 737722356
model_2/config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/content/drive/MyDrive/DeBERTa-final-33-33-33",
3
+ "architectures": [
4
+ "DebertaV2ForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "hidden_act": "gelu",
8
+ "hidden_dropout_prob": 0.1,
9
+ "hidden_size": 768,
10
+ "id2label": {
11
+ "0": "LABEL_0",
12
+ "1": "LABEL_1",
13
+ "2": "LABEL_2"
14
+ },
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 3072,
17
+ "label2id": {
18
+ "LABEL_0": 0,
19
+ "LABEL_1": 1,
20
+ "LABEL_2": 2
21
+ },
22
+ "layer_norm_eps": 1e-07,
23
+ "legacy": true,
24
+ "max_position_embeddings": 512,
25
+ "max_relative_positions": -1,
26
+ "model_type": "deberta-v2",
27
+ "norm_rel_ebd": "layer_norm",
28
+ "num_attention_heads": 12,
29
+ "num_hidden_layers": 12,
30
+ "pad_token_id": 0,
31
+ "pooler_dropout": 0,
32
+ "pooler_hidden_act": "gelu",
33
+ "pooler_hidden_size": 768,
34
+ "pos_att_type": [
35
+ "p2c",
36
+ "c2p"
37
+ ],
38
+ "position_biased_input": false,
39
+ "position_buckets": 256,
40
+ "relative_attention": true,
41
+ "share_att_key": true,
42
+ "torch_dtype": "float32",
43
+ "transformers_version": "4.47.1",
44
+ "type_vocab_size": 0,
45
+ "vocab_size": 128100
46
+ }
model_2/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac3e6a63390057c78f6eeef37db58396714ba022ddd62668eca0d61ea0302973
3
+ size 737722356
modeling_ensemble_deberta.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class EnsembleDebertaConfig(PretrainedConfig):
2
+ model_type = "ensemble-deberta"
3
+ def __init__(self, num_models=3, **kwargs):
4
+ super().__init__(**kwargs)
5
+ self.num_models = num_models
6
+
7
+ class EnsembleDeberta(PreTrainedModel):
8
+ config_class = EnsembleDebertaConfig
9
+ base_model_prefix = "ensemble-deberta"
10
+
11
+ def __init__(self, model_paths=None, config=None):
12
+ # If no config is provided, initialize a default one
13
+ if config is None:
14
+ config = EnsembleDebertaConfig()
15
+ super().__init__(config)
16
+
17
+ # Create a ModuleList to hold the individual models
18
+ # Can pass additional kwargs (e.g. num_labels) if needed
19
+ if model_paths is None:
20
+ raise ValueError("Please provide a list of model paths.")
21
+ # Load each model from the provided paths
22
+ self.models = nn.ModuleList([
23
+ DebertaV2ForSequenceClassification.from_pretrained(path)
24
+ for path in model_paths
25
+ ])
26
+ if len(self.models) != self.config.num_models:
27
+ # Update config if needed
28
+ self.config.num_models = len(self.models)
29
+
30
+ # Automatically load the tokenizer from the first submodel (as all submodels use the same tokenizer)
31
+ self.tokenizer = AutoTokenizer.from_pretrained(save_directory)
32
+
33
+ def forward(self, **kwargs):
34
+ '''
35
+ Forward pass that obtains the logits from each model, computes softmax probabilities and averages them (soft voting).
36
+ '''
37
+ # Collect softmax probabilities from each model
38
+ probs = []
39
+ for model in self.models:
40
+ # Each model is assumed to return a ModelOutput with a 'logits' attribute
41
+ outputs = model(**kwargs)
42
+ logits = outputs.logits # shape: (batch_size, num_labels)
43
+ # Compute softmax for each model
44
+ probs.append(torch.nn.functional.softmax(logits, dim=-1))
45
+
46
+ # Stack and average the probabilities
47
+ avg_probs = torch.stack(probs, dim=0).mean(dim=0)
48
+ return avg_probs
49
+
50
+ def save_pretrained(self, save_directory, **kwargs):
51
+ '''
52
+ Saves the ensemble model and its tokenizer. Each submodel is saved in its own subdirectory.
53
+ '''
54
+ os.makedirs(save_directory, exist_ok=True)
55
+ # Save the ensemble configuration
56
+ self.config.save_pretrained(save_directory)
57
+
58
+ # Save each submodel to its own subdirectory
59
+ for idx, model in enumerate(self.models):
60
+ sub_dir = os.path.join(save_directory, f"model_{idx}")
61
+ model.save_pretrained(sub_dir)
62
+
63
+ # Save the tokenizer
64
+ self.tokenizer.save_pretrained(save_directory)
65
+
66
+ print(f"Ensemble saved to {save_directory}.")
67
+
68
+ @classmethod
69
+ def from_pretrained(cls, save_directory, **kwargs):
70
+ '''
71
+ Loads the ensemble model.
72
+ '''
73
+ # Load the ensemble configuration
74
+ config = EnsembleDebertaConfig.from_pretrained(save_directory)
75
+ num_models = config.num_models
76
+
77
+ # Determine the paths for each submodel
78
+ model_paths = [os.path.join(save_directory, f"model_{idx}") for idx in range(num_models)]
79
+
80
+ # Initialize the ensemble
81
+ ensemble = cls(model_paths=model_paths, config=config)
82
+
83
+ return ensemble
special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "[CLS]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "[SEP]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "mask_token": {
24
+ "content": "[MASK]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "pad_token": {
31
+ "content": "[PAD]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "sep_token": {
38
+ "content": "[SEP]",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ },
44
+ "unk_token": {
45
+ "content": "[UNK]",
46
+ "lstrip": false,
47
+ "normalized": true,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ }
51
+ }
spm.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c679fbf93643d19aab7ee10c0b99e460bdbc02fedf34b92b05af343b4af586fd
3
+ size 2464616
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "[CLS]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "[SEP]",
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": true,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "128000": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "bos_token": "[CLS]",
45
+ "clean_up_tokenization_spaces": false,
46
+ "cls_token": "[CLS]",
47
+ "do_lower_case": false,
48
+ "eos_token": "[SEP]",
49
+ "extra_special_tokens": {},
50
+ "mask_token": "[MASK]",
51
+ "max_length": 256,
52
+ "model_max_length": 1000000000000000019884624838656,
53
+ "pad_to_multiple_of": null,
54
+ "pad_token": "[PAD]",
55
+ "pad_token_type_id": 0,
56
+ "padding_side": "right",
57
+ "sep_token": "[SEP]",
58
+ "sp_model_kwargs": {},
59
+ "split_by_punct": false,
60
+ "stride": 0,
61
+ "tokenizer_class": "DebertaV2Tokenizer",
62
+ "truncation_side": "right",
63
+ "truncation_strategy": "longest_first",
64
+ "unk_token": "[UNK]",
65
+ "vocab_type": "spm"
66
+ }
transformers.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from .modeling_ensemble_deberta import EnsembleDeberta, EnsembleDebertaConfig
2
+ from transformers import AutoConfig, AutoModel
3
+
4
+ # Register the custom config and model with the auto classes.
5
+ AutoConfig.register("ensemble-deberta", EnsembleDebertaConfig)
6
+ AutoModel.register(EnsembleDebertaConfig, EnsembleDeberta)