Total Pageviews

Monday, August 31, 2026

📧 ANN + NLP Example: Spam Email Detection

📧 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 Classification

2. Example Email

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
Educational simplification:

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

INPUT LAYER
Spam Word Score
X₁ = 0.90
Promotional Score
X₂ = 0.80
Link Score
X₃ = 0.70
OUTPUT LAYER
Spam
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₁ = Spam Word Score = 0.90
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.50
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:

Z = X₁W₁ + X₂W₂ + X₃W₃ + b

Substitute the values:

Z = (0.90 × 0.50) + (0.80 × 0.30) + (0.70 × 0.20) + 0.10

Calculate each multiplication:

0.90 × 0.50 = 0.450
0.80 × 0.30 = 0.240
0.70 × 0.20 = 0.140

Add all the values:

Z = 0.450 + 0.240 + 0.140 + 0.100

Z = 0.930

Therefore: Weighted Sum = 0.930.

4 Apply Sigmoid Activation

The sigmoid function is:

Sigmoid(z) = 1 / (1 + e-z)

Since:

Z = 0.930

Substitute:

H₁ = 1 / (1 + e-0.930)

Approximately:

e-0.930 ≈ 0.395

H₁ ≈ 1 / (1 + 0.395)

H₁ ≈ 0.717

Therefore: H₁ ≈ 0.717.

5 Calculate the Output Probability

Suppose the output neuron has:

Output Weight = 1.40
Output Bias = -0.30

First calculate:

Zout = (H₁ × Output Weight) + Output Bias

Substitute:

Zout = (0.717 × 1.40) - 0.30

Calculate:

0.717 × 1.40 = 1.0038

Zout = 1.0038 - 0.30

Zout = 0.7038

Apply sigmoid:

P(Spam) = 1 / (1 + e-0.7038)

P(Spam) ≈ 0.669
Spam Probability ≈ 66.9%

6 Make the Final Decision

Suppose our classification threshold is:

Threshold = 50%

The ANN predicts:

Spam Probability = 66.9%

Compare:

66.9% ≥ 50%
🚨 PREDICTION: SPAM EMAIL

Therefore, the simplified ANN classifies this email as SPAM.

6. Complete NLP → ANN Mathematical Flow

EMAIL TEXT

"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 Threshold

Key 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