Raphael Sourty
commited on
Commit
•
51e0330
1
Parent(s):
b0d33be
upload
Browse files- README.md +58 -1
- config.json +25 -0
- linear.pt +3 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +23 -0
- vocab.txt +0 -0
README.md
CHANGED
@@ -1,3 +1,60 @@
|
|
1 |
---
|
2 |
-
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.SparsEmbed(
|
37 |
+
model=AutoModelForMaskedLM.from_pretrained("raphaelsty/sparsembed-max").to(device),
|
38 |
+
tokenizer=AutoTokenizer.from_pretrained("raphaelsty/sparsembed-max"),
|
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/sparsembed_max_frozen",
|
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 |
+
}
|
linear.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cf052e8af3766d810190f7dbd8e80261236df20aa6bc0cf4972201d7b351b13a
|
3 |
+
size 197352
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b4410c67ed44e716dce6b11f2c8bbb5a632d7e727635b122ce5d0449f0d002b2
|
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,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"clean_up_tokenization_spaces": true,
|
3 |
+
"cls_token": "[CLS]",
|
4 |
+
"device": "cuda",
|
5 |
+
"do_basic_tokenize": true,
|
6 |
+
"do_lower_case": true,
|
7 |
+
"mask_token": "[MASK]",
|
8 |
+
"max_length": 256,
|
9 |
+
"model_max_length": 512,
|
10 |
+
"never_split": null,
|
11 |
+
"pad_to_multiple_of": null,
|
12 |
+
"pad_token": "[PAD]",
|
13 |
+
"pad_token_type_id": 0,
|
14 |
+
"padding_side": "right",
|
15 |
+
"sep_token": "[SEP]",
|
16 |
+
"stride": 0,
|
17 |
+
"strip_accents": null,
|
18 |
+
"tokenize_chinese_chars": true,
|
19 |
+
"tokenizer_class": "DistilBertTokenizer",
|
20 |
+
"truncation_side": "right",
|
21 |
+
"truncation_strategy": "longest_first",
|
22 |
+
"unk_token": "[UNK]"
|
23 |
+
}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|