hanhainebula
commited on
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
@@ -1,3 +1,162 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Introduction
|
2 |
+
|
3 |
+
This respository introduces how to reproduce the `Dense`, `Sparse`, and `Dense+Sparse` evaluation results of the paper [BGE-M3](https://arxiv.org/pdf/2402.03216.pdf) on the [MIRACL](https://direct.mit.edu/tacl/article/doi/10.1162/tacl_a_00595/117438/MIRACL-A-Multilingual-Retrieval-Dataset-Covering) dev split.
|
4 |
+
|
5 |
+
## Requirements
|
6 |
+
|
7 |
+
```bash
|
8 |
+
# Install Java (Linux)
|
9 |
+
apt update
|
10 |
+
apt install openjdk-11-jdk
|
11 |
+
|
12 |
+
# Install Pyserini
|
13 |
+
pip install pyserini
|
14 |
+
|
15 |
+
# Install Faiss
|
16 |
+
## CPU version
|
17 |
+
conda install -c conda-forge faiss-cpu
|
18 |
+
|
19 |
+
## GPU version
|
20 |
+
conda install -c conda-forge faiss-gpu
|
21 |
+
```
|
22 |
+
|
23 |
+
**It should be noted that** the Pyserini code needs to be modified to support the multiple alpha settings in `pyserini/fusion`. I have already submitted a pull request to the official repository to support this feature. You can refer to this [PR]() to modify the code.
|
24 |
+
|
25 |
+
## 2CR
|
26 |
+
|
27 |
+
### Download and Unzip
|
28 |
+
|
29 |
+
```bash
|
30 |
+
# Download
|
31 |
+
## MIRACL topics and qrels
|
32 |
+
git clone https://huggingface.co/datasets/miracl/miracl
|
33 |
+
mv miracl/*/*/* topics-and-qrels
|
34 |
+
|
35 |
+
git lfs install
|
36 |
+
git clone https://huggingface.co/datasets/hanhainebula/bge-m3_miracl_2cr
|
37 |
+
|
38 |
+
|
39 |
+
# Unzip
|
40 |
+
languages=(ar bn en es fa fi fr hi id ja ko ru sw te th zh de yo)
|
41 |
+
|
42 |
+
## Dense
|
43 |
+
for lang in ${languages[@]}; do
|
44 |
+
tar -zxvf bge-m3_miracl_2cr/dense/${lang}.tar.gz -C bge-m3_miracl_2cr/dense/
|
45 |
+
done
|
46 |
+
|
47 |
+
## Sparse
|
48 |
+
for lang in ${languages[@]}; do
|
49 |
+
tar -zxvf bge-m3_miracl_2cr/sparse/${lang}.tar.gz -C bge-m3_miracl_2cr/sparse/
|
50 |
+
done
|
51 |
+
```
|
52 |
+
|
53 |
+
### Reproduction
|
54 |
+
|
55 |
+
#### Dense
|
56 |
+
|
57 |
+
```bash
|
58 |
+
# Avaliable Language: ar bn en es fa fi fr hi id ja ko ru sw te th zh de yo
|
59 |
+
lang=zh
|
60 |
+
|
61 |
+
# Generate run
|
62 |
+
python -m pyserini.search.faiss \
|
63 |
+
--threads 16 --batch-size 512 \
|
64 |
+
--encoder-class auto \
|
65 |
+
--encoder BAAI/bge-m3 \
|
66 |
+
--pooling cls --l2-norm \
|
67 |
+
--topics topics-and-qrels/miracl-v1.0-${lang}-dev.tsv \
|
68 |
+
--index bge-m3_miracl_2cr/dense/${lang} \
|
69 |
+
--output bge-m3_miracl_2cr/dense/runs/${lang}.txt \
|
70 |
+
--hits 1000
|
71 |
+
|
72 |
+
# Evaluate
|
73 |
+
## nDCG@10
|
74 |
+
python -m pyserini.eval.trec_eval \
|
75 |
+
-c -M 100 -m ndcg_cut.10 \
|
76 |
+
topics-and-qrels/qrels.miracl-v1.0-${lang}-dev.tsv \
|
77 |
+
bge-m3_miracl_2cr/dense/runs/${lang}.txt
|
78 |
+
## Recall@100
|
79 |
+
python -m pyserini.eval.trec_eval \
|
80 |
+
-c -m recall.100 \
|
81 |
+
topics-and-qrels/qrels.miracl-v1.0-${lang}-dev.tsv \
|
82 |
+
bge-m3_miracl_2cr/dense/runs/${lang}.txt
|
83 |
+
```
|
84 |
+
|
85 |
+
#### Sparse
|
86 |
+
|
87 |
+
```bash
|
88 |
+
# Avaliable Language: ar bn en es fa fi fr hi id ja ko ru sw te th zh de yo
|
89 |
+
lang=zh
|
90 |
+
|
91 |
+
# Generate run
|
92 |
+
python -m pyserini.search.lucene \
|
93 |
+
--threads 16 --batch-size 128 \
|
94 |
+
--topics bge-m3_miracl_2cr/sparse/${lang}/query_embd.tsv \
|
95 |
+
--index bge-m3_miracl_2cr/sparse/${lang}/index \
|
96 |
+
--output bge-m3_miracl_2cr/sparse/runs/${lang}.txt \
|
97 |
+
--output-format trec \
|
98 |
+
--impact --hits 1000
|
99 |
+
|
100 |
+
# Evaluate
|
101 |
+
## nDCG@10
|
102 |
+
python -m pyserini.eval.trec_eval \
|
103 |
+
-c -M 100 -m ndcg_cut.10 \
|
104 |
+
topics-and-qrels/qrels.miracl-v1.0-${lang}-dev.tsv \
|
105 |
+
bge-m3_miracl_2cr/sparse/runs/${lang}.txt
|
106 |
+
## Recall@100
|
107 |
+
python -m pyserini.eval.trec_eval \
|
108 |
+
-c -m recall.100 \
|
109 |
+
topics-and-qrels/qrels.miracl-v1.0-${lang}-dev.tsv \
|
110 |
+
bge-m3_miracl_2cr/sparse/runs/${lang}.txt
|
111 |
+
```
|
112 |
+
|
113 |
+
#### Dense+Sparse
|
114 |
+
|
115 |
+
**Note**: You should first merge this [PR]() to support the multiple alpha settings in `pyserini/fusion`.
|
116 |
+
|
117 |
+
```bash
|
118 |
+
# Avaliable Language: ar bn en es fa fi fr hi id ja ko ru sw te th zh de yo
|
119 |
+
lang=zh
|
120 |
+
|
121 |
+
# Generate dense run and sparse run
|
122 |
+
python -m pyserini.search.faiss \
|
123 |
+
--threads 16 --batch-size 512 \
|
124 |
+
--encoder-class auto \
|
125 |
+
--encoder BAAI/bge-m3 \
|
126 |
+
--pooling cls --l2-norm \
|
127 |
+
--topics topics-and-qrels/miracl-v1.0-${lang}-dev.tsv \
|
128 |
+
--index bge-m3_miracl_2cr/dense/${lang} \
|
129 |
+
--output bge-m3_miracl_2cr/dense/runs/${lang}.txt \
|
130 |
+
--hits 1000
|
131 |
+
|
132 |
+
python -m pyserini.search.lucene \
|
133 |
+
--threads 16 --batch-size 128 \
|
134 |
+
--topics bge-m3_miracl_2cr/sparse/${lang}/query_embd.tsv \
|
135 |
+
--index bge-m3_miracl_2cr/sparse/${lang}/index \
|
136 |
+
--output bge-m3_miracl_2cr/sparse/runs/${lang}.txt \
|
137 |
+
--output-format trec \
|
138 |
+
--impact --hits 1000
|
139 |
+
|
140 |
+
# Generate dense+sparse run
|
141 |
+
mkdir -p bge-m3_miracl_2cr/fusion/runs
|
142 |
+
|
143 |
+
python -m pyserini.fusion \
|
144 |
+
--method interpolation \
|
145 |
+
--runs bge-m3_miracl_2cr/dense/runs/${lang}.txt bge-m3_miracl_2cr/sparse/runs/${lang}.txt \
|
146 |
+
--alpha 1 3e-5 \
|
147 |
+
--output bge-m3_miracl_2cr/fusion/runs/${lang}.txt \
|
148 |
+
--depth 1000 --k 1000
|
149 |
+
|
150 |
+
# Evaluation
|
151 |
+
## nDCG@10
|
152 |
+
python -m pyserini.eval.trec_eval \
|
153 |
+
-c -M 100 -m ndcg_cut.10 \
|
154 |
+
topics-and-qrels/qrels.miracl-v1.0-${lang}-dev.tsv \
|
155 |
+
bge-m3_miracl_2cr/fusion/runs/${lang}.txt
|
156 |
+
## Recall@100
|
157 |
+
python -m pyserini.eval.trec_eval \
|
158 |
+
-c -m recall.100 \
|
159 |
+
topics-and-qrels/qrels.miracl-v1.0-${lang}-dev.tsv \
|
160 |
+
bge-m3_miracl_2cr/fusion/runs/${lang}.txt
|
161 |
+
```
|
162 |
+
|