All Projects

Husna Search.

TF-IDF search over ~5,000 Arabic articles, built with a custom preprocessing pipeline and a hand-rolled tokenizer.

Natural Language ProcessingArchived~5,000 articlesTF-IDF · cosine sim.313 tokensArabic NLP
4,998
Usable articles
6,366
Scraped rows
313
Vocabulary size
5
Top-K results

Overview

Corpus

~5,000 Arabic articles, one publisher

The dataset is 6,366 scraped rows from a single publisher; after dropping empty-content rows, 4,998 articles actually go into the index — mostly news (5,870 rows across the full scrape), with a smaller mix of blog posts and video entries.

Preprocessing

Four steps before anything gets indexed

Every document — and every query, at search time — goes through the same pipeline before touching the index.

Stopword removal
NLTK Arabic list + a large custom list
Cleaning
maha: harakat, tatweel, links, emojis, punctuation
Normalization
maha normalize + custom lam-alef handling
Light stemming
Tashaphyne ArabicLightStemmer
Indexing & ranking

A hand-rolled tokenizer feeding scikit-learn's TF-IDF

A custom word-level tokenizer builds a frequency-filtered vocabulary (min frequency 5, 313 tokens survive) with PAD/OOV tokens, which is then passed as the fixed vocabulary to scikit-learn's TfidfVectorizer. A query is preprocessed identically, vectorized, and scored against the full matrix with linear_kernel — equivalent to cosine similarity since TF-IDF vectors are L2-normalized — returning the top 5 matches with search latency shown in the UI.

Companion tooling

Arabizi transliteration, adapted from DSAraby

The repo also bundles a small transliteration helper that maps Latin-script Arabic ("Arabizi", e.g. chokran likom kamliin) back to Arabic script — adapted from the DSAraby project rather than written from scratch.

Method

A one-time corpus preprocessing + indexing pass builds a fixed-vocabulary TF-IDF matrix; each query runs through the same preprocessing before being scored against it.

  1. 01
    Corpus

    6,366 scraped articles, 4,998 usable

  2. 02
    Preprocess + tokenize

    clean, normalize, stem, 313-token vocab

  3. 03
    TF-IDF + cosine sim.

    top-5 ranked results

Stack

scikit-learnTfidfVectorizer + cosine similaritymahaArabic text cleaning + normalizationTashaphyneArabic light stemmerNLTKArabic stopword listStreamlitsearch UI

Reproduce it

Local
$ git clone https://github.com/baselhusam/Search-Engine.git
$ pip install -r requirements.txt
$ streamlit run search_engine.py