Total Pageviews

Monday, August 31, 2026

🌐 ANN + NLP Example: Language Detection Use Natural Language Processing and an Artificial Neural Network to identify the language of a sentence.

🌐 ANN + NLP Example: Language Detection

Use Natural Language Processing and an Artificial Neural Network to identify the language of a sentence.

1. Problem Definition

Suppose a user enters a sentence and the system has to determine whether it is written in English, Bengali, or Hindi.

NLP analyzes the text and extracts numerical features. The ANN then uses these features to predict the language.

NLP Language Detection Feature Extraction ANN Classification

2. Input Sentence

"আমি বাংলা ভাষায় কথা বলি"
Bengali sentence

The objective is for the ANN to identify this sentence as Bengali.

3. NLP Feature Extraction

For this classroom demonstration, NLP produces three simplified numerical scores.

Feature Value Interpretation
English Pattern Score 0.10 Very little English evidence
Bengali Pattern Score 0.90 Strong Bengali evidence
Hindi Pattern Score 0.20 Small Hindi evidence
Note:

Real language-detection systems generally use richer features, such as character n-grams, word frequencies, TF-IDF vectors, or learned embeddings. The three scores here are simplified so students can understand the ANN mathematics.

4. ANN Architecture

INPUT LAYER
English Score
X₁ = 0.10
Bengali Score
X₂ = 0.90
Hindi Score
X₃ = 0.20
OUTPUT LAYER
Bengali
Probability

5. Step-by-Step ANN Mathematics

Click each button to understand how the ANN makes its prediction.

1 NLP Converts Text into Numbers

NLP analyzes the sentence:

"আমি বাংলা ভাষায় কথা বলি"

The simplified feature extractor produces:

X₁ = English Pattern Score = 0.10
X₂ = Bengali Pattern Score = 0.90
X₃ = Hindi Pattern Score = 0.20

2 Assign Weights and Bias

Suppose the Bengali-detection hidden neuron has learned:

W₁ = -0.20
W₂ = 0.70
W₃ = -0.10
Bias = 0.20

Notice that the Bengali feature has a strong positive weight, while the English and Hindi features have negative weights.

3 Calculate Weighted Sum

The neuron equation is:

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

Substitute the values:

Z = (0.10 × -0.20) + (0.90 × 0.70) + (0.20 × -0.10) + 0.20

Calculate each multiplication:

0.10 × -0.20 = -0.020
0.90 × 0.70 = 0.630
0.20 × -0.10 = -0.020

Add all terms:

Z = -0.020 + 0.630 - 0.020 + 0.200

Z = 0.790

Therefore: Weighted Sum = 0.790.

4 Apply Sigmoid Activation

The sigmoid function is:

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

We have:

Z = 0.790

Substitute:

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

Approximately:

e-0.790 ≈ 0.454

H₁ = 1 / (1 + 0.454)

H₁ ≈ 0.688

Therefore: H₁ ≈ 0.688.

5 Calculate Bengali Probability

Suppose the output neuron uses:

Output Weight = 1.60
Output Bias = -0.50

Calculate the output weighted sum:

Zout = (H₁ × 1.60) - 0.50

Substitute:

Zout = (0.688 × 1.60) - 0.50

Calculate:

0.688 × 1.60 = 1.1008

Zout = 1.1008 - 0.50

Zout = 0.6008

Apply sigmoid:

P(Bengali) = 1 / (1 + e-0.6008)

P(Bengali) ≈ 0.646
Bengali Probability ≈ 64.6%

6 Final Language Decision

Suppose the classification threshold is:

Threshold = 50%

The ANN predicts:

P(Bengali) = 64.6%

Compare:

64.6% ≥ 50%
🇧🇩 PREDICTION: BENGALI LANGUAGE

Therefore, the simplified ANN classifies the input sentence as Bengali.

6. Complete NLP → ANN Flow

INPUT TEXT

"আমি বাংলা ভাষায় কথা বলি"


NLP FEATURE EXTRACTION
English Score = 0.10
Bengali Score = 0.90
Hindi Score = 0.20


ANN INPUT
X₁ = 0.10
X₂ = 0.90
X₃ = 0.20


WEIGHTED SUM
Z = (0.10 × -0.20) + (0.90 × 0.70) + (0.20 × -0.10) + 0.20
Z = 0.790


SIGMOID
H₁ ≈ 0.688


OUTPUT
Zout = (0.688 × 1.60) - 0.50
Zout = 0.6008


FINAL SIGMOID
P(Bengali) ≈ 0.646


64.6% → BENGALI LANGUAGE 🇧🇩

7. Important NLP + ANN Terms

NLP Language Detection Text Classification Tokenization Character N-Gram Feature Extraction Weight Bias Neuron Weighted Sum Hidden Layer Activation Function Sigmoid Probability Threshold Classification

Key idea: NLP converts language into numerical information. The ANN processes these values using weights and biases and produces a probability that can be used for language classification.

No comments:

Post a Comment