🧠 ANN + NLP Example: Sentiment Analysis
Use Natural Language Processing features and an Artificial Neural Network to determine whether a review is Positive or Negative.
1. What is NLP?
Natural Language Processing (NLP) is a branch of Artificial Intelligence that enables computers to process and understand human language.
In sentiment analysis, NLP converts text into numerical features that a machine-learning model can process.
Text Tokenization Features ANN Sentiment2. Example Customer Review
"The movie was excellent and amazing. I really enjoyed it."
The NLP system analyzes the sentence and converts the text into numerical features.
3. Convert Text into Numerical Features
| NLP Feature | Value | Meaning |
|---|---|---|
| Positive Word Score | 0.90 | Strong positive words detected |
| Negative Word Score | 0.10 | Small negative contribution |
| Review Length Score | 0.50 | Normalized text length |
NLP can use many different representations, such as Bag-of-Words, TF-IDF, word embeddings, or contextual embeddings. For this simple classroom example, we use three manually defined numerical features so the ANN mathematics is easy to follow.
4. ANN Architecture for Sentiment Analysis
X₁ = 0.90
X₂ = 0.10
X₃ = 0.50
Probability
The text is first converted into numerical features. These features are then processed by the ANN.
5. Step-by-Step ANN Mathematics
Click the buttons below to see how the review is classified.
1 NLP Converts Text into Numbers
The review:
For our simplified example, NLP produces:
X₂ = Negative Word Score = 0.10
X₃ = Review Length Score = 0.50
These numerical values become the inputs to the ANN.
2 Assign Weights and Bias
Suppose the hidden neuron H₁ has learned:
W₂ = -0.30
W₃ = 0.20
Bias = 0.10
The negative weight for the negative-score feature means that, in this simplified model, a higher negative score reduces the neuron's activation.
3 Calculate the Weighted Sum
The neuron uses:
Substitute the values:
Calculate each term:
0.10 × -0.30 = -0.030
0.50 × 0.20 = 0.100
Now add them:
Z = 0.710
Therefore: Weighted Sum = 0.710.
4 Apply Sigmoid Activation
We use the sigmoid activation function:
Since:
Substitute:
Approximately:
H₁ ≈ 1 / (1 + 0.492)
H₁ ≈ 0.670
Therefore: H₁ ≈ 0.670.
5 Calculate the Output
Suppose the output neuron has:
Output Bias = -0.40
Calculate the output weighted sum:
Substitute:
Calculate:
Zout = 1.005 - 0.40
Zout = 0.605
Apply sigmoid to obtain the positive sentiment probability:
P(Positive) ≈ 0.647
6 Make the Final Sentiment Prediction
Suppose the classification threshold is:
The ANN predicted:
Compare:
Therefore, the ANN classifies the review as Positive.
6. Complete NLP → ANN Flow
↓
"The movie was excellent and amazing..."
↓
NLP FEATURE EXTRACTION
Positive Score = 0.90
Negative Score = 0.10
Length Score = 0.50
↓
ANN INPUT
X₁ = 0.90
X₂ = 0.10
X₃ = 0.50
↓
WEIGHTED SUM
Z = (0.90 × 0.60) + (0.10 × -0.30) + (0.50 × 0.20) + 0.10
Z = 0.710
↓
SIGMOID
H₁ ≈ 0.670
↓
OUTPUT
Zout = (0.670 × 1.50) - 0.40
Zout = 0.605
↓
FINAL SIGMOID
P(Positive) ≈ 0.647
↓
64.7% → POSITIVE SENTIMENT 😊
7. Important NLP + ANN Terms
NLP Text Tokenization Feature Extraction Positive Score Negative Score Neuron Weight Bias Weighted Sum Activation Function Sigmoid Sentiment Analysis ClassificationKey idea: NLP converts human language into numerical representations. The ANN then processes those numerical inputs and produces a prediction.
No comments:
Post a Comment