CoolFace
Modelpublic

Innovatewithapple/bert-dense-retriever

sourceHugging Facemitupdated 2mo agoView on Hugging Face
1likes31downloads
Model Card

license: mit language:

  • —en libraryname: transformers pipelinetag: feature-extraction tags:
  • —bert
  • —dense-retrieval
  • —semantic-search
  • —information-retrieval
  • —ms-marco
  • —faiss ---

BERT Dense Retriever

A dense semantic retrieval model fine-tuned on the MS MARCO Passage Ranking dataset using BERT-base-uncased.

The model encodes natural language queries and passages into dense vector embeddings that can be indexed with FAISS for efficient semantic search.

This repository contains the complete Hugging Face compatible model including tokenizer, configuration, and custom model implementation.


Model Details

Backbone

  • —BERT-base-uncased

Pooling

  • —Mean Pooling

Embedding Normalization

  • —L2 Normalization

Similarity Metric

  • —Cosine Similarity

Training Objective

  • —CrossEntropy Loss over the similarity matrix (InfoNCE-style retrieval objective)

Training Configuration

ParameterValue
OptimizerAdamW
Learning Rate2e-5
Batch Size32
Epochs10
Weight Decay0.01
Temperature0.05

Evaluation Results

ModelRecall@10MRRnDCG@10
BERT-base-uncased0.47930.28370.3301
Fine-tuned Dense Retriever0.96930.85210.8810

The fine-tuned model substantially improves retrieval quality on the evaluation set compared with the untuned BERT-base encoder.


📊 BEIR Evaluation Results

The table below compares the proposed retrieval pipeline against the BM25 baseline reported by the original BEIR benchmark.

DatasetRetrieval StrategyBM25 (BEIR) NDCG@10Pipeline NDCG@10Recall@10Recall@100Improvement
FEVERHybrid + Cross Encoder0.75300.97910.98730.9937+0.2261
QuoraDense + Cross Encoder0.78300.96860.98580.9938+0.1856
HotpotQADense + Cross Encoder0.60300.89770.88530.8960+0.2947
FiQADense + Cross Encoder0.23610.75120.8055—+0.5151
TREC-COVIDHybrid + Cross Encoder0.65590.68680.01810.1110+0.0309
Note: BM25 scores are taken from the original BEIR benchmark and are included as the lexical retrieval baseline for comparison.

🔍 Key Findings

  • —Strong zero-shot generalization across multiple retrieval domains.
  • —Significant improvements over the BEIR BM25 baseline on FEVER, Quora, HotpotQA, and FiQA.
  • —Hybrid retrieval (BM25 + Dense Retriever) improves retrieval quality for specialized biomedical documents in TREC-COVID.
  • —Cross-Encoder re-ranking substantially enhances the final ranking quality by leveraging full query-document interactions.

Usage

python
from transformers import AutoTokenizer, AutoModel

model_name = "Innovatewithapple/bert-dense-retriever"

tokenizer = AutoTokenizer.from_pretrained(model_name)

model = AutoModel.from_pretrained(
    model_name,
    trust_remote_code=True,
)

inputs = tokenizer(
    "What is deep learning?",
    return_tensors="pt"
)

embeddings = model(**inputs)

print(embeddings.shape)

Intended Use

This model is designed for:

  • —Dense semantic retrieval
  • —Semantic search
  • —Question-passage retrieval
  • —Retrieval-Augmented Generation (RAG)
  • —Information retrieval research

Source Code

GitHub Repository:

https://github.com/Innovatewithapple/dense-semantic-retrieval


Author

Mihir Vyas