ekolasky commited on
Commit
0ef3cc0
·
1 Parent(s): df476cd

Upload model

Browse files
Files changed (3) hide show
  1. config.json +56 -0
  2. model.safetensors +3 -0
  3. modeling_CustomLEDForQA.py +40 -0
config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "./",
3
+ "_num_labels": 3,
4
+ "activation_dropout": 0.0,
5
+ "activation_function": "gelu",
6
+ "architectures": [
7
+ "CustomLEDForQAModel"
8
+ ],
9
+ "attention_dropout": 0.0,
10
+ "attention_window": [
11
+ 1024,
12
+ 1024,
13
+ 1024,
14
+ 1024,
15
+ 1024,
16
+ 1024,
17
+ 1024,
18
+ 1024,
19
+ 1024,
20
+ 1024,
21
+ 1024,
22
+ 1024
23
+ ],
24
+ "auto_map": {
25
+ "AutoModel": "modeling_CustomLEDForQA.CustomLEDForQAModel"
26
+ },
27
+ "bos_token_id": 0,
28
+ "classif_dropout": 0.0,
29
+ "classifier_dropout": 0.0,
30
+ "d_model": 1024,
31
+ "decoder_attention_heads": 16,
32
+ "decoder_ffn_dim": 4096,
33
+ "decoder_layerdrop": 0.0,
34
+ "decoder_layers": 12,
35
+ "decoder_start_token_id": 2,
36
+ "dropout": 0.1,
37
+ "encoder_attention_heads": 16,
38
+ "encoder_ffn_dim": 4096,
39
+ "encoder_layerdrop": 0.0,
40
+ "encoder_layers": 12,
41
+ "eos_token_id": 2,
42
+ "gradient_checkpointing": false,
43
+ "init_std": 0.02,
44
+ "is_encoder_decoder": true,
45
+ "max_decoder_position_embeddings": 1024,
46
+ "max_encoder_position_embeddings": 16384,
47
+ "model_type": "led",
48
+ "num_hidden_layers": 12,
49
+ "output_past": false,
50
+ "pad_token_id": 1,
51
+ "prefix": " ",
52
+ "torch_dtype": "float32",
53
+ "transformers_version": "4.35.0",
54
+ "use_cache": true,
55
+ "vocab_size": 50265
56
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f93ab471be2eed93a99b14a9d4168a2fa1e2dc351d36c38f5fe2216d27323fd2
3
+ size 1028803816
modeling_CustomLEDForQA.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # from transformers.models.led.modeling_led import LEDEncoder
2
+ from transformers import LEDConfig, LEDModel, LEDPreTrainedModel
3
+ import torch.nn as nn
4
+
5
+ # NEED TO REPLACE nn.Module with PreTrainedModel
6
+ class CustomLEDForQAModel(LEDPreTrainedModel):
7
+ config_class = LEDConfig
8
+
9
+ def __init__(self, config: LEDConfig):
10
+
11
+ super().__init__(config)
12
+ config.num_labels = 2
13
+ self.num_labels = config.num_labels
14
+
15
+ self.led = LEDModel(config).get_encoder()
16
+ self.qa_outputs = nn.Linear(config.hidden_size, config.num_labels)
17
+
18
+ def forward(self, input_ids=None, attention_mask=None, global_attention_mask=None, start_positions=None, end_positions=None):
19
+
20
+ outputs = self.led(input_ids=input_ids, attention_mask=attention_mask, global_attention_mask=global_attention_mask)
21
+
22
+ logits = self.qa_outputs(outputs.last_hidden_state)
23
+ start_logits, end_logits = logits.split(1, dim=-1)
24
+ start_logits = start_logits.squeeze(-1).contiguous()
25
+ end_logits = end_logits.squeeze(-1).contiguous()
26
+
27
+ total_loss = None
28
+ if start_positions is not None and end_positions is not None:
29
+
30
+ loss_fct = nn.CrossEntropyLoss()
31
+ start_loss = loss_fct(start_logits, start_positions[0])
32
+ end_loss = loss_fct(end_logits, end_positions[0])
33
+ total_loss = (start_loss + end_loss) / 2
34
+
35
+
36
+ return {
37
+ 'loss': total_loss,
38
+ 'start_logits': start_logits,
39
+ 'end_logits': end_logits,
40
+ }