---
title: contriever-msmarco
canonical_url: "https://www.modelscope.cn/models/facebook/contriever-msmarco"
md_url: "https://www.modelscope.cn/models/facebook/contriever-msmarco.md"
repository: facebook/contriever-msmarco
last_updated: 2025-05-20
pipeline_tag: feature-extraction
tasks:
  - feature-extraction
model_type:
  - bert
architectures:
  - Contriever
library_name:
  - pytorch
  - transformer
frameworks:
  - pytorch
inference_backends:
  - "deploy_task emb"
  - "sglang 0.5.2"
downloads: 712
stars: 1
tags:
  - feature-extraction
---

# contriever-msmarco

> contriever-msmarco - facebook 在 ModelScope 开源的模型。This model is the finetuned version of the pre-trained contriever model available here https://huggingface.co/facebook/contriever, following the approach described in Towards Unsupervised Dense Information…

facebook/contriever-msmarco 是 ModelScope 魔搭社区上的feature-extraction模型，可用 deploy_task emb、sglang 0.5.2 部署。

- **Repository**: facebook/contriever-msmarco
- **Tasks**: feature-extraction
- **Inference backends**: deploy_task emb, sglang 0.5.2
- **Tags**: feature-extraction
- **Downloads**: 712
- **Stars**: 1
- **Last updated**: 2025-05-20

Source: https://www.modelscope.cn/models/facebook/contriever-msmarco

---

This model is the finetuned version of the pre-trained contriever model available here https://huggingface.co/facebook/contriever, following the approach described in [Towards Unsupervised Dense Information Retrieval with Contrastive Learning](https://arxiv.org/abs/2112.09118). The associated GitHub repository is available here https://github.com/facebookresearch/contriever.

## Usage (HuggingFace Transformers)
Using the model directly available in HuggingFace transformers requires to add a mean pooling operation to obtain a sentence embedding.

```python
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 pooling
def mean_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'])
```
