rawsh commited on
Commit
215d532
1 Parent(s): 1454eaf

Upload 8 files

Browse files
README.md ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: sentence-similarity
3
+ tags:
4
+ - sentence-transformers
5
+ - feature-extraction
6
+ - sentence-similarity
7
+ - transformers
8
+
9
+ ---
10
+
11
+ # {MODEL_NAME}
12
+
13
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 128 dimensional dense vector space and can be used for tasks like clustering or semantic search.
14
+
15
+ Based on `nreimers/BERT-Tiny_L-2_H-128_A-2`
16
+
17
+ Teacher: `multi-qa-MiniLM-L6-cos-v1`
18
+
19
+ Terrible performance but it's 5MB
20
+
21
+ ```
22
+ 2023-06-05 15:28:46 - EmbeddingSimilarityEvaluator: Evaluating the model on sts-dev dataset after epoch 0:
23
+ 2023-06-05 15:28:47 - Cosine-Similarity : Pearson: 0.7336 Spearman: 0.7582
24
+ 2023-06-05 15:28:47 - Manhattan-Distance: Pearson: 0.7960 Spearman: 0.7976
25
+ 2023-06-05 15:28:47 - Euclidean-Distance: Pearson: 0.7968 Spearman: 0.7984
26
+ 2023-06-05 15:28:47 - Dot-Product-Similarity: Pearson: 0.5599 Spearman: 0.5410
27
+ 2023-06-05 15:28:48 - MSE evaluation (lower = better) on dataset after epoch 0:
28
+ 2023-06-05 15:28:48 - MSE (*100): 0.152902
29
+ ```
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('{MODEL_NAME}')
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
+ #Mean Pooling - Take attention mask into account for correct averaging
63
+ def mean_pooling(model_output, attention_mask):
64
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
65
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
66
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
67
+
68
+
69
+ # Sentences we want sentence embeddings for
70
+ sentences = ['This is an example sentence', 'Each sentence is converted']
71
+
72
+ # Load model from HuggingFace Hub
73
+ tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
74
+ model = AutoModel.from_pretrained('{MODEL_NAME}')
75
+
76
+ # Tokenize sentences
77
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
78
+
79
+ # Compute token embeddings
80
+ with torch.no_grad():
81
+ model_output = model(**encoded_input)
82
+
83
+ # Perform pooling. In this case, mean pooling.
84
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
85
+
86
+ print("Sentence embeddings:")
87
+ print(sentence_embeddings)
88
+ ```
89
+
90
+
91
+
92
+ ## Evaluation Results
93
+
94
+ <!--- Describe how your model was evaluated -->
95
+
96
+ For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name={MODEL_NAME})
97
+
98
+
99
+ ## Training
100
+ The model was trained with the parameters:
101
+
102
+ **DataLoader**:
103
+
104
+ `torch.utils.data.dataloader.DataLoader` of length 141164 with parameters:
105
+ ```
106
+ {'batch_size': 64, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
107
+ ```
108
+
109
+ **Loss**:
110
+
111
+ `sentence_transformers.losses.MSELoss.MSELoss`
112
+
113
+ Parameters of the fit()-Method:
114
+ ```
115
+ {
116
+ "epochs": 1,
117
+ "evaluation_steps": 5000,
118
+ "evaluator": "sentence_transformers.evaluation.SequentialEvaluator.SequentialEvaluator",
119
+ "max_grad_norm": 1,
120
+ "optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
121
+ "optimizer_params": {
122
+ "eps": 1e-06,
123
+ "lr": 0.0001
124
+ },
125
+ "scheduler": "WarmupLinear",
126
+ "steps_per_epoch": null,
127
+ "warmup_steps": 1000,
128
+ "weight_decay": 0.01
129
+ }
130
+ ```
131
+
132
+
133
+ ## Full Model Architecture
134
+ ```
135
+ SentenceTransformer(
136
+ (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
137
+ (1): Pooling({'word_embedding_dimension': 128, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
138
+ )
139
+ ```
140
+
141
+ ## Citing & Authors
142
+
143
+ <!--- Describe where people can find more information -->
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "./bert-tiny-cos-v1",
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": 128,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 512,
14
+ "layer_norm_eps": 1e-12,
15
+ "max_position_embeddings": 512,
16
+ "model_type": "bert",
17
+ "num_attention_heads": 2,
18
+ "num_hidden_layers": 2,
19
+ "pad_token_id": 0,
20
+ "position_embedding_type": "absolute",
21
+ "transformers_version": "4.29.2",
22
+ "type_vocab_size": 2,
23
+ "use_cache": true,
24
+ "vocab_size": 30522
25
+ }
onnx/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d6ed996a9fe3d8e7a152cdaff987894a5e05c1f7ca3bd17a7540374fda861e6
3
+ size 17525122
onnx/model_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5884f99ff646e4be279d8834b705f8cd33ec5446bfae9fd882ac7b5ad273cec6
3
+ size 4469359
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