What I built
I built a C++ classifier inspired by Piazza posts. It learns from discussions that already have topic labels, then uses what it learned to identify the most likely topic of a new post. The labels are read from the training data instead of being hardcoded into the program.
Training the model
The training data comes from CSV files containing a label and the text of each post. I treat every post as a bag of unique words, which means word order and repeated occurrences do not change the result. Sets and maps store the vocabulary, the number of posts for each label, and how often each word appears overall and within each label.
Making a prediction
The classifier uses a simplified multivariate Bernoulli Naive Bayes model. For each possible label, it combines the label’s prior probability with the likelihood of the words in the post. It uses log-probability scores to keep the calculation manageable, then selects the label with the highest score. The completed program can train from one dataset, classify a separate set of posts, and compare its predictions with the correct labels.