Views
No views yet
sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2. The pipeline performs:resize_token_embeddings() with ID remapping, avoiding the common pitfall of shape-mismatched state dict loading.sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 (Unigram, 250K vocab)en_only — English onlyid_only — Indonesian onlyen_id — English + Indonesianid_ar — Indonesian + Arabicar_only — Arabic onlyen_id_ar — English + Indonesian + ArabicIk45/fihris-embeddding-id-ar (derived from the pruned multilingual MiniLM)ik4545/shamela-waqfeya-split (classical Arabic texts, ~3.57GB)indo_modern.txt)[MASK], 10% → random token, 10% → unchangedDataCollatorForMLMOnTheFly with on-the-fly tokenization| Language | BPT Original | BPT Pruned | PPL Original | PPL Pruned | CosSim |
|---|---|---|---|---|---|
| Target | ~3.5 | ~4.2 | ~12.3 | ~14.1 | >0.95 |
| Other | ~3.5 | ~2.8 | ~12.3 | ~18.5 | ~0.85 |
1from sentence_transformers import SentenceTransformer
2
3model = SentenceTransformer("your-username/fihris-embedding-id-ar-pruned")
4sentences = [
5 "Ini adalah kalimat dalam bahasa Indonesia.",
6 "هذه جملة باللغة العربية.",
7 "This is a sentence in English."
8]
9
10embeddings = model.encode(sentences)
11print(embeddings.shape) # (3, 384)1from transformers import AutoTokenizer, AutoModel
2import torch
3
4tokenizer = AutoTokenizer.from_pretrained("your-username/fihris-embedding-id-ar-pruned")
5model = AutoModel.from_pretrained("your-username/fihris-embedding-id-ar-pruned")
6
7def mean_pooling(model_output, attention_mask):
8 token_embeddings = model_output.last_hidden_state
9 input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
10 return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
11
12texts = ["السلام عليكم", "Selamat pagi", "Good morning"]
13encoded = tokenizer(texts, padding=True, truncation=True, max_length=128, return_tensors="pt")
14
15with torch.no_grad():
16 output = model(**encoded)
17
18embeddings = mean_pooling(output, encoded["attention_mask"])1# Configure and run the pruning notebook
2UNI_MODEL_NAME = "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
3UNI_PRESET = "id_ar" # Indonesian + Arabic
4UNI_PRUNE_EMBEDDINGS = True
5UNI_OUTPUT_DIR = "./pruned_output"
6
7# The notebook will:
8# 1. Load tokenizer and detect type (Unigram/BPE/WordPiece)
9# 2. Compute token frequencies from FineWeb-2
10# 3. Remove low-frequency tokens
11# 4. Prune embeddings via resize_token_embeddings()
12# 5. Verify quality with BPT, PPL, and CosSim
13# 6. Save pruned tokenizer + model1@inproceedings{reimers-2019-sentence-bert,
2 title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
3 author = "Reimers, Nils and Gurevych, Iryna",
4 booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
5 month = "11",
6 year = "2019",
7 publisher = "Association for Computational Linguistics",
8 url = "http://arxiv.org/abs/1908.10084",
9}