Commit
·
f12d262
1
Parent(s):
7fca419
Automatic push from sapienzanlp
Browse files- config.json +28 -0
- hf.py +88 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +13 -0
- vocab.txt +0 -0
config.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "intfloat/e5-small-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 |
+
"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:d9a0c47a5d93d2fd48b2b06567829f7943bc89a36a4a28ecbd772d0f8b99f7eb
|
| 3 |
+
size 133510449
|
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,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"clean_up_tokenization_spaces": true,
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"do_lower_case": true,
|
| 5 |
+
"mask_token": "[MASK]",
|
| 6 |
+
"model_max_length": 512,
|
| 7 |
+
"pad_token": "[PAD]",
|
| 8 |
+
"sep_token": "[SEP]",
|
| 9 |
+
"strip_accents": null,
|
| 10 |
+
"tokenize_chinese_chars": true,
|
| 11 |
+
"tokenizer_class": "BertTokenizer",
|
| 12 |
+
"unk_token": "[UNK]"
|
| 13 |
+
}
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|