Sentence Similarity
sentence-transformers
Safetensors
Twi
Akan
English
xlm-roberta
feature-extraction
twi
akan
cross-lingual-retrieval
retrieval
rag
knowledge-distillation
text-embeddings-inference
Instructions to use DexelLabs/MargEmbed-Akan with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use DexelLabs/MargEmbed-Akan with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("DexelLabs/MargEmbed-Akan") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Add MargEmbed-Akan
Browse files- .gitattributes +1 -0
- 1_Pooling/config.json +5 -0
- 2_Normalize/config.json +4 -0
- README.md +37 -0
- config.json +30 -0
- config_sentence_transformers.json +14 -0
- model.safetensors +3 -0
- modules.json +20 -0
- sentence_bert_config.json +10 -0
- tokenizer.json +3 -0
- tokenizer_config.json +24 -0
.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": 1024,
|
| 3 |
+
"pooling_mode": "mean",
|
| 4 |
+
"include_prompt": true
|
| 5 |
+
}
|
2_Normalize/config.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"module_input_name": "sentence_embedding",
|
| 3 |
+
"module_output_name": "sentence_embedding"
|
| 4 |
+
}
|
README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: sentence-transformers
|
| 3 |
+
base_model: McGill-NLP/AfriE5-Large-instruct
|
| 4 |
+
language: [tw, en]
|
| 5 |
+
license: mit
|
| 6 |
+
tags: [sentence-transformers, twi, akan, cross-lingual-retrieval, query-encoder, knowledge-distillation]
|
| 7 |
+
---
|
| 8 |
+
# MargEmbed-Akan
|
| 9 |
+
|
| 10 |
+
Query encoder for **Twi → English retrieval**. **Encode questions with this model and passages with the original
|
| 11 |
+
`McGill-NLP/AfriE5-Large-instruct`** (the passage space is unchanged).
|
| 12 |
+
|
| 13 |
+
```python
|
| 14 |
+
from sentence_transformers import SentenceTransformer
|
| 15 |
+
q_model = SentenceTransformer("DexelLabs/MargEmbed-Akan")
|
| 16 |
+
p_model = SentenceTransformer("McGill-NLP/AfriE5-Large-instruct")
|
| 17 |
+
prompt = "Instruct: Given a question, retrieve Wikipedia passages that answer the question\nQuery: "
|
| 18 |
+
q = q_model.encode(["Kasa bɛn na nnipa dodow no ara ka wɔ Uganda?"], prompt=prompt, normalize_embeddings=True)
|
| 19 |
+
p = p_model.encode(["Languages of Uganda. In Uganda the most spoken local language is Luganda ..."], normalize_embeddings=True)
|
| 20 |
+
print(q @ p.T)
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
## Training
|
| 24 |
+
English questions (Natural Questions, TriviaQA, SQuAD, GooAQ; sampled to favour low keyword overlap) translated to
|
| 25 |
+
Asante Twi with `facebook/nllb-200-3.3B` and kept only if their back-translation matches the original. The base model,
|
| 26 |
+
given the **English** question, scores the answer passage and 7 hard negatives; this model learns to
|
| 27 |
+
reproduce those scores from the **Twi** question (listwise KL distillation; passages frozen), plus a light Twi–English
|
| 28 |
+
alignment term on the GhanaNLP corpus. Final weights = 1.0 × trained + 0.0 × base.
|
| 29 |
+
**No AfriQA data was used for training or model selection.** NLLB-200 is CC BY-NC 4.0: research use.
|
| 30 |
+
|
| 31 |
+
## AfriQA Twi test (nDCG@10, strict; passages encoded by base AfriE5)
|
| 32 |
+
| setting | base | trained | gemini_ref |
|
| 33 |
+
|:-----------------------|-------:|----------:|-------------:|
|
| 34 |
+
| Twi→Eng | 67.5 | 71.7 | 68 |
|
| 35 |
+
| Twi (standard ɛ/ɔ)→Eng | 68.3 | 72 | 70 |
|
| 36 |
+
| Twi (no ɛ/ɔ)→Eng | 63.4 | 70.2 | 63 |
|
| 37 |
+
| Eng→Eng (ref) | 87.7 | 87.3 | 89.6 |
|
config.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_cross_attention": false,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"XLMRobertaModel"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"bos_token_id": 0,
|
| 8 |
+
"classifier_dropout": null,
|
| 9 |
+
"dtype": "bfloat16",
|
| 10 |
+
"eos_token_id": 2,
|
| 11 |
+
"hidden_act": "gelu",
|
| 12 |
+
"hidden_dropout_prob": 0.1,
|
| 13 |
+
"hidden_size": 1024,
|
| 14 |
+
"initializer_range": 0.02,
|
| 15 |
+
"intermediate_size": 4096,
|
| 16 |
+
"is_decoder": false,
|
| 17 |
+
"layer_norm_eps": 1e-05,
|
| 18 |
+
"max_position_embeddings": 514,
|
| 19 |
+
"model_type": "xlm-roberta",
|
| 20 |
+
"num_attention_heads": 16,
|
| 21 |
+
"num_hidden_layers": 24,
|
| 22 |
+
"output_past": true,
|
| 23 |
+
"pad_token_id": 1,
|
| 24 |
+
"position_embedding_type": "absolute",
|
| 25 |
+
"tie_word_embeddings": true,
|
| 26 |
+
"transformers_version": "5.20.2",
|
| 27 |
+
"type_vocab_size": 1,
|
| 28 |
+
"use_cache": false,
|
| 29 |
+
"vocab_size": 250002
|
| 30 |
+
}
|
config_sentence_transformers.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"__version__": {
|
| 3 |
+
"pytorch": "2.14.1+cu130",
|
| 4 |
+
"sentence_transformers": "6.2.0",
|
| 5 |
+
"transformers": "5.20.2"
|
| 6 |
+
},
|
| 7 |
+
"default_prompt_name": null,
|
| 8 |
+
"model_type": "SentenceTransformer",
|
| 9 |
+
"prompts": {
|
| 10 |
+
"document": "",
|
| 11 |
+
"query": ""
|
| 12 |
+
},
|
| 13 |
+
"similarity_fn_name": "cosine"
|
| 14 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5f1f2bb6f1cd4b41dea13cd000009b9cea1ea860d7f36c5f75c016e5b1d89da3
|
| 3 |
+
size 1119826072
|
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.base.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:883b037111086fd4dfebbbc9b7cee11e1517b5e0c0514879478661440f137085
|
| 3 |
+
size 17082987
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": true,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<s>",
|
| 5 |
+
"clean_up_tokenization_spaces": true,
|
| 6 |
+
"cls_token": "<s>",
|
| 7 |
+
"eos_token": "</s>",
|
| 8 |
+
"extra_special_tokens": [],
|
| 9 |
+
"is_local": true,
|
| 10 |
+
"local_files_only": false,
|
| 11 |
+
"mask_token": "<mask>",
|
| 12 |
+
"max_length": 512,
|
| 13 |
+
"model_max_length": 512,
|
| 14 |
+
"pad_to_multiple_of": null,
|
| 15 |
+
"pad_token": "<pad>",
|
| 16 |
+
"pad_token_type_id": 0,
|
| 17 |
+
"padding_side": "right",
|
| 18 |
+
"sep_token": "</s>",
|
| 19 |
+
"stride": 0,
|
| 20 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
| 21 |
+
"truncation_side": "right",
|
| 22 |
+
"truncation_strategy": "longest_first",
|
| 23 |
+
"unk_token": "<unk>"
|
| 24 |
+
}
|