Fill-Mask
Transformers
Safetensors
Arabic
bert_hash_v2
bert
arabic
masked-language-modeling
encoder
custom_code
berthash
research
Instructions to use Waqf-AI/arabic-berthash-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Waqf-AI/arabic-berthash-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="Waqf-AI/arabic-berthash-v2", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForMaskedLM model = AutoModelForMaskedLM.from_pretrained("Waqf-AI/arabic-berthash-v2", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Release original ArabicBertHash v2 checkpoint 1420000 with portable model code and audited Luna results
3aeda90 verified Download example.py from Waqf-AI/arabic-berthash-v2: direct link, hf CLI and curl.
- Browser
- Download file 962 Bytes
-
https://huggingface.co/Waqf-AI/arabic-berthash-v2/resolve/main/example.py
- Command line
-
hf download hf://Waqf-AI/arabic-berthash-v2/example.py
-
curl -L -o example.py https://huggingface.co/Waqf-AI/arabic-berthash-v2/resolve/main/example.py
962 Bytes
| """Run locally: python example.py /path/to/release (or a Hub repo ID).""" | |
| import sys | |
| import torch | |
| from transformers import AutoTokenizer, AutoModelForMaskedLM | |
| checkpoint = sys.argv[1] if len(sys.argv) > 1 else 'Abdelkareem/arabic-berthash-v2' | |
| tokenizer = AutoTokenizer.from_pretrained(checkpoint, trust_remote_code=True) | |
| model = AutoModelForMaskedLM.from_pretrained(checkpoint, trust_remote_code=True).eval() | |
| batch = tokenizer('اللغة العربية هي لغة [MASK] الكريم',return_tensors='pt',truncation=True,max_length=1024) | |
| mask = batch['input_ids'].eq(tokenizer.mask_token_id) | |
| assert mask.sum().item() == 1 | |
| with torch.inference_mode(): | |
| logits = model(**batch).logits[mask][0] | |
| probabilities, ids = logits.softmax(-1).topk(5) | |
| for token, probability in zip(ids.tolist(),probabilities.tolist()): | |
| filled=batch['input_ids'][0].clone();filled[mask[0]]=token | |
| print(tokenizer.decode(filled,skip_special_tokens=True),round(probability,5)) | |