Raphael Sourty
commited on
Commit
•
20358c1
1
Parent(s):
6b1ff7f
upload
Browse files- README.md +60 -0
- config.json +25 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +21 -0
- vocab.txt +0 -0
README.md
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
---
|
5 |
+
|
6 |
+
This model was trained with [Sparsembed](https://github.com/raphaelsty/sparsembed). You can find details on how to use it in the [Sparsembed](https://github.com/raphaelsty/sparsembed) repository.
|
7 |
+
|
8 |
+
```sh
|
9 |
+
pip install sparsembed
|
10 |
+
```
|
11 |
+
|
12 |
+
```python
|
13 |
+
from sparsembed import model, retrieve
|
14 |
+
from transformers import AutoModelForMaskedLM, AutoTokenizer
|
15 |
+
|
16 |
+
device = "cuda" # cpu
|
17 |
+
|
18 |
+
batch_size = 10
|
19 |
+
|
20 |
+
# List documents to index:
|
21 |
+
documents = [
|
22 |
+
{'id': 0,
|
23 |
+
'title': 'Paris',
|
24 |
+
'url': 'https://en.wikipedia.org/wiki/Paris',
|
25 |
+
'text': 'Paris is the capital and most populous city of France.'},
|
26 |
+
{'id': 1,
|
27 |
+
'title': 'Paris',
|
28 |
+
'url': 'https://en.wikipedia.org/wiki/Paris',
|
29 |
+
'text': "Since the 17th century, Paris has been one of Europe's major centres of science, and arts."},
|
30 |
+
{'id': 2,
|
31 |
+
'title': 'Paris',
|
32 |
+
'url': 'https://en.wikipedia.org/wiki/Paris',
|
33 |
+
'text': 'The City of Paris is the centre and seat of government of the region and province of Île-de-France.'
|
34 |
+
}]
|
35 |
+
|
36 |
+
model = model.Splade(
|
37 |
+
model=AutoModelForMaskedLM.from_pretrained("raphaelsty/distilbert-splade").to(device),
|
38 |
+
tokenizer=AutoTokenizer.from_pretrained("raphaelsty/distilbert-splade"),
|
39 |
+
device=device
|
40 |
+
)
|
41 |
+
|
42 |
+
retriever = retrieve.SpladeRetriever(
|
43 |
+
key="id", # Key identifier of each document.
|
44 |
+
on=["title", "text"], # Fields to search.
|
45 |
+
model=model # Splade retriever.
|
46 |
+
)
|
47 |
+
|
48 |
+
retriever = retriever.add(
|
49 |
+
documents=documents,
|
50 |
+
batch_size=batch_size,
|
51 |
+
k_tokens=256, # Number of activated tokens.
|
52 |
+
)
|
53 |
+
|
54 |
+
retriever(
|
55 |
+
["paris", "Toulouse"], # Queries
|
56 |
+
k_tokens=20, # Maximum number of activated tokens.
|
57 |
+
k=100, # Number of documents to retrieve.
|
58 |
+
batch_size=batch_size
|
59 |
+
)
|
60 |
+
```
|
config.json
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "./drive/MyDrive/GPU/data/splade",
|
3 |
+
"activation": "gelu",
|
4 |
+
"architectures": [
|
5 |
+
"DistilBertForMaskedLM"
|
6 |
+
],
|
7 |
+
"attention_dropout": 0.1,
|
8 |
+
"dim": 768,
|
9 |
+
"dropout": 0.1,
|
10 |
+
"hidden_dim": 3072,
|
11 |
+
"initializer_range": 0.02,
|
12 |
+
"max_position_embeddings": 512,
|
13 |
+
"model_type": "distilbert",
|
14 |
+
"n_heads": 12,
|
15 |
+
"n_layers": 6,
|
16 |
+
"output_hidden_states": true,
|
17 |
+
"pad_token_id": 0,
|
18 |
+
"qa_dropout": 0.1,
|
19 |
+
"seq_classif_dropout": 0.2,
|
20 |
+
"sinusoidal_pos_embds": false,
|
21 |
+
"tie_weights_": true,
|
22 |
+
"torch_dtype": "float32",
|
23 |
+
"transformers_version": "4.32.0",
|
24 |
+
"vocab_size": 30522
|
25 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ba454feb077191ba727bceba740ff00616d6570425190c34449f9664325f260e
|
3 |
+
size 267978033
|
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,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"clean_up_tokenization_spaces": true,
|
3 |
+
"cls_token": "[CLS]",
|
4 |
+
"device": "cuda",
|
5 |
+
"do_lower_case": true,
|
6 |
+
"mask_token": "[MASK]",
|
7 |
+
"max_length": 256,
|
8 |
+
"model_max_length": 512,
|
9 |
+
"pad_to_multiple_of": null,
|
10 |
+
"pad_token": "[PAD]",
|
11 |
+
"pad_token_type_id": 0,
|
12 |
+
"padding_side": "right",
|
13 |
+
"sep_token": "[SEP]",
|
14 |
+
"stride": 0,
|
15 |
+
"strip_accents": null,
|
16 |
+
"tokenize_chinese_chars": true,
|
17 |
+
"tokenizer_class": "DistilBertTokenizer",
|
18 |
+
"truncation_side": "right",
|
19 |
+
"truncation_strategy": "longest_first",
|
20 |
+
"unk_token": "[UNK]"
|
21 |
+
}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|