hsiuchilling
commited on
Commit
•
9a6d76f
1
Parent(s):
83e0610
Upload folder using huggingface_hub
Browse files- README.md +44 -0
- config.json +25 -0
- handler.py +47 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +1 -0
- tokenizer.json +0 -0
- tokenizer_config.json +1 -0
- vocab.txt +0 -0
README.md
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: cc-by-nc-sa-4.0
|
3 |
+
language: "en"
|
4 |
+
tags:
|
5 |
+
- splade
|
6 |
+
- query-expansion
|
7 |
+
- document-expansion
|
8 |
+
- bag-of-words
|
9 |
+
- passage-retrieval
|
10 |
+
- knowledge-distillation
|
11 |
+
- document encoder
|
12 |
+
datasets:
|
13 |
+
- ms_marco
|
14 |
+
---
|
15 |
+
## Efficient SPLADE
|
16 |
+
Efficient SPLADE model for passage retrieval. This architecture uses two distinct models for query and document inference. This is the **query** one, please also download the **doc** one (https://huggingface.co/naver/efficient-splade-VI-BT-large-doc). For additional details, please visit:
|
17 |
+
* paper: https://dl.acm.org/doi/10.1145/3477495.3531833
|
18 |
+
* code: https://github.com/naver/splade
|
19 |
+
| | MRR@10 (MS MARCO dev) | R@1000 (MS MARCO dev) | Latency (PISA) ms | Latency (Inference) ms
|
20 |
+
| --- | --- | --- | --- | --- |
|
21 |
+
| `naver/efficient-splade-V-large` | 38.8 | 98.0 | 29.0 | 45.3
|
22 |
+
| `naver/efficient-splade-VI-BT-large` | 38.0 | 97.8 | 31.1 | 0.7
|
23 |
+
## Citation
|
24 |
+
If you use our checkpoint, please cite our work:
|
25 |
+
```
|
26 |
+
@inproceedings{10.1145/3477495.3531833,
|
27 |
+
author = {Lassance, Carlos and Clinchant, St\'{e}phane},
|
28 |
+
title = {An Efficiency Study for SPLADE Models},
|
29 |
+
year = {2022},
|
30 |
+
isbn = {9781450387323},
|
31 |
+
publisher = {Association for Computing Machinery},
|
32 |
+
address = {New York, NY, USA},
|
33 |
+
url = {https://doi.org/10.1145/3477495.3531833},
|
34 |
+
doi = {10.1145/3477495.3531833},
|
35 |
+
abstract = {Latency and efficiency issues are often overlooked when evaluating IR models based on Pretrained Language Models (PLMs) in reason of multiple hardware and software testing scenarios. Nevertheless, efficiency is an important part of such systems and should not be overlooked. In this paper, we focus on improving the efficiency of the SPLADE model since it has achieved state-of-the-art zero-shot performance and competitive results on TREC collections. SPLADE efficiency can be controlled via a regularization factor, but solely controlling this regularization has been shown to not be efficient enough. In order to reduce the latency gap between SPLADE and traditional retrieval systems, we propose several techniques including L1 regularization for queries, a separation of document/query encoders, a FLOPS-regularized middle-training, and the use of faster query encoders. Our benchmark demonstrates that we can drastically improve the efficiency of these models while increasing the performance metrics on in-domain data. To our knowledge, we propose the first neural models that, under the same computing constraints, achieve similar latency (less than 4ms difference) as traditional BM25, while having similar performance (less than 10% MRR@10 reduction) as the state-of-the-art single-stage neural rankers on in-domain data.},
|
36 |
+
booktitle = {Proceedings of the 45th International ACM SIGIR Conference on Research and Development in Information Retrieval},
|
37 |
+
pages = {2220–2226},
|
38 |
+
numpages = {7},
|
39 |
+
keywords = {splade, latency, information retrieval, sparse representations},
|
40 |
+
location = {Madrid, Spain},
|
41 |
+
series = {SIGIR '22}
|
42 |
+
}
|
43 |
+
```
|
44 |
+
|
config.json
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/tmp-network/user/classanc/CoCodenser/flops_mlm_together/10_epochs/tinybert_256_128_0.001/",
|
3 |
+
"architectures": [
|
4 |
+
"BertForMaskedLM"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"hidden_act": "gelu",
|
9 |
+
"hidden_dropout_prob": 0.1,
|
10 |
+
"hidden_size": 128,
|
11 |
+
"initializer_range": 0.02,
|
12 |
+
"intermediate_size": 512,
|
13 |
+
"layer_norm_eps": 1e-12,
|
14 |
+
"max_position_embeddings": 512,
|
15 |
+
"model_type": "bert",
|
16 |
+
"num_attention_heads": 2,
|
17 |
+
"num_hidden_layers": 2,
|
18 |
+
"pad_token_id": 0,
|
19 |
+
"position_embedding_type": "absolute",
|
20 |
+
"torch_dtype": "float32",
|
21 |
+
"transformers_version": "4.11.3",
|
22 |
+
"type_vocab_size": 2,
|
23 |
+
"use_cache": true,
|
24 |
+
"vocab_size": 30522
|
25 |
+
}
|
handler.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, List, Dict
|
2 |
+
from pathlib import Path
|
3 |
+
|
4 |
+
import torch
|
5 |
+
from transformers import AutoModelForMaskedLM, AutoTokenizer
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
class EndpointHandler():
|
10 |
+
def __init__(self, path="."):
|
11 |
+
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
12 |
+
self.tokenizer = AutoTokenizer.from_pretrained(path)
|
13 |
+
self.model = AutoModelForMaskedLM.from_pretrained(path).to(self.device)
|
14 |
+
|
15 |
+
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
16 |
+
"""
|
17 |
+
Args:
|
18 |
+
data (:obj:):
|
19 |
+
includes the input data and the parameters for the inference.
|
20 |
+
Return:
|
21 |
+
A :obj:`list`:. The list contains the embeddings of the inference inputs
|
22 |
+
"""
|
23 |
+
inputs = data.get("inputs", data)
|
24 |
+
with torch.no_grad():
|
25 |
+
tokens = self.tokenizer(
|
26 |
+
inputs, padding=True, truncation=True, return_tensors='pt'
|
27 |
+
).to(self.device)
|
28 |
+
outputs = self.model(**tokens)
|
29 |
+
vecs = torch.max(
|
30 |
+
torch.log(
|
31 |
+
1 + torch.relu(outputs.logits)
|
32 |
+
) * tokens.attention_mask.unsqueeze(-1),
|
33 |
+
dim=1
|
34 |
+
)[0]
|
35 |
+
embeds = []
|
36 |
+
for vec in vecs:
|
37 |
+
# extract non-zero positions
|
38 |
+
cols = vec.nonzero().squeeze().cpu().tolist()
|
39 |
+
|
40 |
+
# extract the non-zero values
|
41 |
+
weights = vec[cols].cpu().tolist()
|
42 |
+
sparse = {
|
43 |
+
"indices": cols,
|
44 |
+
"values": weights,
|
45 |
+
}
|
46 |
+
embeds.append(sparse)
|
47 |
+
return embeds
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7d8415d9ac4d1d5ef92f005cbb5d39762fcd3e62cc83d946fb2adf4181955a8c
|
3 |
+
size 17687268
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"do_lower_case": true, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "do_basic_tokenize": true, "never_split": null, "special_tokens_map_file": null, "name_or_path": "/tmp-network/user/classanc/CoCodenser/flops_mlm_together/10_epochs/tinybert_256_128_0.001/", "tokenizer_class": "BertTokenizer"}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|