EdwardHuy commited on
Commit
c308aba
·
verified ·
1 Parent(s): 736bad5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +111 -69
README.md CHANGED
@@ -1,33 +1,50 @@
1
  ---
2
- license: cc-by-4.0
3
  language:
4
- - en
5
- - nl
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  ---
7
 
8
- <!--
9
- Template for the Hugging Face model card. Do not upload this file as is:
10
- `python -m src.export_model` fills in every {{PLACEHOLDER}} for one language
11
- and writes the finished README.md into the export folder.
12
- -->
13
 
14
- # Belgian Persona Embeddings ({{LANGUAGE_NAME}})
15
 
16
- A {{LANGUAGE_NAME}} embedding model for finding people from short descriptions.
17
- It is [Qwen/Qwen3-Embedding-0.6B](https://huggingface.co/Qwen/Qwen3-Embedding-0.6B)
18
- fine-tuned with LoRA on synthetic "{{SOMEONE_WHO}}…" queries written for the
19
  [NVIDIA Nemotron-Personas-Belgium](https://huggingface.co/datasets/nvidia/Nemotron-Personas-Belgium)
20
- personas. The LoRA adapter is merged into the weights, so this repository is a
21
  regular Sentence Transformers model.
22
 
23
- It was made for the Advanced Natural Language Processing project by Ward
24
- Huybrechts and Raphael Hermans. The {{OTHER_LANGUAGE_NAME}} model was trained
25
- separately with the same recipe: {{OTHER_REPO_LINK}}.
 
 
 
 
 
 
 
26
 
27
  - **Base model:** Qwen/Qwen3-Embedding-0.6B (1024 dimensions, last-token pooling, L2-normalized)
28
- - **Training data:** [{{DATASET_ID}}](https://huggingface.co/datasets/{{DATASET_ID}}), {{LANGUAGE_NAME}} rows only
29
- - **Training run:** `{{RUN_NAME}}` ({{OBJECTIVE_SHORT}})
30
- - **Language:** {{LANGUAGE_NAME}} only. It was not trained or evaluated on other languages.
31
 
32
  ## Usage
33
 
@@ -36,14 +53,17 @@ pip install -U sentence-transformers
36
  ```
37
 
38
  ```python
 
39
  from sentence_transformers import SentenceTransformer
40
 
41
- model = SentenceTransformer("{{REPO_ID}}")
 
 
42
 
43
- queries = ["{{EXAMPLE_QUERY}}"]
44
  profiles = [
45
- "{{EXAMPLE_PROFILE_1}}",
46
- "{{EXAMPLE_PROFILE_2}}",
47
  ]
48
 
49
  # Query -> full profile: use the "query" prompt for queries, nothing for profiles.
@@ -53,19 +73,22 @@ print(model.similarity(query_embeddings, profile_embeddings))
53
 
54
  # Query -> other short descriptions of the same person: same prompt on both sides.
55
  a = model.encode(queries, prompt_name="same_person")
56
- b = model.encode(["{{EXAMPLE_QUERY_2}}"], prompt_name="same_person")
57
  print(model.similarity(a, b))
58
  ```
59
 
60
- The two prompts are the instructions used during training and evaluation:
 
 
 
61
 
62
  | Prompt name | Used for | Text prepended to the input |
63
  |---|---|---|
64
- | `query` | queries searching full profiles | `Instruct: {{Q2D_INSTRUCTION}}\nQuery:` |
65
- | `same_person` | both sides of query-to-query search | `Instruct: {{Q2Q_INSTRUCTION}}\nQuery:` |
66
 
67
- Profiles (documents) get no prompt. Profiles up to {{DOC_MAX_LENGTH}} tokens were
68
- used in evaluation, which is also this model's `max_seq_length`.
69
 
70
  ### Without Sentence Transformers
71
 
@@ -74,12 +97,12 @@ import torch
74
  import torch.nn.functional as F
75
  from transformers import AutoModel, AutoTokenizer
76
 
77
- tokenizer = AutoTokenizer.from_pretrained("{{REPO_ID}}", padding_side="left")
78
- model = AutoModel.from_pretrained("{{REPO_ID}}", dtype=torch.bfloat16).eval()
79
 
80
- instruction = "{{Q2D_INSTRUCTION}}"
81
  texts = [f"Instruct: {instruction}\nQuery:{q}" for q in queries] + profiles
82
- batch = tokenizer(texts, padding=True, truncation=True, max_length={{DOC_MAX_LENGTH}}, return_tensors="pt")
83
  with torch.inference_mode():
84
  hidden = model(**batch).last_hidden_state
85
  embeddings = F.normalize(hidden[:, -1].float(), dim=-1) # left padding: last position = last token
@@ -90,54 +113,65 @@ embeddings = F.normalize(hidden[:, -1].float(), dim=-1) # left padding: last po
90
  During training the inputs ended in `<|endoftext|><|im_end|>`: the Qwen3-Embedding
91
  tokenizer appends `<|endoftext|>` itself, and the training code appended the
92
  `<|im_end|>` end-of-sequence token after it. The embedding is the hidden state of
93
- that final token. The tokenizer in this repository appends both tokens, so the
94
  usage above reproduces the training setup. If you combine these weights with the
95
  original Qwen3-Embedding tokenizer instead, the embeddings will not match.
96
 
97
  ## Training
98
 
99
- - **Data:** {{TRAIN_PERSONS}} training persons, {{VALIDATION_PERSONS}} validation persons
100
- and {{TEST_PERSONS}} test persons, each with three short {{LANGUAGE_NAME}} queries
101
- and their full persona profile. Persons are split by a hash of their UUID, and the
102
- split is the same for Dutch and English, so no person or translation of a person
103
- crosses splits. The split is computed by `src/embeddings.py:split_assignment` in
104
- the project repository; the published dataset contains all splits.
105
- - **Objective:** {{OBJECTIVE_DESCRIPTION}}
106
- - **Batches:** {{BATCH_SIZE}} distinct persons per batch, so every in-batch negative is
107
- a different person. Each person contributes the same number of pairs per epoch.
108
- - **Model selection:** validation MRR@10 after every epoch{{SELECTION_NOTE}}; the best
109
- epoch was epoch {{BEST_EPOCH}} of {{EPOCHS}}.
110
-
111
- | Hyperparameter | Value |
112
- |---|---|
113
- | LoRA rank / alpha / dropout | {{RANK}} / {{ALPHA}} / {{DROPOUT}} |
114
- | LoRA target modules | q, k, v, o, gate, up and down projections |
115
- | Learning rate | {{LR}}, linear schedule with 10% warmup, AdamW, weight decay 0.01 |
116
- | Temperature | {{TEMPERATURE}} |
117
- | Max query length | {{MAX_LENGTH}} tokens |
118
- | Max profile length | {{DOC_MAX_LENGTH}} tokens |
119
- | Epochs | {{EPOCHS}} |
120
- | Seed | {{SEED}} |
121
- | Precision | bf16 frozen base, fp32 LoRA weights |
122
- | Hardware | One NVIDIA RTX 3080 (10 GB), about {{TRAIN_MINUTES}} minutes |
 
 
 
123
 
124
  ## Evaluation
125
 
126
- Held-out test persons, {{LANGUAGE_NAME}}. Each test query is used once:
 
127
 
128
  - **q2d:** the query searches all test profiles; only its own person's profile is relevant.
129
  - **q2q:** the query searches all other test queries; the person's other two queries are relevant.
130
 
131
  Brackets are 95% person-level bootstrap intervals from a single run.
132
 
133
- {{RESULTS_TABLE}}
 
 
 
 
 
 
 
134
 
135
  `e5-nl` is [clips/e5-large-trm-nl](https://huggingface.co/clips/e5-large-trm-nl) and
136
  `qwen-base` is the unmodified base model, both evaluated with the same code and data.
137
 
138
  Read these numbers with care:
139
 
140
- - The test pool is small (about {{TEST_PERSONS}} profiles), so the task is easier than
141
  searching a large collection.
142
  - The test persons were carved out of the generated training queries by hash, not
143
  taken from the project's separate validation/test manifest.
@@ -145,32 +179,40 @@ Read these numbers with care:
145
  how similar they can be. This caps the q2q scores.
146
  - The queries are synthetic and have not been fully reviewed by humans. Other
147
  persons that also fit a query are counted as wrong.
 
 
148
 
149
  ## Intended use and limitations
150
 
151
  Intended for research on persona retrieval and as a starting point for retrieving
152
- Belgian persona profiles from short {{LANGUAGE_NAME}} descriptions. It is not meant
153
  for searching or profiling real people.
154
 
155
  - All training data is synthetic. The personas may carry stereotypes or internal
156
  inconsistencies, and the generated queries can inherit them or add their own errors.
157
- - The model was only trained on "{{SOMEONE_WHO}}…" descriptions and Nemotron-style
158
- profiles. Behaviour on other query styles or domains was not measured.
 
159
  - Fine-tuning on this narrow task may reduce quality on general retrieval tasks
160
  compared with the base model. This was not measured.
161
 
162
  ## License and attribution
163
 
164
- The weights are released under Apache 2.0, the license of the base model. The
165
- training data is derived from
 
 
 
 
 
166
  [NVIDIA Nemotron-Personas-Belgium](https://huggingface.co/datasets/nvidia/Nemotron-Personas-Belgium)
167
- (CC BY 4.0); keep NVIDIA's attribution when you redistribute derived data.
168
 
169
  ```bibtex
170
  @misc{belgian_persona_embeddings,
171
  title = {Belgian Persona Embeddings},
172
  author = {Huybrechts, Ward and Hermans, Raphael},
173
  year = {2026},
174
- url = {https://huggingface.co/{{REPO_ID}}}
175
  }
176
- ```
 
1
  ---
 
2
  language:
3
+ - nl
4
+ - en
5
+ license: cc-by-4.0
6
+ library_name: sentence-transformers
7
+ pipeline_tag: sentence-similarity
8
+ base_model: Qwen/Qwen3-Embedding-0.6B
9
+ datasets:
10
+ - EdwardHuy/persona-queries
11
+ - nvidia/Nemotron-Personas-Belgium
12
+ tags:
13
+ - sentence-transformers
14
+ - feature-extraction
15
+ - sentence-similarity
16
+ - retrieval
17
+ - qwen3
18
+ - lora
19
+ - personas
20
+ - belgium
21
  ---
22
 
 
 
 
 
 
23
 
24
+ # Belgian Persona Embeddings (Dutch and English)
25
 
26
+ Embedding models for finding people from short descriptions, in **Dutch and
27
+ English**. Each is [Qwen/Qwen3-Embedding-0.6B](https://huggingface.co/Qwen/Qwen3-Embedding-0.6B)
28
+ fine-tuned with LoRA on synthetic "Iemand die…" / "Someone who…" queries written for the
29
  [NVIDIA Nemotron-Personas-Belgium](https://huggingface.co/datasets/nvidia/Nemotron-Personas-Belgium)
30
+ personas. The LoRA adapters are merged into the weights, so each folder is a
31
  regular Sentence Transformers model.
32
 
33
+ The two languages were trained and evaluated **separately**, each only on its own
34
+ language's queries and profiles, and are stored in their own folder:
35
+
36
+ | Folder | Language | Training run | Objective | q2d MRR@10 | q2q MRR@10 |
37
+ |---|---|---|---|---:|---:|
38
+ | `nl/` | Dutch | `qwen-lora-mixed-nl-seed42` | query-to-query plus query-to-profile contrastive loss | 0.811 | 0.031 |
39
+ | `en/` | English | `qwen-lora-mixed-en-seed42` | query-to-query plus query-to-profile contrastive loss | 0.858 | 0.052 |
40
+
41
+ Made for the Advanced Natural Language Processing project by Ward Huybrechts and
42
+ Raphael Hermans.
43
 
44
  - **Base model:** Qwen/Qwen3-Embedding-0.6B (1024 dimensions, last-token pooling, L2-normalized)
45
+ - **Training data:** [EdwardHuy/persona-queries](https://huggingface.co/datasets/EdwardHuy/persona-queries)
46
+ - **Languages:** use `nl/` for Dutch and `en/` for English. Neither was trained or
47
+ evaluated on the other language.
48
 
49
  ## Usage
50
 
 
53
  ```
54
 
55
  ```python
56
+ from huggingface_hub import snapshot_download
57
  from sentence_transformers import SentenceTransformer
58
 
59
+ language = "nl" # or "en"
60
+ path = snapshot_download("EdwardHuy/persona-embeddings", allow_patterns=[f"{language}/*"])
61
+ model = SentenceTransformer(f"{path}/{language}")
62
 
63
+ queries = ["Iemand die geniet van melancholieke romans en solitaire wandelingen in de polders."]
64
  profiles = [
65
+ "Een gepensioneerde juriste uit Boom die graag leest en lange wandelingen maakt.",
66
+ "Een jonge verpleger uit Gent die in het weekend voetbalt met vrienden.",
67
  ]
68
 
69
  # Query -> full profile: use the "query" prompt for queries, nothing for profiles.
 
73
 
74
  # Query -> other short descriptions of the same person: same prompt on both sides.
75
  a = model.encode(queries, prompt_name="same_person")
76
+ b = model.encode(["Iemand die rechten heeft gestudeerd en momenteel niet actief is op de arbeidsmarkt."], prompt_name="same_person")
77
  print(model.similarity(a, b))
78
  ```
79
 
80
+ `snapshot_download` with `allow_patterns` fetches only the chosen language's folder.
81
+
82
+ The two prompts are the instructions used during training and evaluation, and are
83
+ the same for both languages:
84
 
85
  | Prompt name | Used for | Text prepended to the input |
86
  |---|---|---|
87
+ | `query` | queries searching full profiles | `Instruct: Given a short description of a person, retrieve the full profile of that person\nQuery:` |
88
+ | `same_person` | both sides of query-to-query search | `Instruct: Given a short description of a person's interests, work or background, retrieve other descriptions of the same person\nQuery:` |
89
 
90
+ Profiles (documents) get no prompt. Profiles up to 2304 tokens were
91
+ used in evaluation, which is also the models' `max_seq_length`.
92
 
93
  ### Without Sentence Transformers
94
 
 
97
  import torch.nn.functional as F
98
  from transformers import AutoModel, AutoTokenizer
99
 
100
+ tokenizer = AutoTokenizer.from_pretrained("EdwardHuy/persona-embeddings", subfolder=language, padding_side="left")
101
+ model = AutoModel.from_pretrained("EdwardHuy/persona-embeddings", subfolder=language, dtype=torch.bfloat16).eval()
102
 
103
+ instruction = "Given a short description of a person, retrieve the full profile of that person"
104
  texts = [f"Instruct: {instruction}\nQuery:{q}" for q in queries] + profiles
105
+ batch = tokenizer(texts, padding=True, truncation=True, max_length=2304, return_tensors="pt")
106
  with torch.inference_mode():
107
  hidden = model(**batch).last_hidden_state
108
  embeddings = F.normalize(hidden[:, -1].float(), dim=-1) # left padding: last position = last token
 
113
  During training the inputs ended in `<|endoftext|><|im_end|>`: the Qwen3-Embedding
114
  tokenizer appends `<|endoftext|>` itself, and the training code appended the
115
  `<|im_end|>` end-of-sequence token after it. The embedding is the hidden state of
116
+ that final token. The tokenizers in this repository append both tokens, so the
117
  usage above reproduces the training setup. If you combine these weights with the
118
  original Qwen3-Embedding tokenizer instead, the embeddings will not match.
119
 
120
  ## Training
121
 
122
+ - **Data:** each person has three short queries and a full persona profile, per
123
+ language. Persons are split by a hash of their UUID, and the split is the same for
124
+ Dutch and English, so no person or translation of a person crosses splits. The
125
+ split is computed by `src/embeddings.py:split_assignment` in the project
126
+ repository; the published dataset contains all splits.
127
+ - **Objective:** The sum of two InfoNCE losses. (1) Symmetric query-to-query: the positive for a query is another query of the same person. (2) Query-to-profile: the positive is the person's full profile, and the other persons' profiles in the batch are negatives. Profiles are encoded with gradient caching so a full batch fits in 10 GB.
128
+ - **Batches:** distinct persons only, so every in-batch negative is a different
129
+ person. Each person contributes the same number of pairs per epoch.
130
+ - **Model selection:** validation MRR@10 after every epoch (mean of query-to-query and query-to-profile MRR@10).
131
+
132
+ | | Dutch (`nl/`) | English (`en/`) |
133
+ |---|---|---|
134
+ | Training run | `qwen-lora-mixed-nl-seed42` | `qwen-lora-mixed-en-seed42` |
135
+ | Train / validation / test persons | 2,788 / 180 / 366 | 2,776 / 188 / 370 |
136
+ | Queries per person | 3 | 3 |
137
+ | Epochs (best epoch) | 1 (1) | 1 (1) |
138
+ | Persons per batch | 128 | 128 |
139
+ | LoRA rank / alpha / dropout | 16 / 32 / 0.0 | 16 / 32 / 0.0 |
140
+ | Learning rate | 0.0001 | 0.0001 |
141
+ | Temperature | 0.05 | 0.05 |
142
+ | Max query / profile length (tokens) | 128 / 2304 | 128 / 2304 |
143
+ | Seed | 42 | 42 |
144
+ | Training time | about 111 minutes | about 64 minutes |
145
+
146
+ Both runs used LoRA on the q, k, v, o, gate, up and down projections, a linear
147
+ learning-rate schedule with 10% warmup, AdamW with weight decay 0.01, a bf16 frozen
148
+ base with fp32 LoRA weights, and one NVIDIA RTX 3080 (10 GB).
149
 
150
  ## Evaluation
151
 
152
+ Held-out test persons, each language evaluated on its own queries and profiles.
153
+ Each test query is used once:
154
 
155
  - **q2d:** the query searches all test profiles; only its own person's profile is relevant.
156
  - **q2q:** the query searches all other test queries; the person's other two queries are relevant.
157
 
158
  Brackets are 95% person-level bootstrap intervals from a single run.
159
 
160
+ | Language | Model | q2d MRR@10 | q2d Acc@1 | q2d Recall@10 | q2q MRR@10 | q2q Acc@1 | q2q Recall@10 |
161
+ |---|---|---:|---:|---:|---:|---:|---:|
162
+ | Dutch | e5-nl | 0.128 [0.110, 0.146] | 0.069 [0.053, 0.087] | 0.283 [0.253, 0.313] | 0.006 [0.003, 0.009] | 0.001 [0.000, 0.003] | 0.015 [0.009, 0.020] |
163
+ | Dutch | qwen-base | 0.135 [0.116, 0.153] | 0.077 [0.059, 0.095] | 0.288 [0.258, 0.320] | 0.007 [0.004, 0.011] | 0.003 [0.000, 0.006] | 0.012 [0.007, 0.018] |
164
+ | Dutch | **this model** (`nl/`) | 0.811 [0.793, 0.830] | 0.741 [0.717, 0.766] | 0.943 [0.929, 0.955] | 0.031 [0.021, 0.042] | 0.013 [0.005, 0.022] | 0.052 [0.041, 0.065] |
165
+ | English | e5-nl | 0.125 [0.108, 0.143] | 0.068 [0.053, 0.084] | 0.272 [0.244, 0.302] | 0.012 [0.006, 0.019] | 0.005 [0.001, 0.011] | 0.016 [0.010, 0.023] |
166
+ | English | qwen-base | 0.232 [0.210, 0.254] | 0.165 [0.142, 0.187] | 0.419 [0.390, 0.450] | 0.011 [0.006, 0.017] | 0.004 [0.000, 0.008] | 0.018 [0.012, 0.025] |
167
+ | English | **this model** (`en/`) | 0.858 [0.841, 0.876] | 0.799 [0.774, 0.825] | 0.966 [0.955, 0.976] | 0.052 [0.039, 0.067] | 0.023 [0.013, 0.034] | 0.078 [0.064, 0.095] |
168
 
169
  `e5-nl` is [clips/e5-large-trm-nl](https://huggingface.co/clips/e5-large-trm-nl) and
170
  `qwen-base` is the unmodified base model, both evaluated with the same code and data.
171
 
172
  Read these numbers with care:
173
 
174
+ - The test pools are small (a few hundred profiles), so the task is easier than
175
  searching a large collection.
176
  - The test persons were carved out of the generated training queries by hash, not
177
  taken from the project's separate validation/test manifest.
 
179
  how similar they can be. This caps the q2q scores.
180
  - The queries are synthetic and have not been fully reviewed by humans. Other
181
  persons that also fit a query are counted as wrong.
182
+ - Dutch and English scores come from separate models and separately generated
183
+ queries. They are not a controlled comparison between the languages.
184
 
185
  ## Intended use and limitations
186
 
187
  Intended for research on persona retrieval and as a starting point for retrieving
188
+ Belgian persona profiles from short Dutch or English descriptions. It is not meant
189
  for searching or profiling real people.
190
 
191
  - All training data is synthetic. The personas may carry stereotypes or internal
192
  inconsistencies, and the generated queries can inherit them or add their own errors.
193
+ - The models were only trained on "Iemand die…" / "Someone who…" descriptions and
194
+ Nemotron-style profiles. Behaviour on other query styles, other domains or mixed
195
+ languages was not measured.
196
  - Fine-tuning on this narrow task may reduce quality on general retrieval tasks
197
  compared with the base model. This was not measured.
198
 
199
  ## License and attribution
200
 
201
+ Our fine-tuning changes and this model card are released under
202
+ [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), the same license as the
203
+ training data. The weights are a modified version of
204
+ [Qwen/Qwen3-Embedding-0.6B](https://huggingface.co/Qwen/Qwen3-Embedding-0.6B), which is
205
+ licensed under the Apache License 2.0; the parts that come from the base model stay
206
+ under Apache 2.0, and a copy of that license is included as `LICENSE-APACHE-2.0`.
207
+ The training data is derived from
208
  [NVIDIA Nemotron-Personas-Belgium](https://huggingface.co/datasets/nvidia/Nemotron-Personas-Belgium)
209
+ (CC BY 4.0); keep NVIDIA's and Qwen's attribution when you redistribute this model.
210
 
211
  ```bibtex
212
  @misc{belgian_persona_embeddings,
213
  title = {Belgian Persona Embeddings},
214
  author = {Huybrechts, Ward and Hermans, Raphael},
215
  year = {2026},
216
+ url = {https://huggingface.co/EdwardHuy/persona-embeddings}
217
  }
218
+ ```