Yuki131 commited on
Commit
874b09f
·
verified ·
1 Parent(s): a4a7125

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +125 -3
README.md CHANGED
@@ -1,3 +1,125 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+
5
+ <h1 align="center">KaLM-Embedding-V2</h1>
6
+
7
+
8
+ **KaLM-Embedding-V2** is a versatile and compact embedding model, which achieves impressive performance in general-purpose text embedding tasks by leveraging superior training techniques and data.
9
+
10
+ KaLM-embedding-multilingual-mini-instruct-v2 is trained from [Qwen/Qwen2-0.5B](https://huggingface.co/Qwen/Qwen2-0.5B) with massive weakly-supervised pre-training and high-quality supervised fine-tuning data.
11
+
12
+ The model incorporates several innovative designs:
13
+ - Architectural Design: integration of bidirectional attention, enhancing representation learning.
14
+ - Training Recipe: multi-stage training strategy, progressively improving the generalization and performance.
15
+ - Training Objective: focal-style reweighting mechanism and online hard-negative mixing strategy to improve the efficiency and continuity of embedding training.
16
+ - Training Data: 20 categories of data for pre-training and 100 categories of data for fine-tuning, as well as comprehensive recipes for curating training datasets.
17
+
18
+ ## Model Information
19
+ - Model Size: 0.5B
20
+ - Embedding Dimension: 896
21
+ - Max Input Tokens: 32k
22
+ - MLR: 896 512 256 128 64
23
+
24
+ ## 📑 Open-source Plan
25
+
26
+ - [x] Model Checkpoint
27
+ - [x] [KaLM-embedding-multilingual-mini-v1](https://huggingface.co/HIT-TMG/KaLM-embedding-multilingual-mini-v1)
28
+ - [x] [KaLM-embedding-multilingual-mini-instruct-v1](https://huggingface.co/HIT-TMG/KaLM-embedding-multilingual-mini-instruct-v1)
29
+ - [x] [KaLM-embedding-multilingual-mini-instruct-v1.5](https://huggingface.co/HIT-TMG/KaLM-embedding-multilingual-mini-instruct-v1.5)
30
+ - [x] [KaLM-embedding-multilingual-mini-instruct-v2](https://huggingface.co/HIT-TMG/KaLM-embedding-multilingual-mini-instruct-v2)
31
+ - [x] Training and Evaluation Code: [HITsz-TMG/KaLM-Embedding](https://github.com/HITsz-TMG/KaLM-Embedding)
32
+ - [x] Technical Report: [KaLM-Embedding-V2: Superior Training Techniques and Data Inspire A Versatile Embedding Model](https://arxiv.org/abs/2501.01028)
33
+ - [ ] Training Data
34
+
35
+
36
+ ## Evaluation
37
+ ### Overall results on MTEB (cmn, v1) and MTEB (eng, v1).
38
+ ![overall](./imgs/overall.jpg)
39
+
40
+ ### Detailed model performance on MTEB (cmn, v1).
41
+ ![mteb_cmn](./imgs/mteb_cmn.jpg)
42
+
43
+ ### Detailed model performance on MTEB (eng, v1).
44
+ ![mteb_cmn](./imgs/mteb_eng.jpg)
45
+
46
+ ## Requirements
47
+ Since we have used the Qwen2 model, we advise you to install `transformers>=4.37.0`, or you might encounter the following error:
48
+ ```
49
+ KeyError: 'qwen2'
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
55
+
56
+ ```
57
+ pip install -U sentence-transformers
58
+ ```
59
+
60
+ Then you can use the model like this:
61
+
62
+ ```python
63
+ from sentence_transformers import SentenceTransformer
64
+
65
+
66
+ sentences = ["This is an example sentence", "Each sentence is converted"]
67
+
68
+ model = SentenceTransformer("{MODEL_NAME_OR_PATH}", trust_remote_code=True, model_kwargs={"torch_dtype": torch.bfloat16, "attn_implementation": "flash_attention_2"})
69
+ model.max_seq_length = 512
70
+
71
+ embeddings = model.encode(
72
+ sentences,
73
+ normalize_embeddings=True,
74
+ batch_size=256,
75
+ show_progress_bar=True
76
+ )
77
+ print(embeddings)
78
+ ```
79
+
80
+ We add task instructions for asymmetric tasks: retrieval, reranking, classification, and clustering.
81
+ And, we add task instructions for both queries and passages in symmetric tasks, including STS and pair classification.
82
+ If you want to add task instructions to the query, you can use the model like this:
83
+
84
+ ```python
85
+ from sentence_transformers import SentenceTransformer
86
+
87
+
88
+ sentences = ["This is an example sentence", "Each sentence is converted"]
89
+
90
+ model = SentenceTransformer("{MODEL_NAME_OR_PATH}", trust_remote_code=True, model_kwargs={"torch_dtype": torch.bfloat16, "attn_implementation": "flash_attention_2"})
91
+ model.max_seq_length = 512
92
+
93
+ prompt = "Instruct: Classifying the category of french news. \n Query: "
94
+ embeddings = model.encode(
95
+ sentences,
96
+ prompt=prompt,
97
+ normalize_embeddings=True,
98
+ batch_size=256,
99
+ show_progress_bar=True
100
+ )
101
+ print(embeddings)
102
+ ```
103
+
104
+
105
+ ## Citation
106
+ If you find this model useful, please consider giving a star and citation.
107
+ ```
108
+ @article{zhao2025kalmv2,
109
+ title={KaLM-Embedding-V2: Superior Training Techniques and Data Inspire A Versatile Embedding Model},
110
+ author={},
111
+ journal={},
112
+ year={2025}
113
+ }
114
+
115
+ @article{hu2025kalm,
116
+ title={KaLM-Embedding: Superior Training Data Brings A Stronger Embedding Model},
117
+ author={Hu, Xinshuo and Shan, Zifei and Zhao, Xinping and Sun, Zetian and Liu, Zhenyu and Li, Dongfang and Ye, Shaolin and Wei, Xinyuan and Chen, Qian and Hu, Baotian and others},
118
+ journal={arXiv preprint arXiv:2501.01028},
119
+ year={2025}
120
+ }
121
+ ```
122
+
123
+
124
+ ## Contact
125
+ If you encounter any issue, feel free to contact us via the email: <[email protected]>, <[email protected]>