Fine-tuned
Qwen3-Embedding-4B with LoRA for Dutch/English retrieval on
EU AI Act documentation. Supports
Matryoshka embeddings (2560, 1024, 768, 512, 256, 128 dimensions) for flexible speed/quality tradeoffs.
Evaluated on 340 held-out queries across 85 chunks. All metrics measured with cosine similarity.
Stage 2 results are essentially equivalent to Stage 1 — the model was already near-ceiling after Stage 1 on this dataset.
1from sentence_transformers import SentenceTransformer
2
3model = SentenceTransformer("danielnoumon/qwen3-embedding-4b-ai-act-nl")
4
5# Qwen3 uses instruct prompts for queries, no prefix for documents
6queries = model.encode(
7 ["What are the obligations for high-risk AI systems?"],
8 prompt="Instruct: Given a question about EU AI regulation, retrieve the most relevant passage\nQuery:",
9)
10passages = model.encode([
11 "High-risk AI systems must comply with requirements in Chapter III...",
12 "The AI Act defines prohibited practices in Article 5...",
13])
14
15# Compute similarity
16from sentence_transformers.util import cos_sim
17scores = cos_sim(queries, passages)
1# Encode with full 2560 dimensions
2embeddings_2560 = model.encode(queries)
3
4# Truncate to 256 dimensions for faster search
5embeddings_256 = embeddings_2560[:, :256]
6
7# Or specify dimension at encoding time
8model.truncate_dim = 256
9embeddings_256 = model.encode(queries)
Qwen3 uses instruction-based prompting. Queries need the instruct prefix, documents do not:
1# Queries: use instruct prompt
2query_emb = model.encode(
3 ["your question here"],
4 prompt="Instruct: Given a question about EU AI regulation, retrieve the most relevant passage\nQuery:",
5)
6
7# Documents: no prefix needed
8doc_emb = model.encode(["your document here"])
1@misc{qwen3embedding,
2 title={Qwen3-Embedding: Advancing Text Embeddings with Qwen3},
3 author={Qwen Team},
4 year={2025},
5 url={https://huggingface.co/Qwen/Qwen3-Embedding-4B}
6}
7
8@inproceedings{reimers-2019-sentence-bert,
9 title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
10 author = "Reimers, Nils and Gurevych, Iryna",
11 booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
12 year = "2019",
13 url = "https://arxiv.org/abs/1908.10084",
14}
15
16@misc{kusupati2024matryoshka,
17 title={Matryoshka Representation Learning},
18 author={Aditya Kusupati and Gantavya Bhatt and Aniket Rege and Matthew Wallingford and Aditya Sinha and Vivek Ramanujan and William Howard-Snyder and Kaifeng Chen and Sham Kakade and Prateek Jain and Ali Farhadi},
19 year={2024},
20 eprint={2205.13147},
21 archivePrefix={arXiv},
22 primaryClass={cs.LG}
23}
24
25@misc{hu2022lora,
26 title={LoRA: Low-Rank Adaptation of Large Language Models},
27 author={Edward J. Hu and Yelong Shen and Phillip Wallis and Zeyuan Allen-Zhu and Yuanzhi Li and Shean Wang and Lu Wang and Weizhu Chen},
28 year={2022},
29 eprint={2106.09685},
30 archivePrefix={arXiv},
31 primaryClass={cs.CL}
32}