riccorl commited on
Commit
43b478c
1 Parent(s): ae696ff

Upload folder using huggingface_hub

Browse files
Files changed (7) hide show
  1. config.json +30 -0
  2. hf.py +99 -0
  3. model.safetensors +3 -0
  4. special_tokens_map.json +37 -0
  5. tokenizer.json +0 -0
  6. tokenizer_config.json +55 -0
  7. vocab.txt +0 -0
config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "intfloat/e5-base-v2",
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
+ "gradient_checkpointing": false,
12
+ "hidden_act": "gelu",
13
+ "hidden_dropout_prob": 0.1,
14
+ "hidden_size": 768,
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 3072,
17
+ "layer_norm_eps": 1e-12,
18
+ "max_position_embeddings": 512,
19
+ "model_type": "bert",
20
+ "num_attention_heads": 12,
21
+ "num_hidden_layers": 12,
22
+ "pad_token_id": 0,
23
+ "position_embedding_type": "absolute",
24
+ "projection_dim": null,
25
+ "torch_dtype": "float32",
26
+ "transformers_version": "4.41.2",
27
+ "type_vocab_size": 2,
28
+ "use_cache": true,
29
+ "vocab_size": 30522
30
+ }
hf.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ projection_dim=None,
31
+ **kwargs,
32
+ ):
33
+ super().__init__(pad_token_id=pad_token_id, **kwargs)
34
+
35
+ self.vocab_size = vocab_size
36
+ self.hidden_size = hidden_size
37
+ self.num_hidden_layers = num_hidden_layers
38
+ self.num_attention_heads = num_attention_heads
39
+ self.hidden_act = hidden_act
40
+ self.intermediate_size = intermediate_size
41
+ self.hidden_dropout_prob = hidden_dropout_prob
42
+ self.attention_probs_dropout_prob = attention_probs_dropout_prob
43
+ self.max_position_embeddings = max_position_embeddings
44
+ self.type_vocab_size = type_vocab_size
45
+ self.initializer_range = initializer_range
46
+ self.layer_norm_eps = layer_norm_eps
47
+ self.position_embedding_type = position_embedding_type
48
+ self.use_cache = use_cache
49
+ self.classifier_dropout = classifier_dropout
50
+ self.projection_dim = projection_dim
51
+
52
+
53
+ class GoldenRetrieverModel(BertModel):
54
+ config_class = GoldenRetrieverConfig
55
+
56
+ def __init__(self, config, *args, **kwargs):
57
+ super().__init__(config)
58
+ self.layer_norm_layer = torch.nn.LayerNorm(
59
+ config.hidden_size, eps=config.layer_norm_eps
60
+ )
61
+ self.projection: torch.nn.Module | None = None
62
+ if config.projection_dim is not None:
63
+ self.projection = torch.nn.Sequential(
64
+ torch.nn.Linear(config.hidden_size, config.projection_dim),
65
+ torch.nn.LayerNorm(config.projection_dim),
66
+ )
67
+
68
+ def forward(
69
+ self, **kwargs
70
+ ) -> Union[Tuple[torch.Tensor], BaseModelOutputWithPoolingAndCrossAttentions]:
71
+ attention_mask = kwargs.get("attention_mask", None)
72
+ model_outputs = super().forward(**kwargs)
73
+ if attention_mask is None:
74
+ pooler_output = model_outputs.pooler_output
75
+ else:
76
+ token_embeddings = model_outputs.last_hidden_state
77
+ input_mask_expanded = (
78
+ attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
79
+ )
80
+ pooler_output = torch.sum(
81
+ token_embeddings * input_mask_expanded, 1
82
+ ) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
83
+
84
+ pooler_output = self.layer_norm_layer(pooler_output)
85
+
86
+ if self.projection is not None:
87
+ pooler_output = self.projection(pooler_output)
88
+
89
+ if not kwargs.get("return_dict", True):
90
+ return (model_outputs[0], pooler_output) + model_outputs[2:]
91
+
92
+ return BaseModelOutputWithPoolingAndCrossAttentions(
93
+ last_hidden_state=model_outputs.last_hidden_state,
94
+ pooler_output=pooler_output,
95
+ past_key_values=model_outputs.past_key_values,
96
+ hidden_states=model_outputs.hidden_states,
97
+ attentions=model_outputs.attentions,
98
+ cross_attentions=model_outputs.cross_attentions,
99
+ )
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:73af2ffd655875e9d4689060ebb688ba3fbc07947983c021c18cd24cf0a42b07
3
+ size 437957656
special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": true,
45
+ "cls_token": "[CLS]",
46
+ "do_lower_case": true,
47
+ "mask_token": "[MASK]",
48
+ "model_max_length": 512,
49
+ "pad_token": "[PAD]",
50
+ "sep_token": "[SEP]",
51
+ "strip_accents": null,
52
+ "tokenize_chinese_chars": true,
53
+ "tokenizer_class": "BertTokenizer",
54
+ "unk_token": "[UNK]"
55
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff