Commit
·
73496a3
1
Parent(s):
563db18
Fix models to be up to date with the changes
Browse files- README.md +1 -1
- config.json +0 -19
- modules.json +1 -1
- query_0_IDF/special_tokens_map.json +0 -37
- {query_0_IDF → query_0_SparseStaticEmbedding}/config.json +2 -2
- {query_0_IDF → query_0_SparseStaticEmbedding}/model.safetensors +1 -1
- query_0_SparseStaticEmbedding/special_tokens_map.json +7 -0
- {query_0_IDF → query_0_SparseStaticEmbedding}/tokenizer.json +2 -14
- {query_0_IDF → query_0_SparseStaticEmbedding}/tokenizer_config.json +58 -65
- {query_0_IDF → query_0_SparseStaticEmbedding}/vocab.txt +0 -0
- router_config.json +20 -0
- train_script.py +14 -10
README.md
CHANGED
|
@@ -372,7 +372,7 @@ This is a [Asymmetric Inference-free SPLADE Sparse Encoder](https://www.sbert.ne
|
|
| 372 |
```
|
| 373 |
SparseEncoder(
|
| 374 |
(0): Router(
|
| 375 |
-
(
|
| 376 |
(document_0_MLMTransformer): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM
|
| 377 |
(document_1_SpladePooling): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
|
| 378 |
)
|
|
|
|
| 372 |
```
|
| 373 |
SparseEncoder(
|
| 374 |
(0): Router(
|
| 375 |
+
(query_0_SparseStaticEmbedding): SparseStaticEmbedding ({'frozen': False}, dim:30522, tokenizer: BertTokenizerFast)
|
| 376 |
(document_0_MLMTransformer): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM
|
| 377 |
(document_1_SpladePooling): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
|
| 378 |
)
|
config.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"types": {
|
| 3 |
-
"query_0_IDF": "sentence_transformers.sparse_encoder.models.IDF",
|
| 4 |
-
"document_0_MLMTransformer": "sentence_transformers.sparse_encoder.models.MLMTransformer",
|
| 5 |
-
"document_1_SpladePooling": "sentence_transformers.sparse_encoder.models.SpladePooling"
|
| 6 |
-
},
|
| 7 |
-
"structure": {
|
| 8 |
-
"query": [
|
| 9 |
-
"query_0_IDF"
|
| 10 |
-
],
|
| 11 |
-
"document": [
|
| 12 |
-
"document_0_MLMTransformer",
|
| 13 |
-
"document_1_SpladePooling"
|
| 14 |
-
]
|
| 15 |
-
},
|
| 16 |
-
"parameters": {
|
| 17 |
-
"allow_empty_key": true
|
| 18 |
-
}
|
| 19 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modules.json
CHANGED
|
@@ -3,6 +3,6 @@
|
|
| 3 |
"idx": 0,
|
| 4 |
"name": "0",
|
| 5 |
"path": "",
|
| 6 |
-
"type": "sentence_transformers.models.
|
| 7 |
}
|
| 8 |
]
|
|
|
|
| 3 |
"idx": 0,
|
| 4 |
"name": "0",
|
| 5 |
"path": "",
|
| 6 |
+
"type": "sentence_transformers.models.Router"
|
| 7 |
}
|
| 8 |
]
|
query_0_IDF/special_tokens_map.json
DELETED
|
@@ -1,37 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cls_token": {
|
| 3 |
-
"content": "[CLS]",
|
| 4 |
-
"lstrip": false,
|
| 5 |
-
"normalized": false,
|
| 6 |
-
"rstrip": false,
|
| 7 |
-
"single_word": false
|
| 8 |
-
},
|
| 9 |
-
"mask_token": {
|
| 10 |
-
"content": "[MASK]",
|
| 11 |
-
"lstrip": false,
|
| 12 |
-
"normalized": false,
|
| 13 |
-
"rstrip": false,
|
| 14 |
-
"single_word": false
|
| 15 |
-
},
|
| 16 |
-
"pad_token": {
|
| 17 |
-
"content": "[PAD]",
|
| 18 |
-
"lstrip": false,
|
| 19 |
-
"normalized": false,
|
| 20 |
-
"rstrip": false,
|
| 21 |
-
"single_word": false
|
| 22 |
-
},
|
| 23 |
-
"sep_token": {
|
| 24 |
-
"content": "[SEP]",
|
| 25 |
-
"lstrip": false,
|
| 26 |
-
"normalized": false,
|
| 27 |
-
"rstrip": false,
|
| 28 |
-
"single_word": false
|
| 29 |
-
},
|
| 30 |
-
"unk_token": {
|
| 31 |
-
"content": "[UNK]",
|
| 32 |
-
"lstrip": false,
|
| 33 |
-
"normalized": false,
|
| 34 |
-
"rstrip": false,
|
| 35 |
-
"single_word": false
|
| 36 |
-
}
|
| 37 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{query_0_IDF → query_0_SparseStaticEmbedding}/config.json
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
{
|
| 2 |
-
"frozen": false
|
| 3 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"frozen": false
|
| 3 |
}
|
{query_0_IDF → query_0_SparseStaticEmbedding}/model.safetensors
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 122168
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:82ca927cba4916c595053947bfea48b28692538d894ab9f94cceca63f57a845a
|
| 3 |
size 122168
|
query_0_SparseStaticEmbedding/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 |
+
}
|
{query_0_IDF → query_0_SparseStaticEmbedding}/tokenizer.json
RENAMED
|
@@ -1,19 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"version": "1.0",
|
| 3 |
-
"truncation":
|
| 4 |
-
|
| 5 |
-
"max_length": 512,
|
| 6 |
-
"strategy": "LongestFirst",
|
| 7 |
-
"stride": 0
|
| 8 |
-
},
|
| 9 |
-
"padding": {
|
| 10 |
-
"strategy": "BatchLongest",
|
| 11 |
-
"direction": "Right",
|
| 12 |
-
"pad_to_multiple_of": null,
|
| 13 |
-
"pad_id": 0,
|
| 14 |
-
"pad_type_id": 0,
|
| 15 |
-
"pad_token": "[PAD]"
|
| 16 |
-
},
|
| 17 |
"added_tokens": [
|
| 18 |
{
|
| 19 |
"id": 0,
|
|
|
|
| 1 |
{
|
| 2 |
"version": "1.0",
|
| 3 |
+
"truncation": null,
|
| 4 |
+
"padding": null,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
"added_tokens": [
|
| 6 |
{
|
| 7 |
"id": 0,
|
{query_0_IDF → query_0_SparseStaticEmbedding}/tokenizer_config.json
RENAMED
|
@@ -1,65 +1,58 @@
|
|
| 1 |
-
{
|
| 2 |
-
"added_tokens_decoder": {
|
| 3 |
-
"0": {
|
| 4 |
-
"content": "[PAD]",
|
| 5 |
-
"lstrip": false,
|
| 6 |
-
"normalized": false,
|
| 7 |
-
"rstrip": false,
|
| 8 |
-
"single_word": false,
|
| 9 |
-
"special": true
|
| 10 |
-
},
|
| 11 |
-
"100": {
|
| 12 |
-
"content": "[UNK]",
|
| 13 |
-
"lstrip": false,
|
| 14 |
-
"normalized": false,
|
| 15 |
-
"rstrip": false,
|
| 16 |
-
"single_word": false,
|
| 17 |
-
"special": true
|
| 18 |
-
},
|
| 19 |
-
"101": {
|
| 20 |
-
"content": "[CLS]",
|
| 21 |
-
"lstrip": false,
|
| 22 |
-
"normalized": false,
|
| 23 |
-
"rstrip": false,
|
| 24 |
-
"single_word": false,
|
| 25 |
-
"special": true
|
| 26 |
-
},
|
| 27 |
-
"102": {
|
| 28 |
-
"content": "[SEP]",
|
| 29 |
-
"lstrip": false,
|
| 30 |
-
"normalized": false,
|
| 31 |
-
"rstrip": false,
|
| 32 |
-
"single_word": false,
|
| 33 |
-
"special": true
|
| 34 |
-
},
|
| 35 |
-
"103": {
|
| 36 |
-
"content": "[MASK]",
|
| 37 |
-
"lstrip": false,
|
| 38 |
-
"normalized": false,
|
| 39 |
-
"rstrip": false,
|
| 40 |
-
"single_word": false,
|
| 41 |
-
"special": true
|
| 42 |
-
}
|
| 43 |
-
},
|
| 44 |
-
"clean_up_tokenization_spaces": true,
|
| 45 |
-
"cls_token": "[CLS]",
|
| 46 |
-
"do_basic_tokenize": true,
|
| 47 |
-
"do_lower_case": true,
|
| 48 |
-
"extra_special_tokens": {},
|
| 49 |
-
"mask_token": "[MASK]",
|
| 50 |
-
"
|
| 51 |
-
"
|
| 52 |
-
"
|
| 53 |
-
"
|
| 54 |
-
"
|
| 55 |
-
"
|
| 56 |
-
"
|
| 57 |
-
"
|
| 58 |
-
|
| 59 |
-
"strip_accents": null,
|
| 60 |
-
"tokenize_chinese_chars": true,
|
| 61 |
-
"tokenizer_class": "BertTokenizer",
|
| 62 |
-
"truncation_side": "right",
|
| 63 |
-
"truncation_strategy": "longest_first",
|
| 64 |
-
"unk_token": "[UNK]"
|
| 65 |
-
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "[PAD]",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"100": {
|
| 12 |
+
"content": "[UNK]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"101": {
|
| 20 |
+
"content": "[CLS]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"102": {
|
| 28 |
+
"content": "[SEP]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"103": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"clean_up_tokenization_spaces": true,
|
| 45 |
+
"cls_token": "[CLS]",
|
| 46 |
+
"do_basic_tokenize": true,
|
| 47 |
+
"do_lower_case": true,
|
| 48 |
+
"extra_special_tokens": {},
|
| 49 |
+
"mask_token": "[MASK]",
|
| 50 |
+
"model_max_length": 512,
|
| 51 |
+
"never_split": null,
|
| 52 |
+
"pad_token": "[PAD]",
|
| 53 |
+
"sep_token": "[SEP]",
|
| 54 |
+
"strip_accents": null,
|
| 55 |
+
"tokenize_chinese_chars": true,
|
| 56 |
+
"tokenizer_class": "BertTokenizer",
|
| 57 |
+
"unk_token": "[UNK]"
|
| 58 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{query_0_IDF → query_0_SparseStaticEmbedding}/vocab.txt
RENAMED
|
File without changes
|
router_config.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"types": {
|
| 3 |
+
"query_0_SparseStaticEmbedding": "sentence_transformers.sparse_encoder.models.SparseStaticEmbedding.SparseStaticEmbedding",
|
| 4 |
+
"document_0_MLMTransformer": "sentence_transformers.sparse_encoder.models.MLMTransformer.MLMTransformer",
|
| 5 |
+
"document_1_SpladePooling": "sentence_transformers.sparse_encoder.models.SpladePooling.SpladePooling"
|
| 6 |
+
},
|
| 7 |
+
"structure": {
|
| 8 |
+
"query": [
|
| 9 |
+
"query_0_SparseStaticEmbedding"
|
| 10 |
+
],
|
| 11 |
+
"document": [
|
| 12 |
+
"document_0_MLMTransformer",
|
| 13 |
+
"document_1_SpladePooling"
|
| 14 |
+
]
|
| 15 |
+
},
|
| 16 |
+
"parameters": {
|
| 17 |
+
"default_route": "query",
|
| 18 |
+
"allow_empty_key": true
|
| 19 |
+
}
|
| 20 |
+
}
|
train_script.py
CHANGED
|
@@ -8,8 +8,8 @@ from sentence_transformers import (
|
|
| 8 |
from sentence_transformers.sparse_encoder.losses import SpladeLoss, SparseMultipleNegativesRankingLoss
|
| 9 |
from sentence_transformers.training_args import BatchSamplers
|
| 10 |
from sentence_transformers.sparse_encoder.evaluation import SparseNanoBEIREvaluator
|
| 11 |
-
from sentence_transformers.sparse_encoder.models import SpladePooling, MLMTransformer,
|
| 12 |
-
from sentence_transformers.models import
|
| 13 |
|
| 14 |
import logging
|
| 15 |
|
|
@@ -17,20 +17,24 @@ logging.basicConfig(format="%(asctime)s - %(message)s", datefmt="%Y-%m-%d %H:%M:
|
|
| 17 |
|
| 18 |
# 1. Load a model to finetune with 2. (Optional) model card data
|
| 19 |
mlm_transformer = MLMTransformer("prajjwal1/bert-tiny", tokenizer_args={"model_max_length": 512})
|
| 20 |
-
splade_pooling = SpladePooling(
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
|
| 27 |
model = SparseEncoder(
|
| 28 |
-
modules=[
|
| 29 |
model_card_data=SparseEncoderModelCardData(
|
| 30 |
language="en",
|
| 31 |
license="apache-2.0",
|
| 32 |
model_name="Inference-free SPLADE BERT-tiny trained on Natural-Questions tuples",
|
| 33 |
-
)
|
| 34 |
)
|
| 35 |
|
| 36 |
# 3. Load a dataset to finetune on
|
|
@@ -97,4 +101,4 @@ dev_evaluator(model)
|
|
| 97 |
model.save_pretrained(f"models/{run_name}/final")
|
| 98 |
|
| 99 |
# 10. (Optional) Push it to the Hugging Face Hub
|
| 100 |
-
model.push_to_hub(run_name)
|
|
|
|
| 8 |
from sentence_transformers.sparse_encoder.losses import SpladeLoss, SparseMultipleNegativesRankingLoss
|
| 9 |
from sentence_transformers.training_args import BatchSamplers
|
| 10 |
from sentence_transformers.sparse_encoder.evaluation import SparseNanoBEIREvaluator
|
| 11 |
+
from sentence_transformers.sparse_encoder.models import SpladePooling, MLMTransformer, SparseStaticEmbedding
|
| 12 |
+
from sentence_transformers.models import Router
|
| 13 |
|
| 14 |
import logging
|
| 15 |
|
|
|
|
| 17 |
|
| 18 |
# 1. Load a model to finetune with 2. (Optional) model card data
|
| 19 |
mlm_transformer = MLMTransformer("prajjwal1/bert-tiny", tokenizer_args={"model_max_length": 512})
|
| 20 |
+
splade_pooling = SpladePooling(
|
| 21 |
+
pooling_strategy="max", word_embedding_dimension=mlm_transformer.get_sentence_embedding_dimension()
|
| 22 |
+
)
|
| 23 |
|
| 24 |
+
router = Router(
|
| 25 |
+
{
|
| 26 |
+
"query": [SparseStaticEmbedding(tokenizer=mlm_transformer.tokenizer, frozen=False)],
|
| 27 |
+
"document": [mlm_transformer, splade_pooling],
|
| 28 |
+
}
|
| 29 |
+
)
|
| 30 |
|
| 31 |
model = SparseEncoder(
|
| 32 |
+
modules=[router],
|
| 33 |
model_card_data=SparseEncoderModelCardData(
|
| 34 |
language="en",
|
| 35 |
license="apache-2.0",
|
| 36 |
model_name="Inference-free SPLADE BERT-tiny trained on Natural-Questions tuples",
|
| 37 |
+
),
|
| 38 |
)
|
| 39 |
|
| 40 |
# 3. Load a dataset to finetune on
|
|
|
|
| 101 |
model.save_pretrained(f"models/{run_name}/final")
|
| 102 |
|
| 103 |
# 10. (Optional) Push it to the Hugging Face Hub
|
| 104 |
+
model.push_to_hub(run_name)
|