Lensa ML
Lensa ML

Text Classification

Step 1 of 6

Bag of Words

From text to feature vectors

Vocabulary size6
Input sentence:thismoviewasgreatandamazingBag-of-Words vector (vocab=6):great1terrible0love0hate0good0bad0Non-vocabulary words ("this", "movie", "was", "and") are ignored
VOCAB SIZE
6
NON-ZERO
1
SPARSITY
83%

With a 6-word vocabulary, the sentence becomes a 6-dimensional vector. Most entries are 0 (83% sparse). BoW ignores word order — "great and amazing" = "amazing and great".

Step 1 of 6: Bag of Words

From text to feature vectors

Vocabulary size6
Input sentence:thismoviewasgreatandamazingBag-of-Words vector (vocab=6):great1terrible0love0hate0good0bad0Non-vocabulary words ("this", "movie", "was", "and") are ignored
VOCAB SIZE
6
NON-ZERO
1
SPARSITY
83%

With a 6-word vocabulary, the sentence becomes a 6-dimensional vector. Most entries are 0 (83% sparse). BoW ignores word order — "great and amazing" = "amazing and great".

Step 2 of 6: Feature Space

Documents as data points

Sentence (1/8)0
thismoviewasgreatandamazing
1122330positive word count →negative word count →+(2, 0)+++PositiveNegative
POS WORDS
2
NEG WORDS
0
TRUE LABEL
Positive
SEPARABLE?
Yes ✓

This sentence has 2 positive words and no negative words — it maps to the bottom-right of the plot. Notice how all positive reviews land in this region, away from negative ones.

Step 3 of 6: Training a Classifier

Finding a decision boundary

Decision boundary angle (°)135
positive wordsnegative words++++
ANGLE
135°
ACCURACY
0%
CORRECT
0/8

Only 0% accuracy — the boundary is far from optimal. Try rotating to ~135° where positive words (x-axis) and negative words (y-axis) create natural separation.

Step 4 of 6: Softmax & Confidence

From scores to probabilities

Temperature1.00
softmax(z_i / T) — T = 1.0Raw logits:2.1Positive-1.5Negative÷T, exp, normProbabilities:97.3%2.7%Confidence meter97.3%0.112.55argmax (one-hot)standarduniform
TEMPERATURE
1.0
P(POSITIVE)
97.3%
P(NEGATIVE)
2.7%
CONFIDENCE
97.3%

Temperature 1.0: the model assigns 97% to Positive and 3% to Negative. At T=1 (standard softmax), the probabilities reflect the raw logit gap.

Step 5 of 6: Sentiment Polarity

Positive, negative, and neutral

Sentence (1/8)0
1. Look up each word in the sentiment lexicon:this+0.00movie+0.00was+0.00great+0.40and+0.00amazing+0.482. Visualize each word's contribution:0+3. Sum all scores → polarity:+0.40 +0.48 = +0.884. Map to polarity scale [−1, +1]:−1 (negative)0+1 (positive)POSITIVE (+0.88)
POLARITY
+0.88
SCORED WORDS
2/6
RAW SUM
+0.88
SENTIMENT
Positive

Positive words (great, amazing) contribute +0.40, +0.48. These sum to +0.88, giving a clear positive polarity. Lexicon-based scoring is simple but effective for obvious sentiment.

Step 6 of 6: Beyond Binary

Multi-class text classification

Number of classes2
PositiveNegativePositiveNegative
CLASSES
2
SAMPLES
10
BOUNDARIES
1

Binary classification: just positive vs. negative. One decision boundary separates two regions. This is the simplest case — a single threshold on the sentiment score.