Jerado commited on
Commit
c7b531e
1 Parent(s): f69ad92

Add new SentenceTransformer model.

Browse files
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ pytorch_model.bin filter=lfs diff=lfs merge=lfs -text
1_Pooling/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 384,
3
+ "pooling_mode_cls_token": false,
4
+ "pooling_mode_mean_tokens": true,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false
7
+ }
README.md ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: sentence-similarity
3
+ tags:
4
+ - sentence-transformers
5
+ - feature-extraction
6
+ - sentence-similarity
7
+ - transformers
8
+ datasets:
9
+ - train
10
+ - validation
11
+ - test
12
+ ---
13
+
14
+ # Jerado/all-MiniLM-L6-v2-finetuned
15
+
16
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search.
17
+
18
+ <!--- Describe your model here -->
19
+
20
+ ## Usage (Sentence-Transformers)
21
+
22
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
23
+
24
+ ```
25
+ pip install -U sentence-transformers
26
+ ```
27
+
28
+ Then you can use the model like this:
29
+
30
+ ```python
31
+ from sentence_transformers import SentenceTransformer
32
+ sentences = ["This is an example sentence", "Each sentence is converted"]
33
+
34
+ model = SentenceTransformer('Jerado/all-MiniLM-L6-v2-finetuned')
35
+ embeddings = model.encode(sentences)
36
+ print(embeddings)
37
+ ```
38
+
39
+
40
+
41
+ ## Usage (HuggingFace Transformers)
42
+ 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.
43
+
44
+ ```python
45
+ from transformers import AutoTokenizer, AutoModel
46
+ import torch
47
+
48
+
49
+ #Mean Pooling - Take attention mask into account for correct averaging
50
+ def mean_pooling(model_output, attention_mask):
51
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
52
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
53
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
54
+
55
+
56
+ # Sentences we want sentence embeddings for
57
+ sentences = ['This is an example sentence', 'Each sentence is converted']
58
+
59
+ # Load model from HuggingFace Hub
60
+ tokenizer = AutoTokenizer.from_pretrained('Jerado/all-MiniLM-L6-v2-finetuned')
61
+ model = AutoModel.from_pretrained('Jerado/all-MiniLM-L6-v2-finetuned')
62
+
63
+ # Tokenize sentences
64
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
65
+
66
+ # Compute token embeddings
67
+ with torch.no_grad():
68
+ model_output = model(**encoded_input)
69
+
70
+ # Perform pooling. In this case, mean pooling.
71
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
72
+
73
+ print("Sentence embeddings:")
74
+ print(sentence_embeddings)
75
+ ```
76
+
77
+
78
+
79
+ ## Evaluation Results
80
+
81
+ <!--- Describe how your model was evaluated -->
82
+
83
+ For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name=Jerado/all-MiniLM-L6-v2-finetuned)
84
+
85
+
86
+ ## Training
87
+ The model was trained with the parameters:
88
+
89
+ **DataLoader**:
90
+
91
+ `torch.utils.data.dataloader.DataLoader` of length 10 with parameters:
92
+ ```
93
+ {'batch_size': 32, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
94
+ ```
95
+
96
+ **Loss**:
97
+
98
+ `sentence_transformers.losses.MultipleNegativesRankingLoss.MultipleNegativesRankingLoss` with parameters:
99
+ ```
100
+ {'scale': 20.0, 'similarity_fct': 'cos_sim'}
101
+ ```
102
+
103
+ Parameters of the fit()-Method:
104
+ ```
105
+ {
106
+ "epochs": 10,
107
+ "evaluation_steps": 0,
108
+ "evaluator": "NoneType",
109
+ "max_grad_norm": 1,
110
+ "optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
111
+ "optimizer_params": {
112
+ "lr": 2e-05
113
+ },
114
+ "scheduler": "WarmupLinear",
115
+ "steps_per_epoch": null,
116
+ "warmup_steps": 10,
117
+ "weight_decay": 0.01
118
+ }
119
+ ```
120
+
121
+
122
+ ## Full Model Architecture
123
+ ```
124
+ SentenceTransformer(
125
+ (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
126
+ (1): Pooling({'word_embedding_dimension': 384, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
127
+ )
128
+ ```
129
+
130
+ ## Citing & Authors
131
+
132
+ <!--- Describe where people can find more information -->
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.25.1",
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.25.1",
5
+ "pytorch": "1.13.0+cu116"
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:e090be2e6dc4572a7bee0656e58065bed90fe41e47d681ba3310c6b38dfc2fd6
3
+ size 90891565
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,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": "/root/.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
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff