HebArabNlpProject/Semantic-Retrieval-1st-place
Hebrew Semantic Retrieval โ 1st Place Solution
Competition: Hebrew Semantic Retrieval Challenge by MAFAT DDR&D (Directorate of Defense Research & Development) in partnership with the Israel National NLP Program
Result: ๐ฅ 1st place โ nDCG@20 = 0.6736 (private test set)
Author: victord
Overview
This repository contains the complete inference code and fine-tuned models for the winning solution to the Hebrew Semantic Retrieval Challenge. The challenge tasked participants with building a semantic retrieval system capable of ranking Hebrew paragraphs from a large-scale corpus (127,731 paragraphs) in response to natural-language Hebrew queries, evaluated by NDCG@20.
Hebrew is a morphologically rich, Semitic language written in an almost consonant-only script, which creates high lexical ambiguity and makes retrieval significantly harder than in English or other high-resource languages. The challenge was designed to close this gap and advance Hebrew NLP for domains such as government services, law, academia, and the public sector.
The Challenge
Ground-truth labels were produced in two stages: a semantic retrieval model first retrieved the top-20 candidates per query, then human annotators rated them on a 0โ4 relevance scale.
Solution Architecture
The solution is a classic two-stage retrieve-then-rerank pipeline, built on top of a large ensemble of multilingual and Hebrew-specialized embedding models, combined with a sparse BM25 stage.
Query
โ
โโโบ [Dense Retriever ร6] โโโ
โ โโโบ Score Fusion (weighted, z-normalized)
โโโบ [BM25s Sparse] โโโโโโโโโโ
โ
โผ
Top-250 Candidates
โ
โผ
[BGE Cross-Encoder Reranker] (fine-tuned)
โ
โผ
Final Top-20 Results (ranked by fused score)Stage 1 โ Ensemble Dense + Sparse Retrieval
Six dense embedding models run in parallel. Each produces per-document cosine-similarity scores, which are z-score normalized (using pre-computed corpus statistics) and linearly fused with learned weights. BM25s contributes a 15 % weight in the final fusion.
Retriever fusion weights (normalized):
Long-document handling: For passages exceeding the model's max context length, a sliding-window chunking strategy with 50 % overlap is applied at the token level, and the maximum chunk score is used to represent the document.
Stage 2 โ Cross-Encoder Reranking
The top-250 candidates from Stage 1 are reranked by a fine-tuned BGE cross-encoder (bge-reranker-v2-m3, pseudo-fine-tuned on the challenge corpus). The reranker operates with a max sequence length of 2048 tokens using the same sliding-window + max-score strategy for long documents.
The final score is a blend of the reranker score and the Stage 1 fusion score:
$$\text{score}\text{final} = 0.35 \cdot \hat{s}\text{reranker} + 0.65 \cdot s_\text{fusion}$$
where $\hat{s}_\text{reranker}$ is z-score normalized. The top-20 documents by this blended score are returned.
Included Models (fine-tuned)
The remaining models (bge-m3, multilingual-e5-large-instruct, snowflake-arctic-embed-l-v2.0, Solon-embeddings-large-0.1, Webiks_Hebrew_RAGbot_KolZchut_QA_Embedder_v1.0) are used as-is (no additional fine-tuning).
Repository Structure
model.py โ Full inference pipeline (preprocess + predict)
models/
bge-m3/
bge-reranker-v2-m3_pseudo_tune_full/ โ Fine-tuned reranker โจ
multilingual-e5-large_pseudo_full/ โ Fine-tuned embedder โจ
multilingual-e5-large-instruct/
snowflake-arctic-embed-l-v2.0/
Solon-embeddings-large-0.1/
Webiks_Hebrew_RAGbot_KolZchut_QA_Embedder_v1.0/Usage
The pipeline exposes two functions that match the competition API:
from model import preprocess, predict
# Build corpus index (run once)
# corpus_dict: {doc_id: {"passage": "..."}, ...}
preprocessed = preprocess(corpus_dict)
# Query at inference time
results = predict({"query": "ืื ืืืืืืืช ืฉื ืฉืืืจื ืืืจื?"}, preprocessed)
# Returns: [{"paragraph_uuid": "...", "score": 0.92}, ...] (top-20)Requirements:
torch
transformers
sentence-transformers
bm25s
scikit-learn
numpyA CUDA-capable GPU is strongly recommended (the pipeline loads ~6 large models simultaneously).
Technical Notes
- All models are loaded in bfloat16 precision to reduce GPU memory footprint.
- Offline mode is enforced at runtime (
HF_HUB_OFFLINE=1) โ all model weights must be present locally. - BM25s tokenization uses the default
bm25stokenizer with no additional Hebrew-specific pre-processing. - The pipeline is time-budgeted: the reranker respects a ~1.85 s per-query wall-clock limit and will skip remaining batches if the budget is exceeded, gracefully falling back to Stage 1 scores.
- CUDA memory is proactively freed between batches; OOM errors trigger single-sample fallback processing.
Results
Citation
If you use this solution or the models in this repository, please acknowledge the Hebrew Semantic Retrieval Challenge by MAFAT DDR&D and the Israel National NLP Program, and credit victord as the solution author.
Acknowledgements
- MAFAT DDR&D and the Israel National NLP Program for organizing the challenge and providing the annotated Hebrew corpus.
- Webiks for the
Hebrew-RAGbot-KolZchut-QA-Embedder-v1.0model. - The authors of
multilingual-e5-large,bge-m3,bge-reranker-v2-m3,snowflake-arctic-embed-l-v2.0, andSolon-embeddings-large-0.1.
