លំហសិក្សាកម្ពុជា លំហសិក្សាកម្ពុជា V1.0
ចូល ចុះឈ្មោះ

Hybrid Spam Detection Framework

មូលសង្ខេប / Abstract

Combining Naive Bayes & DistilBERT for Intelligent Spam Detection

ពាក្យគន្លឹះ

1. Background & Objectives

1.1 Problem Statement

Global electronic communication continues to expand rapidly, with an estimated 392 billion emails sent daily worldwide, approximately 49% of which are flagged as spam. Email and SMS serve as critical everyday communication channels; however, the proliferation of spam, phishing attacks, financial scams, and embedded malicious links creates severe security vulnerabilities. Manual identification is unscalable and inefficient, necessitating automated Machine Learning (ML) and Natural Language Processing (NLP) solutions capable of keeping pace with continuously evolving threats.

1.2 Research Objectives

The primary objective of this project is to construct a scalable framework to classify text messages as either Spam or Ham (legitimate). The specific goals include:

  • Analyzing textual patterns in spam versus ham messages and preprocessing raw text corpora.
  • Implementing a classical Naive Bayes classifier utilizing TF-IDF features as a baseline.
  • Fine-tuning a DistilBERT Transformer model to capture deep contextual semantics.
  • Evaluating performance metrics and deploying a hybrid decision system via an interactive Streamlit web interface.

1.3 Key Research Questions

  1. How does the classical Naive Bayes model compare to the contextual DistilBERT model in terms of predictive accuracy and latency?
  2. Does dynamic contextual understanding significantly improve the detection of sophisticated spam messages?
  3. Can a hybrid tiered architecture effectively balance execution speed with high detection precision?

2. Dataset & Model Architecture

2.1 Dataset Overview

The project utilizes the SMS Spam Collection dataset sourced from the UCI Machine Learning Repository and Kaggle, containing approximately 5,572 binary-labeled text messages (Spam vs. Ham). The data processing pipeline involves removing duplicate entries followed by an 80/20 stratified train/test split to preserve the natural label imbalance ($\sim13\%$ spam ratio).

2.2 Model Selection

  • Naive Bayes (Speed): A classical probabilistic model paired with Term Frequency-Inverse Document Frequency (TF-IDF) feature vectorization. The preprocessing pipeline includes text cleaning, stop-word removal, and tokenization. It provides ultra-fast inference and low computational overhead, making it ideal for obvious, keyword-driven spam patterns.
  • DistilBERT (Context): A lightweight, distilled Transformer model utilizing WordPiece sub-word tokenization, attention masks, and input IDs. It requires minimal manual text preprocessing and excels at identifying complex, deceptive messages through context-aware token embeddings, albeit at a higher computational cost.

3. Architecture & Operational Workflow

3.1 Tiered Hybrid Architecture

The proposed system implements a two-tier decision cascade to optimize both throughput and accuracy:

  1. Input Ingestion: The raw incoming message is ingested.
  2. Tier 1 (Naive Bayes - TF-IDF): The lightweight model processes the text. If the probabilistic prediction confidence crosses a high/low certainty threshold, the final label (Spam or Ham) is emitted immediately.
  3. Tier 2 (DistilBERT Audit): If the Tier 1 prediction falls within an ambiguous confidence interval (borderline case), the message is escalated to DistilBERT for contextual evaluation.
  4. Final Output: Emits the verified classification decision.

                     +---------------------+

                     |    Input Message    |

                     +----------+----------+

                                |

                                v

                     +---------------------+

                     |  Text Preprocessing |

                     +----------+----------+

                                |

                                v

                     +---------------------+

                     | TIER 1: Naive Bayes |

                     +----------+----------+

                                |

                   /------------+------------\

                  /                           \

        [Clear Prediction]             [Borderline / Ambiguous]

                |                               |

                v                               v

    +-----------------------+       +-----------------------+

    | Final Decision:       |       | TIER 2: DistilBERT    |

    | Spam / Ham            |       | Contextual Audit      |

    +-----------------------+       +-----------+-----------+

                                                |

                                                v

                                    +-----------------------+

                                    | Final Decision:       |

                                    | Spam / Ham            |

                                    +-----------------------+

3.2 End-to-End Workflow Pipeline

The development lifecycle consists of nine sequential phases:

  1. Data Acquisition
  2. Data Cleaning & Deduplication
  3. Stratified Dataset Preparation
  4. Naive Bayes Baseline Training
  5. DistilBERT Fine-Tuning
  6. Comparative Model Evaluation
  7. Hybrid Decision Engine Integration
  8. Interactive Streamlit Interface Deployment
  9. Production-Ready Spam Classification Engine

4. Results & Explainability

4.1 Benchmark Performance Metrics

The models were evaluated across key performance metrics on the test dataset:

Metric

Naive Bayes

DistilBERT

Accuracy

$\sim97\%$

$\sim99\%$

Precision

$\sim95\%$

$\sim98\%$

Recall

$\sim93\%$

$\sim98\%$

F1-Score

$\sim94\%$

$\sim98\%$

Latency

$< 1\text{ ms/sample}$

$\sim15\text{--}30\text{ ms/sample}$

4.2 Model Explainability & Interpretability

  • Naive Bayes: Explainability is achieved through TF-IDF feature log-probabilities, directly exposing influential trigger words (e.g., "FREE", "CLAIM", "WINNER").
  • DistilBERT: Interpretability is derived by extracting multi-head attention weights, revealing inter-token relationships driving classification.
  • Security Value: Model auditing facilitates threat pattern verification, zero-day spam pattern detection, and adversarial attack mitigation.

5. Conclusion & Future Work

5.1 Summary

The hybrid framework effectively harmonizes the operational speed of Naive Bayes with the semantic intelligence of DistilBERT. This dual-tier methodology maximizes efficiency while guaranteeing contextual accuracy for sophisticated security threats.

5.2 Technical Constraints & Future Roadmaps

  • Limitations: Current implementation is restricted to English text corpora, requires dedicated GPU resources for DistilBERT inference, and faces risks from evolving adversarial evasion techniques.
  • Future Enhancements: Extending to multilingual spam detection, integrating real-time streaming pipelines, and establishing automated continuous model retraining.
  • Tech Stack: Python, Scikit-Learn, PyTorch, Hugging Face Transformers, Pandas/NumPy, Streamlit.

 

ចែករំលែក
រក្សាទុក
ការផ្សព្វផ្សាយ
ការផ្សព្វផ្សាយ
មតិយោបល់ 0
ចូលគណនី ដើម្បីបញ្ចេញមតិ