Views
No views yet
[MASK], 10% random, 10% unchanged) using cross-entropy loss [Devlin et al., 2018].| Dataset | Task | F1 (Alberta-MSA) | F1 (BERT-MSA) | Retention (%) |
|---|---|---|---|---|
| AAFAQ [Essam et al., 2025] | Question Classification | 0.8835 | 0.8973 | 98.4 |
| ANERCorp [Benajiba et al., 2007] | NER (9 tags) | 0.6416 | 0.6739 | 95.23 |
| OSCAT [Seelawi et al., 2021] | Offensive Detection | 0.7459 | 0.8000 | 93.24 |
| IDAT [Seelawi et al., 2021] | Irony Detection | 0.7800 | 0.7947 | 98.13 |
| NSURL [Seelawi et al., 2021] | Semantic Similarity | 0.9385 | 0.9596 | 97.76 |
| ASERQA | QA (Span Extraction) | 0.5300 | 0.5289 | 100.19 |
1from transformers import pipeline, AutoModelForMaskedLM, AutoTokenizer
2import torch
3
4model_name = "AbdallahhSaleh/Alberta-MSA"
5
6# 1. Load Tokenizer and Model
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForMaskedLM.from_pretrained(model_name)
9
10# 2. Prepare Input
11text = "السلام [MASK] الجميع."
12# Tokenize input
13inputs = tokenizer(text, return_tensors="pt")
14# Shape: (Batch=1, Seq_Len=6) -> e.g., [CLS, السلام, [MASK], الجميع, ., SEP]
15
16# 3. Forward Pass (Data Flow)
17with torch.no_grad():
18 outputs = model(**inputs)
19
20 # Hidden State Projection:
21 # Embedding (1, 6, 128) -> Projected (1, 6, 768) -> Layers -> Final Hidden (1, 6, 768)
22
23 # Logits Calculation:
24 logits = outputs.logits
25 # Shape: (Batch=1, Seq_Len=6, Vocab_Size=100000)
26
27# 4. Decode Mask
28mask_token_index = (inputs.input_ids == tokenizer.mask_token_id)[0].nonzero(as_tuple=True)[0]
29predicted_token_id = logits[0, mask_token_index].argmax(axis=-1)
30print(tokenizer.decode(predicted_token_id))
31# Output: "عليكم"