Sparse Retrieval โ SPLADE & SparseEmbed
Collection
Learned sparse retrieval models: SPLADE and SparseEmbed checkpoints for first-stage neural search. โข 4 items โข Updated
Run raphaelsty/distilbert-splade on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Use HF Jobs to fine-tune https://huggingface.co/raphaelsty/distilbert-splade. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Use HF Jobs to run batch inference with https://huggingface.co/raphaelsty/distilbert-splade on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
How to use raphaelsty/distilbert-splade with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("fill-mask", model="raphaelsty/distilbert-splade") # pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForMaskedLM
tokenizer = AutoTokenizer.from_pretrained("raphaelsty/distilbert-splade")
model = AutoModelForMaskedLM.from_pretrained("raphaelsty/distilbert-splade", device_map="auto")This model was trained with Sparsembed. You can find details on how to use it in the Sparsembed repository.
pip install sparsembed
from sparsembed import model, retrieve
from transformers import AutoModelForMaskedLM, AutoTokenizer
device = "cuda" # cpu
batch_size = 10
# List documents to index:
documents = [
{'id': 0,
'title': 'Paris',
'url': 'https://en.wikipedia.org/wiki/Paris',
'text': 'Paris is the capital and most populous city of France.'},
{'id': 1,
'title': 'Paris',
'url': 'https://en.wikipedia.org/wiki/Paris',
'text': "Since the 17th century, Paris has been one of Europe's major centres of science, and arts."},
{'id': 2,
'title': 'Paris',
'url': 'https://en.wikipedia.org/wiki/Paris',
'text': 'The City of Paris is the centre and seat of government of the region and province of รle-de-France.'
}]
model = model.Splade(
model=AutoModelForMaskedLM.from_pretrained("raphaelsty/distilbert-splade").to(device),
tokenizer=AutoTokenizer.from_pretrained("raphaelsty/distilbert-splade"),
device=device
)
retriever = retrieve.SpladeRetriever(
key="id", # Key identifier of each document.
on=["title", "text"], # Fields to search.
model=model # Splade retriever.
)
retriever = retriever.add(
documents=documents,
batch_size=batch_size,
k_tokens=256, # Number of activated tokens.
)
retriever(
["paris", "Toulouse"], # Queries
k_tokens=20, # Maximum number of activated tokens.
k=100, # Number of documents to retrieve.
batch_size=batch_size
)