mirianokradze commited on
Commit
e82acef
·
verified ·
1 Parent(s): 7848307

Desearch Embedding 4B

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
1_Pooling/config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "embedding_dimension": 2560,
3
+ "pooling_mode": "lasttoken",
4
+ "include_prompt": true
5
+ }
README.md ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: Qwen/Qwen3-Embedding-4B
4
+ library_name: sentence-transformers
5
+ pipeline_tag: sentence-similarity
6
+ language:
7
+ - en
8
+ tags:
9
+ - sentence-transformers
10
+ - text-embeddings
11
+ - retrieval
12
+ - web-search
13
+ - news
14
+ - peft
15
+ ---
16
+
17
+ # Desearch Embedding 4B
18
+
19
+ Desearch Embedding 4B is a text embedding model for web and news search, developed by
20
+ [Desearch](https://desearch.ai). It is fine-tuned from [Qwen/Qwen3-Embedding-4B](https://huggingface.co/Qwen/Qwen3-Embedding-4B)
21
+ and maps search queries and web documents into a shared vector space for first-stage retrieval.
22
+
23
+ ## Highlights
24
+
25
+ - **Built for news and the open web.** Fine-tuned on recent news coverage, reference pages and
26
+ encyclopedic articles, the content a web search engine has to rank every day.
27
+ - **Real queries in every form.** Short keyword searches, natural-language questions, noisy
28
+ queries, questions about dated news events, and multi-hop questions that combine facts from
29
+ linked pages.
30
+ - **One model for chunks and whole pages.** Documents are seen as paragraph chunks, page openings
31
+ and full pages, the units a search index stores.
32
+ - **Binary first-stage ready.** Trained with a binary objective on the leading 256 dimensions, for
33
+ search stacks that shortlist with compact binary vectors before rescoring with full vectors.
34
+
35
+ ## Model details
36
+
37
+ | | |
38
+ |---|---|
39
+ | Base model | [Qwen/Qwen3-Embedding-4B](https://huggingface.co/Qwen/Qwen3-Embedding-4B) |
40
+ | Parameters | 4B |
41
+ | Embedding dimension | 2560 |
42
+ | Max sequence length | 32K tokens |
43
+ | Pooling | Last token, L2-normalized |
44
+ | Query instruction | Built-in `query` prompt |
45
+ | Language | English |
46
+ | Training method | LoRA fine-tuning |
47
+ | License | Apache 2.0 |
48
+
49
+ ## Usage
50
+
51
+ The weights are a LoRA adapter on Qwen/Qwen3-Embedding-4B; the base model downloads automatically.
52
+
53
+ ```bash
54
+ pip install -U sentence-transformers peft
55
+ ```
56
+
57
+ ### Using Sentence Transformers
58
+
59
+ ```python
60
+ from sentence_transformers import SentenceTransformer
61
+
62
+ model = SentenceTransformer("desearch/Desearch-Embedding-4B")
63
+
64
+ queries = [
65
+ "Who became Apple’s chief executive and will lead the Sept. 9, 2026 “Surprise and Shine” product event?",
66
+ "How much does the base Mac Mini M6 cost in US dollars as of its August 2026 announcement?",
67
+ ]
68
+ documents = [
69
+ "John Ternus, Apple's new chief executive, takes the stage at the September 9, 2026 “Surprise and Shine” event to unveil the latest iPhones and Apple Watches.",
70
+ "Apple surprised buyers in late August 2026 with the Mac Mini M6 at $899 and the Mac Mini M5 Pro at $1,699, both shipping on September 22.",
71
+ ]
72
+
73
+ query_embeddings = model.encode(queries, prompt_name="query")
74
+ document_embeddings = model.encode(documents)
75
+ print(model.similarity(query_embeddings, document_embeddings))
76
+ ```
77
+
78
+ Queries use the built-in `query` prompt; documents are encoded as they are.
79
+
80
+ ### Using Transformers
81
+
82
+ ```python
83
+ import torch
84
+ import torch.nn.functional as F
85
+ from peft import PeftModel
86
+ from transformers import AutoModel, AutoTokenizer
87
+
88
+ task = "Given a web search query, retrieve relevant passages that answer the query"
89
+ questions = [
90
+ "Who became Apple’s chief executive and will lead the Sept. 9, 2026 “Surprise and Shine” product event?",
91
+ "How much does the base Mac Mini M6 cost in US dollars as of its August 2026 announcement?",
92
+ ]
93
+ queries = [f"Instruct: {task}\nQuery:{q}" for q in questions]
94
+ documents = [
95
+ "John Ternus, Apple's new chief executive, takes the stage at the September 9, 2026 “Surprise and Shine” event to unveil the latest iPhones and Apple Watches.",
96
+ "Apple surprised buyers in late August 2026 with the Mac Mini M6 at $899 and the Mac Mini M5 Pro at $1,699, both shipping on September 22.",
97
+ ]
98
+
99
+ tokenizer = AutoTokenizer.from_pretrained("desearch/Desearch-Embedding-4B", padding_side="left")
100
+ model = AutoModel.from_pretrained("Qwen/Qwen3-Embedding-4B", dtype=torch.bfloat16)
101
+ model = PeftModel.from_pretrained(model, "desearch/Desearch-Embedding-4B").eval()
102
+
103
+
104
+ def encode(texts):
105
+ batch = tokenizer(texts, padding=True, truncation=True, max_length=8192, return_tensors="pt")
106
+ with torch.no_grad():
107
+ hidden = model(**batch).last_hidden_state
108
+ return F.normalize(hidden[:, -1], p=2, dim=1)
109
+
110
+
111
+ print(encode(queries) @ encode(documents).T)
112
+ ```
113
+
114
+ ## Recommended use cases
115
+
116
+ - First-stage retrieval for web search, news search and retrieval-augmented generation
117
+ - Semantic search over news archives, documentation and reference content
118
+ - Candidate generation ahead of a reranker
119
+
120
+ ## Limitations
121
+
122
+ - Tuned on English text; other languages are not a focus of this release.
123
+ - Queries need the `query` prompt; documents are encoded without one.
124
+ - Trained on documents up to 2,048 tokens; split longer pages into passages.
125
+ - Embeddings differ from Qwen/Qwen3-Embedding-4B; re-embed an existing corpus when switching.
126
+
127
+ ## License
128
+
129
+ This model is licensed under the Apache License 2.0. It is derived from Qwen/Qwen3-Embedding-4B, which is also
130
+ licensed under the Apache License 2.0.
131
+
132
+ ## Citation
133
+
134
+ ```bibtex
135
+ @misc{desearch2026embedding,
136
+ title = {Desearch Embedding 4B},
137
+ author = {Desearch},
138
+ year = {2026},
139
+ url = {https://huggingface.co/desearch/Desearch-Embedding-4B}
140
+ }
141
+ ```
adapter_config.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "Qwen/Qwen3-Embedding-4B",
7
+ "bias": "none",
8
+ "corda_config": null,
9
+ "ensure_weight_tying": false,
10
+ "eva_config": null,
11
+ "exclude_modules": null,
12
+ "fan_in_fan_out": false,
13
+ "inference_mode": false,
14
+ "init_lora_weights": true,
15
+ "kasa_config": null,
16
+ "layer_replication": null,
17
+ "layers_pattern": null,
18
+ "layers_to_transform": null,
19
+ "loftq_config": {},
20
+ "lora_alpha": 64,
21
+ "lora_bias": false,
22
+ "lora_dropout": 0.0,
23
+ "lora_ga_config": null,
24
+ "megatron_config": null,
25
+ "megatron_core": "megatron.core",
26
+ "modules_to_save": null,
27
+ "monteclora_config": null,
28
+ "peft_type": "LORA",
29
+ "peft_version": "0.21.0",
30
+ "qalora_group_size": 16,
31
+ "r": 64,
32
+ "rank_pattern": {},
33
+ "revision": null,
34
+ "target_modules": [
35
+ "down_proj",
36
+ "up_proj",
37
+ "o_proj",
38
+ "q_proj",
39
+ "k_proj",
40
+ "gate_proj",
41
+ "v_proj"
42
+ ],
43
+ "target_parameters": null,
44
+ "task_type": "FEATURE_EXTRACTION",
45
+ "trainable_token_indices": null,
46
+ "use_bdlora": null,
47
+ "use_dora": false,
48
+ "use_qalora": false,
49
+ "use_rslora": false,
50
+ "velora_config": null
51
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9bb94d1aa7a0b0d49f0be7de88e7c4367643c7675e10e5028909fd8aed8baf2a
3
+ size 528547232
chat_template.jinja ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- 'You are a helpful assistant.' }}
7
+ {%- endif %}
8
+ {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" %}
25
+ {{- '<|im_start|>' + message.role }}
26
+ {%- if message.content %}
27
+ {{- '\n' + message.content }}
28
+ {%- endif %}
29
+ {%- for tool_call in message.tool_calls %}
30
+ {%- if tool_call.function is defined %}
31
+ {%- set tool_call = tool_call.function %}
32
+ {%- endif %}
33
+ {{- '\n<tool_call>\n{"name": "' }}
34
+ {{- tool_call.name }}
35
+ {{- '", "arguments": ' }}
36
+ {{- tool_call.arguments | tojson }}
37
+ {{- '}\n</tool_call>' }}
38
+ {%- endfor %}
39
+ {{- '<|im_end|>\n' }}
40
+ {%- elif message.role == "tool" %}
41
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
42
+ {{- '<|im_start|>user' }}
43
+ {%- endif %}
44
+ {{- '\n<tool_response>\n' }}
45
+ {{- message.content }}
46
+ {{- '\n</tool_response>' }}
47
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
48
+ {{- '<|im_end|>\n' }}
49
+ {%- endif %}
50
+ {%- endif %}
51
+ {%- endfor %}
52
+ {%- if add_generation_prompt %}
53
+ {{- '<|im_start|>assistant\n' }}
54
+ {%- endif %}
config_sentence_transformers.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "pytorch": "2.13.0+cu130",
4
+ "sentence_transformers": "5.7.0",
5
+ "transformers": "5.15.0"
6
+ },
7
+ "default_prompt_name": null,
8
+ "model_type": "SentenceTransformer",
9
+ "prompts": {
10
+ "document": "",
11
+ "query": "Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery:"
12
+ },
13
+ "similarity_fn_name": "cosine"
14
+ }
modules.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.base.modules.transformer.Transformer"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Pooling",
12
+ "type": "sentence_transformers.sentence_transformer.modules.pooling.Pooling"
13
+ },
14
+ {
15
+ "idx": 2,
16
+ "name": "2",
17
+ "path": "2_Normalize",
18
+ "type": "sentence_transformers.sentence_transformer.modules.normalize.Normalize"
19
+ }
20
+ ]
sentence_bert_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "transformer_task": "feature-extraction",
3
+ "modality_config": {
4
+ "text": {
5
+ "method": "forward",
6
+ "method_output_name": "last_hidden_state"
7
+ }
8
+ },
9
+ "module_output_name": "token_embeddings"
10
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ff800fee44eacd1a1c8c2f96b890ade65d722550ab6693efa8d2c368f40a5853
3
+ size 11423209
tokenizer_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "is_local": false,
9
+ "local_files_only": false,
10
+ "model_max_length": 2048,
11
+ "pad_token": "<|endoftext|>",
12
+ "padding_side": "left",
13
+ "split_special_tokens": false,
14
+ "tokenizer_class": "Qwen2Tokenizer",
15
+ "unk_token": null
16
+ }