Downloads · 30 days
14
5% of all-time downloads
HikmaLabs/ukhbert_narrator_detection
ukhbert_narrator_detection is a token classification model from HikmaLabs. Use it when you need labels on individual words, such as names. It is set up for transformers. The card lists the license as apache-2.0.
Ukhbert is a pair of BERT base transformer models for use with classical arabic texts. Specifically, it's used with reports composed of a isnad, or chain of narrators that transmit the report, and the matn, the actual…
Downloads · 30 days
14
5% of all-time downloads
All-time downloads
265
Public
Parameters
177M
2.8 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors709 MB · 100%
How the weights are stored.
F32177M · 100%
From the Hugging Face model README
Ukhbert is a pair of BERT base transformer models for use with classical arabic texts. Specifically, it's used with reports composed of a isnad, or chain of narrators that transmit the report, and the matn, the actual content. Ukhbert is used to identify narrators within a isnad from the text of the report.
For example, consider the following text, which is a hadith or attribution to the Prophet Muhammad:
حَدَّثَنَا قُتَيْبَةُ بْنُ سَعِيدٍ، حَدَّثَنَا عَبْدُ الْوَهَّابِ، قَالَ سَمِعْتُ يَحْيَى بْنَ سَعِيدٍ، يَقُولُ أَخْبَرَنِي مُحَمَّدُ بْنُ إِبْرَاهِيمَ، أَنَّهُ سَمِعَ عَلْقَمَةَ بْنَ وَقَّاصٍ اللَّيْثِيَّ، يَقُولُ سَمِعْتُ عُمَرَ بْنَ الْخَطَّابِ ـ رضى الله عنه ـ يَقُولُ سَمِعْتُ رَسُولَ اللَّهِ صلى الله عليه وسلم يَقُولُ " إِنَّمَا الأَعْمَالُ بِالنِّيَّةِ، وَإِنَّمَا لاِمْرِئٍ مَا نَوَى، فَمَنْ كَانَتْ هِجْرَتُهُ إِلَى اللَّهِ وَرَسُولِهِ فَهِجْرَتُهُ إِلَى اللَّهِ وَرَسُولِهِ، وَمَنْ كَانَتْ هِجْرَتُهُ إِلَى دُنْيَا يُصِيبُهَا أَوِ امْرَأَةٍ يَتَزَوَّجُهَا، فَهِجْرَتُهُ إِلَى مَا هَاجَرَ إِلَيْهِ .
Narrated `Umar bin Al-Khattab: I heard Allah's Messenger (ﷺ) saying, "The (reward of) deeds, depend upon the intentions and every person will get the reward according to what he has intended. So whoever emigrated for the sake of Allah and His Apostle, then his emigration will be considered to be for Allah and His Apostle, and whoever emigrated for the sake of worldly gain or for a woman to marry, then his emigration will be considered to be for what he emigrated for."
Sahih al-Bukhari 6689 https://sunnah.com/bukhari:6689
The isnad is this:
حَدَّثَنَا قُتَيْبَةُ بْنُ سَعِيدٍ، حَدَّثَنَا عَبْدُ الْوَهَّابِ، قَالَ سَمِعْتُ يَحْيَى بْنَ سَعِيدٍ، يَقُولُ أَخْبَرَنِي مُحَمَّدُ بْنُ إِبْرَاهِيمَ، أَنَّهُ سَمِعَ عَلْقَمَةَ بْنَ وَقَّاصٍ اللَّيْثِيَّ، يَقُولُ سَمِعْتُ عُمَرَ بْنَ الْخَطَّابِ
Qutaybah bin Saeed narrated from Abdul Wahhab who said he heard Yahya bin Saeed who said it was reported to him from Muhammad bin Ibrahim who heard Alqamah bin Waqqaa al Laythi, who said he heard from Umar bin Khattab.
The use of Ukhbert is to first identify the names narrators from the text, and then find out who they are.
This is the first half of the ukhbert pair. It identifies the names of narrators from a text. It classifies the tokens of the text into 3 classes: Begining Narrator "B-NAR", Intermediate Narrrator "I-NAR", and other "O". For finding out names of narrators, we gather the "NAR"s, as names of narrators are composed of the concatenation of B-NAR with zero or more I-NARs.
It is strongly recommended to use pipeline from the transformers library
for inference. Make sure to preprocess the text by removing diacritics,
and ensuring only arabic text is in the corpus.
Here is a working example:
from transformers import pipeline
pipe = pipeline('ner', model='HikmaLabs/ukhbert_narrator_detection', tokenizer='HikmaLabs/ukhbert_narrator_detection', config='HikmaLabs/ukhbert_narrator_detection',aggregation_strategy="simple")
# you can also use a list of strings, HF datasets, as per pipelines documentation
hadith = 'حدثنا قتيبة بن سعيد، حدثنا عبد الوهاب، قال سمعت يحيى بن سعيد، يقول أخبرني محمد بن إبراهيم، أنه سمع علقمة بن وقاص الليثي، يقول سمعت عمر بن الخطاب ـ رضى الله عنه ـ يقول سمعت رسول الله صلى الله عليه وسلم يقول " إنما الأعمال بالنية، وإنما لامرئ ما نوى، فمن كانت هجرته إلى الله ورسوله فهجرته إلى الله ورسوله، ومن كانت هجرته إلى دنيا يصيبها أو امرأة يتزوجها، فهجرته إلى ما هاجر إليه "'
ner_results = pipe(hadith)
The output of ner_results is this:
[{'entity_group': 'NAR',
'score': np.float32(0.99935853),
'word': 'قتيبة بن سعيد',
'start': 6,
'end': 19},
{'entity_group': 'NAR',
'score': np.float32(0.9982073),
'word': 'عبد الوهاب',
'start': 27,
'end': 37},
{'entity_group': 'NAR',
'score': np.float32(0.998333),
'word': 'يحيى بن سعيد',
'start': 48,
'end': 60},
{'entity_group': 'NAR',
'score': np.float32(0.9989322),
'word': 'محمد بن إبراهيم',
'start': 74,
'end': 89},
{'entity_group': 'NAR',
'score': np.float32(0.99043906),
'word': 'علقمة بن وقاص الليثي',
'start': 99,
'end': 119},
{'entity_group': 'NAR',
'score': np.float32(0.9782518),
'word': 'عمر بن الخطاب',
'start': 131,
'end': 144}]
To identify the narrators (ie get biographical info of the narrator), it is highly recommended to use the Narrator linking Model HikmaLabs/ukhbert_narrator_linking
Ukhbert is finetuned from the ARABERT v0.1 model. For more details, please consult the referenced paper, "Learning to identify Narrators in Classical Islamic Texts"
If you use the model, please cite this paper:
@article{ALKAOUD2021335,
title = {Learning to Identify Narrators in Classical Arabic Texts},
journal = {Procedia Computer Science},
volume = {189},
pages = {335-342},
year = {2021},
note = {AI in Computational Linguistics},
issn = {1877-0509},
doi = {https://doi.org/10.1016/j.procs.2021.05.109},
url = {https://www.sciencedirect.com/science/article/pii/S1877050921012369},
author = {Mohamed Alkaoud and Mairaj Syed},
keywords = {NLP, Classical Arabic, Entity linking, Named-entity recognition, Digital humanities, Hadith science},
abstract = {One widespread historical method of transmitting and recording information about important events and people in the Middle East is the narration-based method. In this method, each saying about a person or event is transmitted from person to person until a systematic collector records and compiles such sayings in a stable collection. At each stage of transmission, the narrator not only transmits the saying but also the person he got it from going back to the earliest narrator. Identifying each narrator in these collections is important to better measure the accuracy of the narrations and identify the date and geographies of their circulation. In this work, we propose a natural language processing technique to automate the identification of narrators in classical Arabic texts. Our proposed technique consists of two models: 1) a model for detecting the narrators in the text, and 2) a model for linking narrators to their biographies. We train our two models on a large collection of annotated classical Arabic texts and achieve F1-scores of 96.15% and 95.74% for narration detection and linking respectively.}
}