jpohhhh commited on
Commit
8b5c988
1 Parent(s): 3eb6e86

Fork jpohhhh/embeddings_from_msmarco-MiniLM-L-6-v3

Browse files
README.md CHANGED
@@ -1,3 +1,3 @@
1
  ---
2
- license: unknown
3
  ---
 
1
  ---
2
+ license: unlicense
3
  ---
config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "sentence-transformers/all-MiniLM-L6-v2",
3
+ "architectures": [
4
+ "BertModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "gradient_checkpointing": false,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 384,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 1536,
14
+ "layer_norm_eps": 1e-12,
15
+ "max_position_embeddings": 512,
16
+ "model_type": "bert",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 6,
19
+ "pad_token_id": 0,
20
+ "position_embedding_type": "absolute",
21
+ "torch_dtype": "float32",
22
+ "transformers_version": "4.23.1",
23
+ "type_vocab_size": 2,
24
+ "use_cache": true,
25
+ "vocab_size": 30522
26
+ }
handler.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+ from transformers import AutoTokenizer, AutoModel
3
+ import torch
4
+
5
+ #Mean Pooling - Take attention mask into account for correct averaging
6
+ def mean_pooling(model_output, attention_mask):
7
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
8
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
9
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
10
+
11
+ class EndpointHandler():
12
+ def __init__(self, path=""):
13
+ self.tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/msmarco-MiniLM-L-6-v3')
14
+ self.model = AutoModel.from_pretrained('sentence-transformers/msmarco-MiniLM-L-6-v3')
15
+
16
+ def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
17
+ """
18
+ data args:
19
+ inputs (:obj: `str` | `PIL.Image` | `np.array`)
20
+ kwargs
21
+ Return:
22
+ A :obj:`list` | `dict`: will be serialized and returned
23
+ """
24
+ sentences = data.pop("inputs",data)
25
+ encoded_input = self.tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
26
+ # Compute token embeddings
27
+ with torch.no_grad():
28
+ model_output = self.model(**encoded_input)
29
+
30
+ # Perform pooling. In this case, max pooling.
31
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
32
+ return sentence_embeddings.tolist()
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4593facd634592b4a1ba74db6e75b0d3a6418343a0fec6e019a07d04785b08b5
3
+ size 128
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ torch
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,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "do_basic_tokenize": true,
4
+ "do_lower_case": true,
5
+ "mask_token": "[MASK]",
6
+ "model_max_length": 512,
7
+ "name_or_path": "sentence-transformers/all-MiniLM-L6-v2",
8
+ "never_split": null,
9
+ "pad_token": "[PAD]",
10
+ "sep_token": "[SEP]",
11
+ "special_tokens_map_file": "C:\\Users\\alvin/.cache\\huggingface\\hub\\models--sentence-transformers--all-MiniLM-L6-v2\\snapshots\\7dbbc90392e2f80f3d3c277d6e90027e55de9125\\special_tokens_map.json",
12
+ "strip_accents": null,
13
+ "tokenize_chinese_chars": true,
14
+ "tokenizer_class": "BertTokenizer",
15
+ "unk_token": "[UNK]"
16
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8f1477dbc12d625e3d64d8f2f9cb5bf693eb30bccabba930eb66d06d3a3bdd84
3
+ size 128
vocab.txt ADDED
The diff for this file is too large to render. See raw diff