論文閱讀 Qwen3 Embedding
論文地址:https://arxiv.org/pdf/2506.05176
Contribution
-
基於合成數據的 multi-stage 訓練
-
構建高質量合成數據
-
引入模型合併(model merging)
細節
模型
Embedding Models
-
所有嵌入模型均基於 Qwen3 基座大模型構建;
-
使用帶因果注意力(causal attention)的解碼式架構;
-
在輸入序列的末尾添加 [EOS],使用其最終一層 hidden state 作爲 embedding 表示;
-
支持帶指令輸入(instruction),格式爲:
{Instruction} {Query}<|endoftext|>; -
官方實驗顯示:相比無 instruction,指令式輸入能顯著提升效果;
-
支持 MRL。
Reranking Models
-
採用 point-wise reranking with LLMs within a single context:point-wise reranking 是指大型語言模型會對每個候選項單獨評估其與查詢的相關性,給出一個分數,然後根據這些分數進行排序。
-
支持 instruction 輸入,prompt 格式如下:
<|im_start|>system
Judge whether the Document meets the requirements based on the Query and the
Instruct provided. Note that the answer can only be "yes" or
"no".<|im_end|>
, →, →
<|im_start|>user
<Instruct>: {Instruction}
<Query>: {Query}
<Document>: {Document}<|im_end|>
<|im_start|>assistant
<think>\n\n</think>\n\n
訓練
訓練目標
Embedding 模型採用 InfoNCE 對比損失
-
InfoNCE loss 的目標是最大化正樣本對的相似度,同時最小化負樣本對的相似度。
-
負樣本包括硬負樣本、批內負樣本等
Reranking 模型採用 SFT(二分類交叉熵)損失
-
通過 SFT 訓練 LLM 作爲一個判別器,讓它逐項評估候選段落是否與查詢匹配。這種 point-wise reranking 方法不要求文檔之間直接比較,僅需模型判斷每個文檔的相關性強弱。
-
優化目標是最大化模型給正確標籤(yes/no)打的概率,也就是:
-
如果某個文檔是正例,標籤爲 “yes”,模型就應儘可能預測 “yes”;
-
如果是負例,標籤是 “no”,模型就應預測 “no”。
-
公式說明
-
q 表示查詢, d 表示 document。
-
P(q, d) 表示輸入提示(prompt),通常是拼接後的上下文,比如:“Q: ... D: ...”。
-
p(l \mid P(q, d)) 表示模型輸出標籤 l 的概率(通過 softmax 或 logit)。
-
l 表示監督標籤,“yes” 表示文檔與查詢相關,“no” 表示無關
Multi-stage training
分爲三階段:
第一階段:大規模的合成數據驅動的弱監督學習
Large-Scale Synthetic Data-Driven Weak Supervision Training
之前的 GTE, E5, BGE models 的數據主要來源於開源社區,Qwen3 的創新點在於使用基座模型來合成數據。根據不同維度的需要來生成,例如 task, language, length 和 difficulty。與開源數據相比,合成數據更加可控,具有多樣性。
第二階段:SFT 階段利用高質量合成數據進行監督學習
High-Quality Synthetic Data Utilization in Supervised Fine Tuning
對篩選出的高質量合成數據(相似度 > 0.7)和公開監督數據集(如 MS MARCO、MIRACL 等)進行監督訓練。
第三階段:模型合併(Model Merging)
在 SFT 之後,對篩選出的高質量合成數據(相似度 > 0.7)和公開監督數據集(如 MS MARCO、MIRACL 等)進行監督訓練。
注意:
Reranking 模型的訓練補不包含第一階段的弱監督訓練。
數據合成
Qwen3 的訓練體系引入了四類任務合成數據:
-
Retrieval(信息檢索)
-
Bitext Mining(比對挖掘)
-
Classification(分類)
-
Semantic Textual Similarity(STS,語義文本相似度)
數據合成使用的模型爲 Qwen3-32B,語料來源是 Qwen3 基座模型預訓練階段的多語言數據集。
以 Retrieval 任務數據合成爲例
數據合成分爲兩個階段:
-
配置階段(Configuration)
-
對合成的 query 使用大模型決定 “Question Type”, “Difficulty”, and “Character” 。
-
Characters 來源於 Persona Hub (Ge et al., 2024),,從角色庫中找出 top-5 的候選項
Template 如下:
Given a **Passage** and **Character**, select the appropriate option from
three fields: Character, Question_Type, Difficulty, and return the output
in JSON format.
First, select the Character who are likely to be interested in the Passage
from the candidates. Then select the Question_Type that the Character
might ask about the Passage; Finally, choose the Difficulty of the
possible question based on the Passage, the Character, and the
Question_Type.
Character: Given by input **Character**
Question_Type:
- keywords: ...
- acquire_knowledge: ...
- summary: ...
- yes_or_no: ...
- background: ...
Difficulty:
- high_school: ...
- university: ...
- phd: ...
Here are some examples
<Example1> <Example2> <Example3>
Now, generate the **output** based on the **Passage** and **Character** from
user, the **Passage** will be in {language} language and the **Character**
will be in English.
Ensure to generate only the JSON output with content in English.
**Passage**:
{passage}
**Character**:
{character}
拆解這個 prompt:
輸入:一段多語種文檔(Passage)和角色(Character)
使用 LLM(如 Qwen3-32B)生成:
-
Character:對該文檔感興趣的角色(從 Persona Hub 中檢索 Top-5 候選)
-
Question_Type:角色可能提出的問題類型(如關鍵詞、背景、摘要等)
-
Difficulty:問題的難度等級(高中 / 大學 / 博士)
輸出(JSON 格式):
{
"Character": "...",
"Question_Type": "...",
"Difficulty": "..."
}
- 查詢生成階段(Query Generation)
基於上述配置,LLM 生成一個自然語言查詢(Query),用於構造 (query, document) 檢索訓練對。
template 爲:
Given a **Character**, **Passage**, and **Requirement**, generate a query from
the **Character**'s perspective that satisfies the **Requirement** and can
be used to retrieve the **Passage**. Please return the result in JSON
format.
Here is an example:
<example>
Now, generate the **output** based on the **Character**, **Passage** and
**Requirement** from user, the **Passage** will be in {corpus_language}
language, the **Character** and **Requirement** will be in English.
Ensure to generate only the JSON output, with the key in English and the value
in {queries_language} language.
**Character**
{character}
**Passage**
{passage}
**Requirment**
- Type: {type};
- Difficulty: {difficulty};
- Length: the length of the generated sentences should be {length} words;
- Languange: the language in which the results are generated should be
{language} language;
拆解這個 prompt:
輸入:
-
Character:一個角色設定,代表提問者的身份、興趣或背景(如 “a university student interested in ancient Chinese astronomy”)。
-
Passage:一段多語種文檔,作爲檢索目標。
-
Requirement:一個結構化配置,包含:
-
Type:問題類型(如 keywords、summary、background 等); -
Difficulty:問題難度(如 high_school、university、phd); -
Length:生成的查詢長度(如 10、20、30 個詞); -
Language:生成查詢的語言(如 English、Chinese、Arabic 等)。
輸出:
-
僅輸出 JSON 格式;
-
JSON 的 key 爲英文,value 爲指定語言;
-
查詢必須從 Character 的視角出發,滿足指定的 Requirement,並能用於檢索該 Passage。
數據過濾
對每一對數據計算 cosine 相似度,選擇相似度大於 0.7 的數據作爲高質量數據。
數據
第一階段 Weakly Supervised Pre-Traning
-
數據來源:合成數據
-
數量:150M( 1 億 5 千萬)
第二階段 Supervised Fine Tuning
-
數據來源:MS MARCO, NQ, HotpotQA, NLI, Dureader, T2 -Ranking, SimCLUE, MIRACL, MLDR, Mr.TyDi, Multi-CPR, CodeSearchNet .etc + 高質量合成數據
-
數量:有標籤的數據:7M;合成數據:12M
評估和結果
Massive Multilingual Text Embedding Benchmark (MMTEB)
-
Qwen3-Embedding-4B/8B 模型表現最好
-
Qwen3-Embedding-0.6B 排在 Gemini-Embedding 之後,儘管只有 0.6B 的參數
消融實驗
-
僅僅在合成數據上訓練的 Qwen3-Embedding-0.6B 比最後的 Qwen3-Embedding-0.6B 模型效果要好。
-
把弱監督階段去掉的話,最後的性能會下降。
-
如果不進行合併,Qwen3-Embedding-0.6B 的性能會明顯下降;
術語和概念
因果注意力(Causal Attention)
Causal attention 是一種自迴歸注意力機制,模型在生成每個詞時只能看到它之前的詞。這種機制通過一個上三角的 attention mask 實現。
注意力機制的區別
Rerank 方法
-
Point-wise
-
優點:每個候選項獨立打分,效率高
-
缺點:缺乏全局比較能力
-
Pair-wise
-
優點:比較兩個候選項的相對優劣
-
缺點:計算複雜度高(O(n²))
-
List-wise
-
優點:同時考慮所有候選項整體排序
-
缺點:對 LLM 輸入長度要求高
MRL
(略)
spherical linear interpolation 球狀線性差值 (slerp)
(略)
其他
1. Persona Hub (地址:https://github.com/tencent-ailab/persona-hub)
我覺得這個項目很有意思,裏面有 3 億個擬人設定,例如環保主義者,歷史學家,自然愛好者,老師,地理學家,學生,歌唱家等第。想象一下在虛擬世界裏,這些人會幹什麼,會問什麼問題?
隨便看兩個人物設定:
對羅馬帝國感興趣的歷史學家:
A historian or a scholar who is interested in the history of the Roman Empire, particularly the early years and the impact of Christianity on society. They are knowledgeable about the persecution of Christians in the Roman Empire and the story of Saint Maurice, the Roman soldier who refused to participate in pagan sacrifices and was eventually martyred. They are also interested in the concept of honor, courage, and faithfulness to one's beliefs, which are reflected in the story of Saint Maurice.
對醫學術語感興趣的人:
A person who is interested in medical terms and their meanings, particularly those related to cancer and medicine. They are likely to be a medical professional, a researcher, or a student who is studying the field of cancer biology. They are knowledgeable about the NCI Dictionary of Cancer Terms and are interested in learning more about parathyroid cancer and its related terms.
2. 比對挖掘(bitext mining)
比對挖掘(Bitext Mining)是一種自動從不同語言的文本中找出互爲翻譯的句子對的技術。它廣泛應用於機器翻譯、跨語言信息檢索、多語言語料構建等領域。
-
裏面的 Bitext 是 bilingually aligned text。
-
例子
-
如果你有一組英文句子和一組中文句子,bitext mining 的目標就是自動識別出哪些英文句子和哪些中文句子是彼此的翻譯。
本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源:https://mp.weixin.qq.com/s/EZLPjgNl9eH-kzwAVXCTtQ