Loading the lesson...
In the print dialog, choose "Save as PDF" as the destination.
Arabic NLP - Lesson 1
Understanding corpora, tokenization, segmentation, and stopword removal for Arabic text.
POS tagging, NER, sentiment analysis, machine translation| Category | Examples | Supports |
|---|---|---|
| General-purpose | Arabic Gigaword (news), Arabic Web Corpus (crawled text), Tashkeela Corpus (diacritics/Tashkeel) | Tokenization, parsing, embeddings |
| Speech & conversational | MGB-2 (TV broadcasts), CALLHOME Arabic (phone calls), ArzEn (Egyptian Arabic-English bilingual speech) | Recognition, chatbots, dialogue systems |
| Category | Examples |
|---|---|
| Sentiment/opinion | ASTD (annotated tweets), LABR (book reviews), OCA (movie reviews) |
| Quranic/religious | Quranic Arabic Corpus (annotated Quran), Al-Hadith Corpus |
| Historical/literary | Al-Khalil Corpus (classical texts), Doha Historical Dictionary of Arabic |
Tokenization
Splitting text into words or subwords
Segmentation
Dividing text into sentences or phrases
Stemming
Reducing words to root form by removing affixes
Lemmatization
Converting words to base dictionary form
split() - basic, whitespace-basedre.findall() / re.split()NLP library - nltk.word_tokenize (or Farasa for Arabic)import re
pre_processed = re.sub(r'[^\w\s]', '', text) # keep only whitespace & wordsMethod 1
split()tokens_1 = pre_processed.split()
# ['إن', 'التاريخ', 'العسكري', 'سوف', 'يتوقف', ...]Method 2
re.findall(PATTERN, TEXT) extracts tokens matching a pattern\w+ matches word characters, giving a result similar to split() herePATTERN = r"\w+"
tokens_2 = re.findall(PATTERN, pre_processed)Method 3
word_tokenizepunkt_tab pretrained model (replaces the deprecated punkt)import nltk
nltk.download('punkt_tab')
from nltk.tokenize import word_tokenize
tokens_3 = word_tokenize(pre_processed)def segment(text):
segmenter = nltk.data.load("tokenizers/punkt/english.pickle")
sents = segmenter.tokenize(text)
for sent in sents:
print(sent)the, and, is) that add little meaning to text analysis.from nltk.corpus import stopwords
stopwords = stopwords.words('arabic')
X_set = {w for w in word_tokenize(X) if w not in stopwords}أحب المشي على الشاطئ becomes the set of words المشي, الشاطئ, أحبsplit(), regex, and NLTK - each trades simplicity for accuracyMahmoud Abas|Arabic Corpora: A Key Resource for Arabic NLP