Views
No views yet
Note: This is the query encoder. For inference, you also need the corresponding document encoder, which remains unchanged from the original SPLADE++ checkpoint. SPLADE can use asymmetric architecture: separate models for query and document representation.
The input format is a flattened version of the conversational history. q_n [SEP] a_{n-1} [SEP] q_{n-1} [SEP] ... [SEP] a_0 [SEP] q_0
1from transformers import AutoTokenizer, AutoModelForMaskedLM
2import torch.nn.functional as F
3import torch
4
5
6model = AutoModelForMaskedLM.from_pretrained("slupart/splade-disco-human")
7tokenizer = AutoTokenizer.from_pretrained("slupart/splade-disco-human")
8model.eval()
9
10conv = [
11 ("what's the weather like today?", "it's sunny."),
12 ("should I wear sunscreen?", "yes, UV index is high."),
13 ("do I need sunglasses?", "definitely."),
14 ("where can I buy sunglasses?", "try the optician nearby."),
15 ("how much do they cost?", None)
16]
17
18parts = [conv[-1][0]] + [x for q, a in reversed(conv[:-1]) for x in (a, q) if x]
19text = " [SEP] ".join(parts)
20
21inputs = tokenizer(text, return_tensors="pt")
22with torch.no_grad():
23 logits = model(**inputs).logits
24sparse = F.relu(logits).max(1).values.squeeze(0)
25
26scores = [(tokenizer.convert_ids_to_tokens([i.item()])[0], sparse[i].item())
27 for i in torch.nonzero(sparse).squeeze(1)]
28for token, score in sorted(scores, key=lambda x: -x[1]):
29 print(f"Token: {token:15} | Score: {score:.4f}")@article{lupart2024disco,
title={DiSCo Meets LLMs: A Unified Approach for Sparse Retrieval and Contextual Distillation in Conversational Search},
author={Lupart, Simon and Aliannejadi, Mohammad and Kanoulas, Evangelos},
journal={arXiv preprint arXiv:2410.14609},
year={2024}
}