Standalone punctuation breaks negation handling and reverses sentiment predictions

Open Beginner friendly
#28 1 comment 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 2 days

@vivek-3728 is already working on this.

Since Nov 1, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
87/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

The issue identifies the tokenizer in mess_mood/text.py and gives a reproduction for standalone punctuation between a negation word and the next word. Start by running those examples, then inspect the token cleanup and negation handling in that file. Add regression coverage for the listed examples; done means punctuation creates no empty features and the punctuated and unpunctuated sentences produce the same sentiment prediction.

Written by the indexing model from the issue text.

Description

good first issue
Description

I found a bug in the tokenizer where punctuation appearing as a separate word creates empty tokens and interferes with negation handling.

As a result, adding punctuation to a sentence can completely reverse its sentiment prediction, even though the actual words remain unchanged.

Steps to Reproduce

Run:

from mess_mood.text import tokenize

print(tokenize("not fresh"))
print(tokenize("not ... fresh"))
print(tokenize("good ... food"))

Actual output:

['not_fresh']
['not_', 'fresh', 'not__fresh']
['good', '', 'food', 'good_', '_food']

The issue also affects the trained sentiment classifier:

from mess_mood.data import load_reviews
from mess_mood.evaluate import fit

model = fit(load_reviews())

print(model.predict("not fresh"))
print(model.predict("not ... fresh"))

Actual predictions:

negative
positive
Expected Behavior

Standalone punctuation should not generate empty tokens or interrupt negation.

Both "not fresh" and "not ... fresh" should produce the same meaningful features and sentiment prediction.

Actual Behavior

When punctuation is separated by whitespace, the tokenizer strips it into an empty string but continues processing it as a normal token.

This creates invalid features such as not_, good_, and _food.

More importantly, the empty token interrupts negation handling. Instead of recognizing not_fresh, the tokenizer processes fresh as a normal word, causing the classifier to change its prediction from negative to positive.

Root Cause

In mess_mood/text.py, punctuation is stripped using:

words = [w.strip(".,!?;:\"'()[]{}") for w in text.lower().split()]

However, tokens that become empty after stripping are not filtered out before stopword removal and negation processing.

Suggested Fix

Filter out empty tokens after punctuation stripping, before applying negation and feature-generation logic.

Regression tests should cover standalone punctuation, particularly between a negation word and the word it modifies.

Related Issue

This is related to #2, but the root cause is different.

Issue #2 concerned punctuation attached to words. This issue specifically concerns standalone punctuation creating empty tokens and breaking negation handling, resulting in incorrect sentiment predictions.

Dominant language
Python
Stars
0
Forks
3
Avg merge
1d 9h
Merged PRs (30d)
13

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from techcsispit/mess-mood

All issues in techcsispit/mess-mood

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.