Views
No views yet
trust_remote_code=True argument when loading it.pip install transformers torch pandas arabert1import torch
2import numpy as np
3from transformers import AutoTokenizer, AutoModel
4from arabert.preprocess import ArabertPreprocessor
5
6# --- 1. Define the Feature Engineering Function ---
7def get_lexical_features(text, lexicon):
8 words = text.split()
9 if not words: return [0.0] * 7
10 word_difficulties = [lexicon.get(word, 3.0) for word in words]
11 features = [
12 float(len(text)), float(len(words)),
13 float(np.mean([len(w) for w in words]) if words else 0.0),
14 float(np.mean(word_difficulties)), float(np.max(word_difficulties)),
15 float(np.sum(np.array(word_difficulties) > 4)),
16 float(len([w for w in words if w not in lexicon]) / len(words))
17 ]
18 return features
19
20# --- 2. Initialize Models and Processors ---
21repo_id = "FatimahEmadEldin/Constrained-Track-Document-Bassline-Readability-Arabertv2-d3tok-reg"
22arabert_preprocessor = ArabertPreprocessor(model_name="aubmindlab/bert-large-arabertv2")
23tokenizer = AutoTokenizer.from_pretrained(repo_id)
24model = AutoModel.from_pretrained(repo_id, trust_remote_code=True)
25
26# --- 3. Prepare Input Document and Lexicon ---
27# For a real use case, load the full SAMER lexicon.
28sample_lexicon = {'جملة': 2.5, 'عربية': 3.1, 'بسيطة': 1.8, 'النص': 2.8, 'طويل': 3.5}
29document_text = "هذا مثال لجملة عربية بسيطة. هذا النص أطول قليلاً من المثال السابق."
30
31# --- 4. Run the Full Pipeline ---
32preprocessed_text = arabert_preprocessor.preprocess(document_text)
33numerical_features_list = get_lexical_features(preprocessed_text, sample_lexicon)
34numerical_features = torch.tensor([numerical_features_list], dtype=torch.float)
35
36inputs = tokenizer(preprocessed_text, return_tensors="pt", padding=True, truncation=True, max_length=512)
37inputs['extra_features'] = numerical_features # The model expects 'extra_features'
38
39# --- 5. Perform Inference ---
40model.eval()
41with torch.no_grad():
42 logits = model(**inputs)[1] # The model returns (loss, logits)
43
44# --- 6. Process the Output ---
45predicted_score = logits.item()
46final_level = round(max(0, min(18, predicted_score))) + 1
47
48print(f"Input Document: '{document_text}'")
49print(f"Raw Regression Score: {predicted_score:.4f}")
50print(f"Predicted Readability Level (1-19): {final_level}")
51CAMeL-Lab/readability-arabertv2-d3tok-reg, fine-tuned directly on the BAREC dataset.[CLS] token embedding with a 7-dimensional vector of engineered lexical features derived from the SAMER lexicon.d3tok format. The d3tok analyzer performs a deep morphological analysis by disambiguating words in context and then segmenting them into their constituent morphemes.| Track | Task | Dev (QWK) | Test (QWK) |
|---|---|---|---|
| Strict | Sentence | 0.823 | 84.2 |
| Document | 0.823* | 79.9 | |
| Constrained | Sentence | 0.810 | 82.9 |
| Document | 0.835* | 75.5 | |
| Open | Sentence | 0.827 | 83.6 |
| Document | 0.827* | 79.2 |
@inproceedings{eldin2025morphoarabia,
title={{MorphoArabia at BAREC 2025 Shared Task: A Hybrid Architecture with Morphological Analysis for Arabic Readability Assessmen}},
author={Eldin, Fatimah Mohamed Emad},
year={2025},
booktitle={Proceedings of the BAREC 2025 Shared Task},
eprint={25XX.XXXXX},
archivePrefix={arXiv},
primaryClass={cs.CL}
}