yarden077 commited on
Commit
fb9bcb2
Β·
verified Β·
1 Parent(s): 4ea0491

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +198 -0
README.md ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - he
4
+ tags:
5
+ - hebrew
6
+ - semantic-retrieval
7
+ - information-retrieval
8
+ - dense-retrieval
9
+ - reranking
10
+ - ensemble
11
+ - sentence-transformers
12
+ - competition
13
+ pipeline_tag: sentence-similarity
14
+ license: other
15
+ ---
16
+
17
+ # Hebrew Semantic Retrieval β€” 1st Place Solution
18
+
19
+ **Competition:** [Hebrew Semantic Retrieval Challenge](https://www.codabench.org/) by [MAFAT DDR&D](https://www.mafat.org.il/) (Directorate of Defense Research & Development) in partnership with the **Israel National NLP Program**
20
+
21
+ **Result:** πŸ₯‡ **1st place** β€” nDCG@20 = **0.6736** (private test set)
22
+
23
+ **Author:** victord
24
+
25
+ ---
26
+
27
+ ## Overview
28
+
29
+ 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**.
30
+
31
+ 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.
32
+
33
+ ---
34
+
35
+ ## The Challenge
36
+
37
+ | Property | Detail |
38
+ |---|---|
39
+ | Organizer | MAFAT DDR&D + Israel National NLP Program |
40
+ | Corpus size | 127,731 Hebrew paragraphs |
41
+ | Data sources | Hebrew Wikipedia, Kol-Zchut (legal/civil-rights), Knesset committee protocols |
42
+ | Evaluation metric | NDCG@20 |
43
+ | Phase I | Public leaderboard (Codabench) |
44
+ | Phase II | Private test set with additional human annotation of previously unseen retrievals |
45
+ | Relevance scale | 0–4 (human annotated) |
46
+
47
+ 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.
48
+
49
+ ---
50
+
51
+ ## Solution Architecture
52
+
53
+ 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.
54
+
55
+ ```
56
+ Query
57
+ β”‚
58
+ β”œβ”€β–Ί [Dense Retriever Γ—6] ──┐
59
+ β”‚ β”œβ”€β–Ί Score Fusion (weighted, z-normalized)
60
+ └─► [BM25s Sparse] β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
61
+ β”‚
62
+ β–Ό
63
+ Top-250 Candidates
64
+ β”‚
65
+ β–Ό
66
+ [BGE Cross-Encoder Reranker] (fine-tuned)
67
+ β”‚
68
+ β–Ό
69
+ Final Top-20 Results (ranked by fused score)
70
+ ```
71
+
72
+ ### Stage 1 β€” Ensemble Dense + Sparse Retrieval
73
+
74
+ 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.
75
+
76
+ | Model | Role | Pooling | Max Length |
77
+ |---|---|---|---|
78
+ | `multilingual-e5-large` (pseudo-fine-tuned) | Primary dense retriever | Mean pooling + L2 norm | 512 |
79
+ | `multilingual-e5-large-instruct` | Instruct-style dense retriever | Mean pooling + L2 norm | 512 |
80
+ | `BAAI/bge-m3` | Multilingual dense retriever | CLS token + L2 norm | 512 |
81
+ | `Snowflake/snowflake-arctic-embed-l-v2.0` | Multilingual dense retriever | CLS token + L2 norm | 1024 |
82
+ | `OrdalieTech/Solon-embeddings-large-0.1` | Multilingual dense retriever | Mean pooling + L2 norm | 512 |
83
+ | `Webiks/Hebrew-RAGbot-KolZchut-QA-Embedder-v1.0` | Hebrew-specialized retriever | Mean pooling + L2 norm | 512 |
84
+ | **BM25s** | Sparse lexical retriever | β€” | β€” |
85
+
86
+ **Retriever fusion weights (normalized):**
87
+
88
+ | Retriever | Weight |
89
+ |---|---|
90
+ | E5-large (pseudo-tuned) | 1.10 |
91
+ | E5-large-instruct | 0.25 |
92
+ | BGE-M3 | 0.20 |
93
+ | Snowflake Arctic | 0.30 |
94
+ | Solon | 0.30 |
95
+ | Hebrew RAGbot | 0.30 |
96
+ | BM25s | 15 % blended into final fusion |
97
+
98
+ **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.
99
+
100
+ ### Stage 2 β€” Cross-Encoder Reranking
101
+
102
+ 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.
103
+
104
+ The final score is a blend of the reranker score and the Stage 1 fusion score:
105
+
106
+ $$\text{score}_\text{final} = 0.35 \cdot \hat{s}_\text{reranker} + 0.65 \cdot s_\text{fusion}$$
107
+
108
+ where $\hat{s}_\text{reranker}$ is z-score normalized. The top-20 documents by this blended score are returned.
109
+
110
+ ---
111
+
112
+ ## Included Models (fine-tuned)
113
+
114
+ | Path in repo | Base model | Fine-tuning |
115
+ |---|---|---|
116
+ | `models/multilingual-e5-large_pseudo_full/` | `intfloat/multilingual-e5-large` | Pseudo-label fine-tuning on the challenge corpus |
117
+ | `models/bge-reranker-v2-m3_pseudo_tune_full/` | `BAAI/bge-reranker-v2-m3` | Pseudo-label fine-tuning on the challenge corpus |
118
+
119
+ 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).
120
+
121
+ ---
122
+
123
+ ## Repository Structure
124
+
125
+ ```
126
+ model.py ← Full inference pipeline (preprocess + predict)
127
+ models/
128
+ bge-m3/
129
+ bge-reranker-v2-m3_pseudo_tune_full/ ← Fine-tuned reranker ✨
130
+ multilingual-e5-large_pseudo_full/ ← Fine-tuned embedder ✨
131
+ multilingual-e5-large-instruct/
132
+ snowflake-arctic-embed-l-v2.0/
133
+ Solon-embeddings-large-0.1/
134
+ Webiks_Hebrew_RAGbot_KolZchut_QA_Embedder_v1.0/
135
+ ```
136
+
137
+ ---
138
+
139
+ ## Usage
140
+
141
+ The pipeline exposes two functions that match the competition API:
142
+
143
+ ```python
144
+ from model import preprocess, predict
145
+
146
+ # Build corpus index (run once)
147
+ # corpus_dict: {doc_id: {"passage": "..."}, ...}
148
+ preprocessed = preprocess(corpus_dict)
149
+
150
+ # Query at inference time
151
+ results = predict({"query": "ΧžΧ” Χ”Χ–Χ›Χ•Χ™Χ•Χͺ של Χ©Χ•Χ›Χ¨Χ™ Χ“Χ™Χ¨Χ”?"}, preprocessed)
152
+ # Returns: [{"paragraph_uuid": "...", "score": 0.92}, ...] (top-20)
153
+ ```
154
+
155
+ **Requirements:**
156
+ ```
157
+ torch
158
+ transformers
159
+ sentence-transformers
160
+ bm25s
161
+ scikit-learn
162
+ numpy
163
+ ```
164
+
165
+ A CUDA-capable GPU is strongly recommended (the pipeline loads ~6 large models simultaneously).
166
+
167
+ ---
168
+
169
+ ## Technical Notes
170
+
171
+ - All models are loaded in **bfloat16** precision to reduce GPU memory footprint.
172
+ - **Offline mode** is enforced at runtime (`HF_HUB_OFFLINE=1`) β€” all model weights must be present locally.
173
+ - BM25s tokenization uses the default `bm25s` tokenizer with no additional Hebrew-specific pre-processing.
174
+ - 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.
175
+ - CUDA memory is proactively freed between batches; OOM errors trigger single-sample fallback processing.
176
+
177
+ ---
178
+
179
+ ## Results
180
+
181
+ | Phase | NDCG@20 | Rank |
182
+ |---|---|---|
183
+ | Public (Phase I) | β€” | πŸ₯‡ 1st |
184
+ | Private (Phase II) | **0.6736** | πŸ₯‡ 1st |
185
+
186
+ ---
187
+
188
+ ## Citation
189
+
190
+ 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.
191
+
192
+ ---
193
+
194
+ ## Acknowledgements
195
+
196
+ - [MAFAT DDR&D](https://www.mafat.org.il/) and the **Israel National NLP Program** for organizing the challenge and providing the annotated Hebrew corpus.
197
+ - [Webiks](https://www.webiks.com/) for the `Hebrew-RAGbot-KolZchut-QA-Embedder-v1.0` model.
198
+ - The authors of `multilingual-e5-large`, `bge-m3`, `bge-reranker-v2-m3`, `snowflake-arctic-embed-l-v2.0`, and `Solon-embeddings-large-0.1`.