Using the model directly available in HuggingFace transformers requires to add a mean pooling operation to obtain a sentence embedding.
import torch
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained('facebook/contriever-msmarco')
model = AutoModel.from_pretrained('facebook/contriever-msmarco')
sentences = [
"Where was Marie Curie born?",
"Maria Sklodowska, later known as Marie Curie, was born on November 7, 1867.",
"Born in Paris on 15 May 1859, Pierre Curie was the son of Eugène Curie, a doctor of French Catholic origin from Alsace."
]
# Apply tokenizer
inputs = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
# Compute token embeddings
outputs = model(**inputs)
# Mean poolingdefmean_pooling(token_embeddings, mask):
token_embeddings = token_embeddings.masked_fill(~mask[..., None].bool(), 0.)
sentence_embeddings = token_embeddings.sum(dim=1) / mask.sum(dim=1)[..., None]
return sentence_embeddings
embeddings = mean_pooling(outputs[0], inputs['attention_mask'])
Runs of facebook contriever-msmarco on huggingface.co
231.8K
Total runs
3.4K
24-hour runs
22.2K
3-day runs
114.5K
7-day runs
213.0K
30-day runs
More Information About contriever-msmarco huggingface.co Model
contriever-msmarco huggingface.co
contriever-msmarco huggingface.co is an AI model on huggingface.co that provides contriever-msmarco's model effect (), which can be used instantly with this facebook contriever-msmarco model. huggingface.co supports a free trial of the contriever-msmarco model, and also provides paid use of the contriever-msmarco. Support call contriever-msmarco model through api, including Node.js, Python, http.
contriever-msmarco huggingface.co is an online trial and call api platform, which integrates contriever-msmarco's modeling effects, including api services, and provides a free online trial of contriever-msmarco, you can try contriever-msmarco online for free by clicking the link below.
facebook contriever-msmarco online free url in huggingface.co:
contriever-msmarco is an open source model from GitHub that offers a free installation service, and any user can find contriever-msmarco on GitHub to install. At the same time, huggingface.co provides the effect of contriever-msmarco install, users can directly use contriever-msmarco installed effect in huggingface.co for debugging and trial. It also supports api for free installation.