An Arabic Preprocessing Toolkit for Pretraining of LLM
Project description
Tahdheeb (تهذیب)
Overview
Tahdheeb (تهذیب) is an Arabic Preprocessing Library developed at Qatar Computing Research. This library provides tools for preprocessing Arabic text, including normalization, diacritics handling, number normalization, punctuation correction, and more.
Develpers
- Ehsaneddin Asgari
- Yassine Elkheir
Features
- Normalization: Standardizes Arabic text by normalizing character variations and numbers.
- Diacritics Handling: Removes or processes Arabic diacritics.
- Punctuation Correction: Corrects punctuation usage in Arabic text.
- Determine Arabic Ratio: Output the arabic ration.
Installation
You can install Tahdheeb using pip:
pip install src
Example Usage
The following example demonstrates how to use the Tahdheeb library for preprocessing Arabic text, including fixing punctuation issues, improving text structure, and normalizing the text.
Code Example
from src.preprocessing.text_content import ArabicTextProcess
from src.preprocessing.text_verification import ArabicTextVerify
from src.preprocessing.text_structure import ArabicStructure
text = 'الـــــــــسلام عليكم . كيـــف حالك ؟ أتـــمنى أن تكون بــــــخير .أ نحنو هنا للمســـــاعدة ...هل تريــــد شيء مـــا؟ الرجـــــــاء إبلاغن ا بــــأي وقــــت! في ٢دقيقه شكرا ، جزيــــلا Thanks!'
# Initialize the classes
ATB = ArabicStructure()
ASP = ArabicTextProcess()
ATP = ArabicTextVerify()
# Check the ratio of Arabic text
print('Ratio of Arabic text:', ATP.check_arabic_ratio(text))
print('\nText before structure improvement:\n', text, '\n-----------\n')
# Preprocess the text to fix structure and remove English text
text = ATB.preprocess(text, remove_english=True)
print('\nText after structure improvement:\n', text, '\n-----------\n')
# Normalize the text (basic normalization)
text = ASP.get_arabic_normal(text, extensive_normalization=False)
print('\nText after normalizing:\n', text, '\n-----------\n')
# Normalize the text (extensive normalization)
text = ASP.get_arabic_normal(text, extensive_normalization=True)
print('\nText after extensive normalizing:\n', text, '\n-----------\n')
Explanation
Import Libraries
from src.preprocessing.text_content import ArabicTextProcess
from src.preprocessing.text_verification import ArabicTextVerify
from src.preprocessing.text_structure import ArabicStructure
Original Text
The sample text contains various errors such as character repetition, incorrect punctuation, and mixed language content.
text = 'الـــــــــسلام عليكم . كيـــف حالك ؟ أتـــمنى أن تكون بــــــخير .أ نحنو هنا للمســـــاعدة ...هل تريــــد شيء مـــا؟ الرجـــــــاء إبلاغن ا بــــأي وقــــت! في ٢دقيقه شكرا ، جزيــــلا Thanks!'
Initialize the Classes
Initialize the classes for structure improvement, text processing, and text verification.
ATB = ArabicStructure()
ASP = ArabicTextProcess()
ATP = ArabicTextVerify()
Check the Ratio of Arabic Text
Verify how much of the text is in Arabic.
print('Ratio of Arabic text:', ATP.check_arabic_ratio(text))
Before Structure Improvement
Print the original text before any processing.
print('\nText before structure improvement:\n', text, '\n-----------\n')
Structure Improvement
Preprocess the text to fix punctuation issues and remove English text.
text = ATB.preprocess(text, remove_english=True)
print('\nText after structure improvement:\n', text, '\n-----------\n')
Basic Normalization
Normalize the text with basic normalization.
text = ASP.get_arabic_normal(text, extensive_normalization=False)
print('\nText after normalizing:\n', text, '\n-----------\n')
Extensive Normalization
Normalize the text with extensive normalization.
text = ASP.get_arabic_normal(text, extensive_normalization=True)
print('\nText after extensive normalizing:\n', text, '\n-----------\n')
Output
This example will output the following information at each step:
- The ratio of Arabic text in the original input.
- The original text before any processing.
- The text after fixing structural issues and removing English text.
- The text after basic normalization.
- The text after extensive normalization.
This step-by-step process ensures that the Arabic text is cleaned, normalized, and ready for further processing or analysis.
Notes
Diacretics
| Unicode | Diacritic | Name (English) | Name (Arabic) | Description |
|---|---|---|---|---|
| \u064b | ً | Tanwin Fathah | تَنوين الفتح | Indicates a nun sound after the vowel (an). |
| \u064c | ٌ | Tanwin Dammah | تَنوين الضم | Indicates a nun sound after the vowel (un). |
| \u064d | ٍ | Tanwin Kasrah | تَنوين الكسر | Indicates a nun sound after the vowel (in). |
| \u064e | َ | Fathah | فتحة | Represents a short "a" sound. |
| \u064f | ُ | Dammah | ضمة | Represents a short "u" sound. |
| \u0650 | ِ | Kasrah | كسرة | Represents a short "i" sound. |
| \u0651 | ّ | Shaddah | شدة | Indicates gemination or doubling of a consonant. |
| \u0652 | ْ | Sukun | سكون | Indicates the absence of a vowel. |
| \u0653 | ٓ | Maddah | مدّة | Indicates a long vowel sound. |
| \u0670 | ٰ | Superscript Alif | ألف خنجرية | Indicates a short "a" sound, mainly in Quranic text. |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Tahdheeb-0.1.0.tar.gz.
File metadata
- Download URL: Tahdheeb-0.1.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7da3d817b69d1d7660179a9d2a077b16797251ecbabd9dc3c762c7ac3a845e20
|
|
| MD5 |
a9bd6c056a2811f21a05415f2449cc1a
|
|
| BLAKE2b-256 |
a7eeaeecc278f381c885a8c22bba475b80968987abe0692a93ff22478eb72a83
|
File details
Details for the file Tahdheeb-0.1.0-py3-none-any.whl.
File metadata
- Download URL: Tahdheeb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a62fe2b21e40c279a153dff596f115c58593f6adf08f2381f2c94dc740111a5
|
|
| MD5 |
ff0c569772d4d86c28bed51bdf5e99cb
|
|
| BLAKE2b-256 |
394e400b49dab76bc3c404f645c4a1cc3545089b1c10ab837826875bc714fdbf
|