CreaLabs commited on
Commit
9aa2ffa
verified
1 Parent(s): 17c4aad

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +101 -0
README.md ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Enhanced-BGE-M3-with-CLPL-and-MoE
2
+
3
+ This repository provides the code for applying Contrastive Learning Penalty Loss (CLPL) and Mixture of Experts (MoE) to the BGE-M3 text embedding model for enhanced information retrieval performance.
4
+
5
+ ## Contrastive Learning Penalty Loss (CLPL)
6
+
7
+ CLPL is a novel loss function designed to address the limitations of existing contrastive learning methods for improved performance in information retrieval tasks. It incorporates a penalty term that encourages the model to learn more discriminative representations by considering the similarity between negative samples and their corresponding queries.
8
+
9
+ The CLPL loss function is defined as follows:
10
+
11
+ ![CLPL formula](https://github.com/Dream-Forge-Studios/Enhanced-BGE-M3-with-CLPL-and-MoE/blob/main/imgs/clpl_formula.PNG?raw=true)
12
+
13
+ where:
14
+
15
+ * h<sub>i</sub>: The embedding of the query for the i-th instance.
16
+ * h<sub>i</sub><sup>+</sup>: The embedding of the positive sample for the i-th instance.
17
+ * H<sup>'</sup>: The set of negative samples for the i-th instance.
18
+ * h<sup>'</sup>: The embedding of the negative sample's query.
19
+ * H<sup>*</sup>: the set of positive queries for the documents corresponding to the negative samples
20
+ * sim(a, b): The cosine similarity function between embeddings a and b.
21
+ * 蟿: The temperature parameter.
22
+ * 位: The balancing parameter between the contrastive loss and the penalty term.
23
+
24
+ The difference between Contrastive Learning Loss and Contrastive Learning Penalty Loss:
25
+
26
+ ![CLPL figure](https://github.com/Dream-Forge-Studios/Enhanced-BGE-M3-with-CLPL-and-MoE/blob/main/imgs/figure1.PNG?raw=true)
27
+
28
+ ## Specs
29
+
30
+ - Model
31
+
32
+ | Model Name | Introduction |
33
+ |---|---|
34
+ | [bge-m3-ko-CLPL-interMoE](https://huggingface.co/CreaLabs/bge-m3-ko-CLPL-interMoE) | This model applies CLPL and MoE, trained on the MIRACL Korean training dataset. MoE is applied to the intermediate layer, and only the MoE layers were trained during fine-tuning. |
35
+ | [bge-m3-fa-CLPL-interMoE](https://huggingface.co/CreaLabs/bge-m3-fa-CLPL-interMoE) | This model applies CLPL and MoE, trained on the MIRACL Persian training dataset. MoE is applied to the intermediate layer, and only the MoE layers were trained during fine-tuning. |
36
+ | [bge-m3-hi-CLPL-interMoE](https://huggingface.co/CreaLabs/bge-m3-hi-CLPL-interMoE) | This model applies CLPL and MoE, trained on the MIRACL Hindi training dataset. MoE is applied to the intermediate layer, and only the MoE layers were trained during fine-tuning. |
37
+
38
+ - Data
39
+
40
+ Performing negative sampling using the ANCE methodology and generating negative sample's positive queries through the Gemini 1.5 Pro model, which are required for CLPL.
41
+
42
+ | Dataset | Introduction |
43
+ |---|---|
44
+ | [ko_CLPL_train_data](https://github.com/Dream-Forge-Studios/Enhanced-BGE-M3-with-CLPL-and-MoE/blob/main/data/ko_CLPL_train_data.jsonl) | MIRACL Korean CLPL training dataset |
45
+ | [fa_CLPL_train_data](https://github.com/Dream-Forge-Studios/Enhanced-BGE-M3-with-CLPL-and-MoE/blob/main/data/fa_CLPL_train_data.jsonl) | MIRACL Persian CLPL training dataset |
46
+ | [hi_CLPL_train_data](https://github.com/Dream-Forge-Studios/Enhanced-BGE-M3-with-CLPL-and-MoE/blob/main/data/hi_CLPL_train_data.jsonl) | MIRACL Hindi CLPL training dataset |
47
+
48
+ ## Usage
49
+
50
+ Install:
51
+
52
+ - train
53
+
54
+ git clone https://github.com/Dream-Forge-Studios/Enhanced-BGE-M3-with-CLPL-and-MoE.git
55
+ pip install -e .
56
+ pip install transformers==4.45.2
57
+ pip install sentencepiece
58
+ pip install protobuf
59
+ pip install simple_parsing
60
+
61
+ - evalution
62
+
63
+ pip install -U FlagEmbedding
64
+ pip install sentencepiece
65
+ pip install protobuf
66
+ pip install faiss-cpu
67
+ pip install faiss-gpu
68
+ pip install nmslib
69
+ pip install pyserini==0.22.1
70
+ pip install peft
71
+ pip install "numpy<2"
72
+ pip install --upgrade datasets
73
+ pip install simple_parsing
74
+
75
+ Execution:
76
+
77
+ - train
78
+
79
+ python run.py --output_dir CreaLabs/bge-m3-fa-CLPL-outputMoE --model_name_or_path BAAI/bge-m3 --train_data ./train_data --learning_rate 1e-5 --fp16 y --num_train_epochs 2 --per_device_train_batch_size 1 --gradient_accumulation_steps 4 --dataloader_drop_last True --normlized True --temperature 0.02 --query_max_len 128 --passage_max_len 512 --train_group_size 5 --logging_steps 10 --same_task_within_batch True --unified_finetuning False --use_self_distill False --only_train intermediate --moe intermediate --num_experts 2 --num_experts_per_tok 1
80
+
81
+ - evalution
82
+
83
+ python step0-generate_embedding.py --encoder CreaLabs/bge-m3-fa-CLPL-outputMoE --languages ko --index_save_dir ./corpus-index --max_passage_length 8192 --batch_size 4 --fp16 --pooling_method cls --normalize_embeddings True --moe intermediate
84
+ python step1-search_results.py --encoder CreaLabs/bge-m3-fa-CLPL-outputMoE --languages ko fa hi --index_save_dir ./corpus-index --result_save_dir /data/js/search_results --threads 4 --hits 20 --pooling_method cls --normalize_embeddings True --add_instruction False --moe intermediate
85
+ python step2-eval_dense_mldr.py --encoder CreaLabs/bge-m3-fa-CLPL-outputMoE --languages ko --search_result_save_dir ./search_results --qrels_dir ./qrels --eval_result_save_dir ./eval_results --metrics ndcg@5 ndcg@10 --pooling_method cls --normalize_embeddings True
86
+
87
+
88
+ ## Evaluation
89
+
90
+ ![Table 2](https://github.com/Dream-Forge-Studios/Enhanced-BGE-M3-with-CLPL-and-MoE/blob/main/imgs/table2.PNG?raw=true)
91
+
92
+ ## Citation
93
+
94
+ @misc{
95
+ title={Efficient Fine-tuning Methodology of Text Embedding Models for Information Retrieval: Contrastive Learning Penalty Loss (CLPL)},
96
+ author={Jeongsu YU},
97
+ year={2024},
98
+ eprint={},
99
+ archivePrefix={},
100
+ primaryClass={cs.CL}
101
+ }