📧 ANN + NLP Example: Spam Email Detection
Use Natural Language Processing features and an Artificial Neural Network to determine whether an email is SPAM or NOT SPAM.
1. What is NLP?
Natural Language Processing (NLP) allows computers to process and analyze human language.
For spam detection, NLP can convert an email into numerical features. The ANN then uses these features to make a classification.
NLP Text Processing Feature Extraction ANN Classification2. Example Email
Message:
"Congratulations! You are a lucky winner. Claim your FREE reward now. Click the link to receive your prize."
The email contains words and patterns that may be associated with spam. NLP converts these observations into numerical features.
3. NLP Feature Extraction
| NLP Feature | Value | Meaning |
|---|---|---|
| Spam Word Score | 0.90 | Many spam-related words detected |
| Promotional Word Score | 0.80 | Many promotional words detected |
| Suspicious Link Score | 0.70 | Suspicious link pattern detected |
These three values are manually chosen feature scores so that the ANN calculation can be demonstrated easily. A real spam classifier could use thousands of text features or learned text embeddings.
4. ANN Architecture
X₁ = 0.90
X₂ = 0.80
X₃ = 0.70
Probability
The three NLP features enter the ANN. The hidden layer processes them, and the output layer produces a spam probability.
5. Step-by-Step ANN Mathematics
Click each button to reveal the calculation.
1 NLP Creates Numerical Inputs
NLP analyzes the email and creates three simplified numerical features:
X₂ = Promotional Word Score = 0.80
X₃ = Suspicious Link Score = 0.70
These values become the inputs for the ANN.
2 Assign Weights and Bias
Suppose the hidden neuron H₁ has learned:
W₂ = 0.30
W₃ = 0.20
Bias = 0.10
These values determine the contribution of each feature to the hidden neuron.
3 Calculate Weighted Sum
The neuron calculates:
Substitute the values:
Calculate each multiplication:
0.80 × 0.30 = 0.240
0.70 × 0.20 = 0.140
Add all the values:
Z = 0.930
Therefore: Weighted Sum = 0.930.
4 Apply Sigmoid Activation
The sigmoid function is:
Since:
Substitute:
Approximately:
H₁ ≈ 1 / (1 + 0.395)
H₁ ≈ 0.717
Therefore: H₁ ≈ 0.717.
5 Calculate the Output Probability
Suppose the output neuron has:
Output Bias = -0.30
First calculate:
Substitute:
Calculate:
Zout = 1.0038 - 0.30
Zout = 0.7038
Apply sigmoid:
P(Spam) ≈ 0.669
6 Make the Final Decision
Suppose our classification threshold is:
The ANN predicts:
Compare:
Therefore, the simplified ANN classifies this email as SPAM.
6. Complete NLP → ANN Mathematical Flow
↓
"Congratulations! You have won a FREE prize..."
↓
NLP FEATURE EXTRACTION
Spam Score = 0.90
Promotional Score = 0.80
Link Score = 0.70
↓
ANN INPUT
X₁ = 0.90
X₂ = 0.80
X₃ = 0.70
↓
WEIGHTED SUM
Z = (0.90 × 0.50) + (0.80 × 0.30) + (0.70 × 0.20) + 0.10
Z = 0.930
↓
SIGMOID
H₁ ≈ 0.717
↓
OUTPUT
Zout = (0.717 × 1.40) - 0.30
Zout = 0.7038
↓
FINAL SIGMOID
P(Spam) ≈ 0.669
↓
66.9% → SPAM EMAIL 🚨
7. Important NLP + ANN Terms
NLP Text Processing Tokenization Feature Extraction Spam Detection Neuron Weight Bias Weighted Sum Hidden Layer Output Layer Sigmoid Probability Classification ThresholdKey idea: NLP converts text into numerical information. The ANN processes those numerical features using weights, biases and activation functions to produce a final prediction.
No comments:
Post a Comment