PereLluis13 commited on
Commit
b994e9c
1 Parent(s): 25c3ef4

Upload model

Browse files
Files changed (3) hide show
  1. config.json +28 -0
  2. hf.py +88 -0
  3. pytorch_model.bin +3 -0
config.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "wandb/run-20240127_232932-y87tmk9t/files/retriever/question_encoder",
3
+ "architectures": [
4
+ "GoldenRetrieverModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "auto_map": {
8
+ "AutoModel": "hf.GoldenRetrieverModel"
9
+ },
10
+ "classifier_dropout": null,
11
+ "hidden_act": "gelu",
12
+ "hidden_dropout_prob": 0.1,
13
+ "hidden_size": 384,
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 1536,
16
+ "layer_norm_eps": 1e-12,
17
+ "max_position_embeddings": 512,
18
+ "model_type": "bert",
19
+ "num_attention_heads": 12,
20
+ "num_hidden_layers": 12,
21
+ "pad_token_id": 0,
22
+ "position_embedding_type": "absolute",
23
+ "torch_dtype": "float32",
24
+ "transformers_version": "4.33.3",
25
+ "type_vocab_size": 2,
26
+ "use_cache": true,
27
+ "vocab_size": 30522
28
+ }
hf.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Tuple, Union
2
+
3
+ import torch
4
+ from transformers import PretrainedConfig
5
+ from transformers.modeling_outputs import BaseModelOutputWithPoolingAndCrossAttentions
6
+ from transformers.models.bert.modeling_bert import BertModel
7
+
8
+
9
+ class GoldenRetrieverConfig(PretrainedConfig):
10
+ model_type = "bert"
11
+
12
+ def __init__(
13
+ self,
14
+ vocab_size=30522,
15
+ hidden_size=768,
16
+ num_hidden_layers=12,
17
+ num_attention_heads=12,
18
+ intermediate_size=3072,
19
+ hidden_act="gelu",
20
+ hidden_dropout_prob=0.1,
21
+ attention_probs_dropout_prob=0.1,
22
+ max_position_embeddings=512,
23
+ type_vocab_size=2,
24
+ initializer_range=0.02,
25
+ layer_norm_eps=1e-12,
26
+ pad_token_id=0,
27
+ position_embedding_type="absolute",
28
+ use_cache=True,
29
+ classifier_dropout=None,
30
+ **kwargs,
31
+ ):
32
+ super().__init__(pad_token_id=pad_token_id, **kwargs)
33
+
34
+ self.vocab_size = vocab_size
35
+ self.hidden_size = hidden_size
36
+ self.num_hidden_layers = num_hidden_layers
37
+ self.num_attention_heads = num_attention_heads
38
+ self.hidden_act = hidden_act
39
+ self.intermediate_size = intermediate_size
40
+ self.hidden_dropout_prob = hidden_dropout_prob
41
+ self.attention_probs_dropout_prob = attention_probs_dropout_prob
42
+ self.max_position_embeddings = max_position_embeddings
43
+ self.type_vocab_size = type_vocab_size
44
+ self.initializer_range = initializer_range
45
+ self.layer_norm_eps = layer_norm_eps
46
+ self.position_embedding_type = position_embedding_type
47
+ self.use_cache = use_cache
48
+ self.classifier_dropout = classifier_dropout
49
+
50
+
51
+ class GoldenRetrieverModel(BertModel):
52
+ config_class = GoldenRetrieverConfig
53
+
54
+ def __init__(self, config, *args, **kwargs):
55
+ super().__init__(config)
56
+ self.layer_norm_layer = torch.nn.LayerNorm(
57
+ config.hidden_size, eps=config.layer_norm_eps
58
+ )
59
+
60
+ def forward(
61
+ self, **kwargs
62
+ ) -> Union[Tuple[torch.Tensor], BaseModelOutputWithPoolingAndCrossAttentions]:
63
+ attention_mask = kwargs.get("attention_mask", None)
64
+ model_outputs = super().forward(**kwargs)
65
+ if attention_mask is None:
66
+ pooler_output = model_outputs.pooler_output
67
+ else:
68
+ token_embeddings = model_outputs.last_hidden_state
69
+ input_mask_expanded = (
70
+ attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
71
+ )
72
+ pooler_output = torch.sum(
73
+ token_embeddings * input_mask_expanded, 1
74
+ ) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
75
+
76
+ pooler_output = self.layer_norm_layer(pooler_output)
77
+
78
+ if not kwargs.get("return_dict", True):
79
+ return (model_outputs[0], pooler_output) + model_outputs[2:]
80
+
81
+ return BaseModelOutputWithPoolingAndCrossAttentions(
82
+ last_hidden_state=model_outputs.last_hidden_state,
83
+ pooler_output=pooler_output,
84
+ past_key_values=model_outputs.past_key_values,
85
+ hidden_states=model_outputs.hidden_states,
86
+ attentions=model_outputs.attentions,
87
+ cross_attentions=model_outputs.cross_attentions,
88
+ )
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9d00da0accfb05fb29975b3af200cd92758e208cf12e579f29e8c1a14bb04f05
3
+ size 133508078