Fill-Mask
Transformers
Safetensors
Arabic
modernbert
arabic
encoder
masked-language-modeling
natural-language-inference
retrieval
extractive-qa
Instructions to use Waqf-AI/arabic-modernbert-unified with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Waqf-AI/arabic-modernbert-unified with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="Waqf-AI/arabic-modernbert-unified")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("Waqf-AI/arabic-modernbert-unified") model = AutoModelForMaskedLM.from_pretrained("Waqf-AI/arabic-modernbert-unified", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download example.py from Waqf-AI/arabic-modernbert-unified: direct link, hf CLI and curl.
- Browser
- Download file 897 Bytes
-
https://huggingface.co/Waqf-AI/arabic-modernbert-unified/resolve/main/example.py
- Command line
-
hf download hf://Waqf-AI/arabic-modernbert-unified/example.py
-
curl -L -o example.py https://huggingface.co/Waqf-AI/arabic-modernbert-unified/resolve/main/example.py
897 Bytes
| """Run masked-word prediction, NLI and embeddings from a downloaded snapshot.""" | |
| from pathlib import Path | |
| from unified_encoder import UnifiedArabicEncoder | |
| def main(): | |
| model = UnifiedArabicEncoder(Path(__file__).resolve().parent) | |
| print(model.fill_mask(['تقع القاهرة على ضفاف نهر [MASK].'], top_k=5)) | |
| probabilities = model.classify( | |
| ['يقرأ الطفل كتاباً في المكتبة.'], | |
| ['الطفل يقرأ كتاباً.'], | |
| )[0] | |
| print(dict(zip(('entailment', 'neutral', 'contradiction'), probabilities.tolist()))) | |
| texts = ['يقرأ الطفل كتاباً.', 'الطفل يقرأ كتاباً.', 'توقفت الحافلة عند المحطة.'] | |
| embeddings = model.encode(texts) | |
| print('Embeddings:', embeddings.shape, 'query scores:', (embeddings[0] @ embeddings[1:].T).tolist()) | |
| if __name__ == '__main__': | |
| main() | |