Skip to content

raeesiarya/PerceptNet

Repository files navigation

PerceptNet: Revisiting Linear and Neural Perceptrons for Text Classification

A controlled comparison of sparse linear classifiers and embedding-based multilayer perceptrons across sentiment and topic classification.

Abstract

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).

1. Tasks and Data

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.

2. Methods

2.1 Sparse Linear Perceptron

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.

2.2 Embedding-based MLP

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.

3. Setup

We use uv for environment and dependency management:

uv sync

Commands below can be run inside the environment via uv run, e.g. uv run python perceptron.py -d sst2 -f bow.

4. Reproducing the Experiments

# Linear perceptron
python perceptron.py -d newsgroups -f bow
python perceptron.py -d sst2 -f bow

# Embedding-based MLP
python multilayer_perceptron.py -d newsgroups

Feature ablations for the linear model can be specified with +-joined feature names, e.g. -f bow+len.

5. Evaluation

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.py

It is recommended to confirm all unit tests pass prior to submission.

Reproducibility Note

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

About

PerceptNet: A controlled comparison of sparse linear perceptrons and embedding-based MLPs for text classification on SST-2 sentiment and 20 Newsgroups topic tasks.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages