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
File size: 897 Bytes
2a23a8c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | """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()
|