nthakur commited on
Commit
0a356bb
1 Parent(s): bbfb1f7

initial model add and README.

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 768,
3
+ "pooling_mode_cls_token": true,
4
+ "pooling_mode_mean_tokens": false,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false
7
+ }
README.md ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: sentence-similarity
3
+ tags:
4
+ - sentence-transformers
5
+ - feature-extraction
6
+ - sentence-similarity
7
+ - transformers
8
+ datasets:
9
+ - wikipedia
10
+ - bookcorpus
11
+ - ms_marco
12
+ - BeIR/fiqa
13
+ - BeIR/trec-covid
14
+ - BeIR/scifact
15
+ - BeIR/nfcorpus
16
+ - BeIR/nq
17
+ - BeIR/hotpotqa
18
+ - BeIR/arguana
19
+ - BeIR/webis-touche2020
20
+ - BeIR/quora
21
+ - BeIR/dbpedia-entity
22
+ - BeIR/scidocs
23
+ - BeIR/fever
24
+ - BeIR/climate-fever
25
+ ---
26
+
27
+ # nthakur/RetroMAE_BEIR
28
+
29
+ This is a port of the [RetroMAE_BEIR](https://huggingface.co/Shitao/RetroMAE_BEIR) Model to [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
30
+
31
+ <!--- Describe your model here -->
32
+
33
+ ## Usage (Sentence-Transformers)
34
+
35
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
36
+
37
+ ```
38
+ pip install -U sentence-transformers
39
+ ```
40
+
41
+ Then you can use the model like this:
42
+
43
+ ```python
44
+ from sentence_transformers import SentenceTransformer
45
+ sentences = ["This is an example sentence", "Each sentence is converted"]
46
+
47
+ model = SentenceTransformer('nthakur/RetroMAE_BEIR')
48
+ embeddings = model.encode(sentences)
49
+ print(embeddings)
50
+ ```
51
+
52
+
53
+
54
+ ## Usage (HuggingFace Transformers)
55
+ Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
56
+
57
+ ```python
58
+ from transformers import AutoTokenizer, AutoModel
59
+ import torch
60
+
61
+
62
+ def cls_pooling(model_output, attention_mask):
63
+ return model_output[0][:,0]
64
+
65
+
66
+ # Sentences we want sentence embeddings for
67
+ sentences = ['This is an example sentence', 'Each sentence is converted']
68
+
69
+ # Load model from HuggingFace Hub
70
+ tokenizer = AutoTokenizer.from_pretrained('nthakur/RetroMAE_BEIR')
71
+ model = AutoModel.from_pretrained('nthakur/RetroMAE_BEIR')
72
+
73
+ # Tokenize sentences
74
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
75
+
76
+ # Compute token embeddings
77
+ with torch.no_grad():
78
+ model_output = model(**encoded_input)
79
+
80
+ # Perform pooling. In this case, cls pooling.
81
+ sentence_embeddings = cls_pooling(model_output, encoded_input['attention_mask'])
82
+
83
+ print("Sentence embeddings:")
84
+ print(sentence_embeddings)
85
+ ```
86
+
87
+
88
+
89
+ ## Evaluation Results
90
+
91
+ <!--- Describe how your model was evaluated -->
92
+
93
+ For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name=nthakur/RetroMAE_BEIR)
94
+
95
+
96
+
97
+ ## Full Model Architecture
98
+ ```
99
+ SentenceTransformer(
100
+ (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
101
+ (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
102
+ )
103
+ ```
104
+
105
+ ## Citing & Authors
106
+ Have a look at [RetroMAE](https://github.com/staoxiao/RetroMAE/).
107
+ <!--- Describe where people can find more information -->
config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Shitao/RetroMAE_BEIR",
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": 768,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-12,
15
+ "max_position_embeddings": 512,
16
+ "model_type": "bert",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 0,
20
+ "position_embedding_type": "absolute",
21
+ "torch_dtype": "float32",
22
+ "transformers_version": "4.30.2",
23
+ "type_vocab_size": 2,
24
+ "use_cache": true,
25
+ "vocab_size": 30522
26
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.2.2",
4
+ "transformers": "4.30.2",
5
+ "pytorch": "2.0.1+cu117"
6
+ }
7
+ }
modules.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.models.Transformer"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Pooling",
12
+ "type": "sentence_transformers.models.Pooling"
13
+ }
14
+ ]
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f6a720644cfe4f41c317b73af9afb3aa837c7b3dbda0f54182a849fc3b36da1b
3
+ size 438000173
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 512,
3
+ "do_lower_case": false
4
+ }
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,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "clean_up_tokenization_spaces": true,
3
+ "cls_token": "[CLS]",
4
+ "do_basic_tokenize": true,
5
+ "do_lower_case": true,
6
+ "mask_token": "[MASK]",
7
+ "model_max_length": 512,
8
+ "never_split": null,
9
+ "pad_token": "[PAD]",
10
+ "sep_token": "[SEP]",
11
+ "strip_accents": null,
12
+ "tokenize_chinese_chars": true,
13
+ "tokenizer_class": "BertTokenizer",
14
+ "unk_token": "[UNK]"
15
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff