A controlled comparison of sparse linear classifiers and embedding-based multilayer perceptrons across sentiment and topic classification.
We present PerceptNet, a compact framework for studying two foundational approaches to text classification under a shared evaluation protocol. The first is a sparse linear perceptron operating over bag-of-words and hand-engineered features; the second is an embedding-based multilayer perceptron (MLP) that mean-pools learned token representations before a stack of nonlinear layers. By holding the data pipeline, train/validation split, and metric fixed, PerceptNet isolates the effect of model class on two contrasting tasks: binary sentiment (SST-2) and multi-class topic classification (20 Newsgroups).
| Dataset | Task | Classes | Split source |
|---|---|---|---|
sst2 |
Sentiment (positive/negative) | 2 | data/sst2/ |
newsgroups |
Topic classification | 20 | data/newsgroups/ |
All datasets follow a train / dev / test layout. A fixed-seed shuffle
reserves 5% of the training set for validation, ensuring reproducible runs.
A multiclass perceptron with weights keyed by (feature, label) pairs. Features
are modular and composable (e.g. bow, len, or bow+len), enabling ablation
over feature design. Training uses online updates with a step-decayed learning
rate.
A neural classifier that embeds tokens, applies length-normalized mean pooling over the (padded, masked) sequence, and feeds the pooled representation through two hidden layers with batch normalization, LeakyReLU activations, and dropout regularization. Optimized with Adam under a stepwise learning-rate schedule.
We use uv for environment and dependency
management:
uv syncCommands below can be run inside the environment via uv run, e.g.
uv run python perceptron.py -d sst2 -f bow.
# Linear perceptron
python perceptron.py -d newsgroups -f bow
python perceptron.py -d sst2 -f bow
# Embedding-based MLP
python multilayer_perceptron.py -d newsgroupsFeature ablations for the linear model can be specified with +-joined feature
names, e.g. -f bow+len.
We report classification accuracy on the held-out development set; predictions
on the unlabeled test set are written to results/. To verify the
implementation against the reference test suite:
pytest
pytest tests/test_perceptron.py
pytest tests/test_multilayer_perceptron.pyIt is recommended to confirm all unit tests pass prior to submission.
Please do not commit changes to the following files and directories, as doing so may cause the GitHub Classroom autograder to flag your submission:
tests/
.github/
pytest.ini