Suffolk University • Sawyer Business School

Neural Networks, Embeddings & LLMs as Features

A multilayer perceptron on tabular data (and why it usually loses to boosting), text as features — TF-IDF, sentence embeddings, zero-shot LLM labels — and the AI-assisted analyst's workflow: generate, verify, own

Session 12 of 13 · Mon Dec 7
Module: Time & Text
150 Minutes
Mondays 5:00 PM
Hands-On Learning
01 // LEARNING OBJECTIVES

What You'll Learn Today

By the end of tonight you'll have both the concept and the working code — every objective maps to a cell you run yourself.

01

Train a Neural Network and Know When Not To

MLPClassifier on Telco: layers, activations, epochs, and the honest result — on a 7,000-row table it ties logistic regression and loses to boosting. Neural nets earn their keep on text, images, and sequences.

02

Turn Text Into Features Three Ways

TF-IDF (counts), sentence embeddings (meaning), and zero-shot LLM labels (judgment). Same reviews, three feature sets, three price points — and a clear winner for each budget.

03

Use LLM Embeddings Inside a Tabular Model

Embed the free-text column, append it to the structured features, and let gradient boosting use both. The 2025 evidence: biggest gains on small, imbalanced, or text-rich problems.

04

Work With an AI Coding Assistant Without Losing the Plot

Colab's Data Science Agent, Jupyter AI, Claude Code: generate the boilerplate, then verify the split, the leakage, and the metric yourself. The analyst who can't explain the cell didn't write it.

02 // SESSION AGENDA

Today's Journey

A business question, a dataset, a model — and the judgment to evaluate it.

5:00 PM - 5:20 PM

Project Check-In & What a Neural Network Is

20 minutes

Where every project stands after Milestone 3, then the model everyone has heard of: layers of weighted sums and nonlinear activations, trained by gradient descent on a loss. A logistic regression is a neural network with no hidden layer. MLPClassifier makes it three lines.

  • Scale the inputs — a neural net is more sensitive to scale than kNN
  • Hidden layers, learning rate, epochs, early stopping: the same overfitting story, new vocabulary
5:20 PM - 5:40 PM

MLP vs. Boosting on Tabular Data — The Honest Result

20 minutes

MLPClassifier on the Telco pipeline: AUC within a point of logistic regression, below the boosted model, three times slower to tune. This is the Grinsztajn result on a business table. Then where neural nets win: text, images, audio, sequences — anything without a fixed set of columns.

  • On tabular business data, reach for boosting first and a TFM second; a plain MLP is rarely the answer
  • Deep learning's real gift to tabular work is embeddings — dense vectors for text and categories
5:40 PM - 6:05 PM

Text as Features I: TF-IDF and Sentence Embeddings

25 minutes

Meet the data: Amazon product reviews, binary sentiment. TfidfVectorizer + logistic regression is a 30-second baseline that reaches ~88% accuracy. A sentence-transformer (all-MiniLM-L6-v2) turns each review into a 384-number vector that captures meaning, not just words — and a logistic regression on those vectors does about as well with a fraction of the features.

  • TF-IDF: sparse, fast, interpretable (read the coefficients); embeddings: dense, semantic, transferable
  • Embeddings are the bridge between deep learning and every model you already know
6:05 PM - 6:15 PM

Break

10 minutes

Stretch, coffee, last project questions.

6:15 PM - 6:45 PM

Text as Features II: Zero-Shot LLM Labels & Embeddings Inside Boosting

30 minutes

Ask an LLM to label 200 reviews with no training data: accuracy near the trained models, at a cost per call. Then the practical pattern: embed the free-text 'reason for contact' column in a churn table, append it to the structured features, and let boosting use both. The evidence says this helps most when the table is small or the text carries what the columns don't.

  • LLMs are competitive zero-shot on small, simple classification and fall behind tuned models as complexity grows (LLMTabBench, 2026)
  • Cost, latency, and privacy decide: embeddings once, LLM calls sparingly, boosting for the decision
6:45 PM - 7:15 PM

The AI-Assisted Analyst: Generate, Verify, Own

30 minutes

Live: Colab's Data Science Agent builds a churn notebook from a prompt in two minutes. We read it together and find what it got wrong — the split after the scaler, the leaked column, the metric it chose. Then the workflow that works: let the assistant draft, verify the four things that matter, and be able to explain every cell in the presentation.

  • The four things to verify in any AI-written notebook: the split, the leakage, the metric, the baseline
  • Claude Code and Jupyter AI can edit notebooks directly — the analyst's job shifts from typing to judging
7:15 PM - 7:30 PM

Dry Runs in Pairs & Final Week

15 minutes

Teams pair up: four minutes each with the Milestone 4 slides, two minutes of feedback on the one thing to fix. Then the map is complete: tabular → boosting and TFMs; text → embeddings and LLMs; time → lags and foundation models; everything → honest validation and a decision. Next Monday: ship it, then present.

  • Project notebook + 2-page decision memo + repo link due Mon Dec 14, 5:00 PM on Canvas — the start of the exam-week slot
  • Presentations Mon Dec 14, 8 minutes + 2 minutes Q&A per team, order posted Friday
03 // INTERACTIVE RESOURCES

Tools & Learning Materials

Notebooks, readings, explorers, and the stories behind the methods.

Hands-On

Session 12 Notebook — Neural Nets, Embeddings & LLMs as Features

MLPClassifier vs. boosting on Telco, TF-IDF vs. sentence embeddings on Amazon reviews, an optional zero-shot Claude cell, embeddings appended to a tabular model, and a checklist for verifying AI-generated notebooks.

Open in Colab
Video

3Blue1Brown — Neural Networks (video series)

The best visual explanation of what a neural network computes and how gradient descent trains it. Watch the first two before class; the transformer episodes explain what powers the embedding models.

Open the playlist
Tool

Sentence-Transformers Documentation

SentenceTransformer('all-MiniLM-L6-v2').encode(texts) — one line from text to a 384-dimensional meaning vector. The pretrained models page lists the speed/quality trade-offs.

Open the docs
Data

Amazon Polarity — the dataset (Hugging Face)

3.6 million Amazon reviews labeled positive/negative. We use a 5,000-review slice; the datasets library streams it with no login.

Open the dataset card
Interactive

TensorFlow Playground

Train a small neural network in your browser: add layers and neurons, change the activation, and watch the decision boundary bend. Ten minutes here and "hidden layer" stops being abstract.

Open the explainer
Interactive

MLU-Explain — Neural Networks

Forward pass, loss, backpropagation — as an interactive essay you can scroll through before class.

Open the explainer
Video

Kozyrkov — Making Friends with Machine Learning (full course)

Google's former Chief Decision Scientist's beloved conceptual course, free on YouTube: what ML is for, how projects fail, and how to think like a decision-maker. Six hours; watch the first hour before the project.

Watch on YouTube
Reading

Grinsztajn et al. (2022) & LLMTabBench (2026) — When Not to Use Deep Learning

LLMTabBench: LLMs are competitive zero-shot on low-data binary tasks but degrade past a complexity threshold, and few-shot examples can hurt. Pair with the 2022 tree-vs-NN benchmark for the full picture.

Read the abstract
Reading

LLM Embeddings as Features for Tabular Models (2024–25 evidence)

Embedding text fields and feeding them to XGBoost/CatBoost helps most on small, imbalanced, or text-rich datasets, and embedding-derived features often rank high in importance. The pattern we implement in class.

Read the paper
Tool

Google Colab — Data Science Agent

Upload a CSV, describe the goal, get a full notebook. Free in Colab. We use it live and then audit what it produced — the exercise that defines the AI-assisted analyst.

Read the announcement
Go Deeper

Claude Code for Data Scientists — Getting Started

A practical walkthrough of using an agentic coding assistant on notebooks and data pipelines, including the verification habits that keep it honest.

Read the guide
Go Deeper

Géron — Hands-On ML With Scikit-Learn & PyTorch (notebooks)

The PyTorch edition of the practitioner's classic. Chapters 10–11 (introduction to neural networks, training deep nets) are the natural continuation if you want to go deeper than MLPClassifier.

Open the notebooks
04 // HANDS-ON ACTIVITIES

Learning by Doing

Open the notebook and build it with us.

Activity 1

Three Ways to Read a Review

5,000 Amazon reviews, positive or negative. Build TF-IDF + logistic regression, then sentence-embeddings + logistic regression, compare accuracy and feature counts, and (optionally) ask an LLM to label 100 of them zero-shot.

1

Load a slice

datasets.load_dataset('fancyzhx/amazon_polarity', split='train[:5000]'). Stratified 80/20 split on the label.

2

Counts: TF-IDF

TfidfVectorizer(ngram_range=(1,2), min_df=3) → LogisticRegression. Accuracy, and the ten most positive and negative n-grams from the coefficients.

3

Meaning: embeddings

SentenceTransformer('all-MiniLM-L6-v2').encode() on the same texts → 384 features → LogisticRegression. Accuracy vs. TF-IDF; note the feature count.

4

Judgment: zero-shot (optional)

With an API key, ask Claude to label 100 test reviews 'positive' or 'negative'. Accuracy vs. the two trained models, and the cost per 1,000 reviews.

python
from datasets import load_dataset
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sentence_transformers import SentenceTransformer

ds = load_dataset('fancyzhx/amazon_polarity', split='train[:5000]')
texts, labels = ds['content'], ds['label']
X_tr, X_te, y_tr, y_te = train_test_split(texts, labels, test_size=0.2, stratify=labels, random_state=835)

# 1) Counts: TF-IDF
tfidf = TfidfVectorizer(ngram_range=(1, 2), min_df=3, sublinear_tf=True)
clf = LogisticRegression(max_iter=2000, C=3).fit(tfidf.fit_transform(X_tr), y_tr)
print(f'TF-IDF + logistic: {accuracy_score(y_te, clf.predict(tfidf.transform(X_te))):.3f}  ({len(tfidf.vocabulary_):,} features)')

# 2) Meaning: sentence embeddings (downloads a 90MB model once)
enc = SentenceTransformer('all-MiniLM-L6-v2')
E_tr, E_te = enc.encode(X_tr, batch_size=128, show_progress_bar=False), enc.encode(X_te, batch_size=128, show_progress_bar=False)
clf2 = LogisticRegression(max_iter=2000).fit(E_tr, y_tr)
print(f'embeddings + logistic: {accuracy_score(y_te, clf2.predict(E_te)):.3f}  ({E_tr.shape[1]} features)')

# 3) Judgment: zero-shot LLM labels — optional, needs ANTHROPIC_API_KEY; see the notebook

Three feature sets, three price points. TF-IDF is free and you can read its coefficients — 'waste of money' and 'highly recommend' sit at the two extremes. Embeddings cost one model download and capture meaning TF-IDF cannot ('not bad at all'). The LLM costs a call per review and needs no training data at all — the right tool for the first week of a project, the wrong tool for scoring a million reviews a day. The 2026 analyst picks by budget and volume, and usually ends up with embeddings feeding a model they can validate.

05 // KEY TAKEAWAYS

What to Remember

A neural network is stacked weighted sums with nonlinearities, trained by gradient descent. On a business table it rarely beats boosting; it wins on text, images, and sequences — anything without fixed columns.

Text becomes features three ways: TF-IDF (counts, interpretable), sentence embeddings (meaning, transferable), zero-shot LLM labels (judgment, per-call cost). Embeddings appended to a tabular model are the practical 2026 pattern.

Generate, verify, own. Let an AI assistant draft the notebook, then check the split, the leakage, the metric, and the baseline yourself — and be able to explain every cell without it.

06 // HOMEWORK

Before Next Session

Complete these before next Monday — they are the practice that makes the next session land.

Project Final Stretch No new homework. Final project notebook, 2-page decision memo, and repo link are due Mon Dec 14, 5:00 PM on Canvas, and presentations follow that evening in the exam-week slot. Before you submit, run the Session 12 verification checklist on your own notebook: is the split before every fitted transformer, is any feature recorded after the outcome, is the metric the one the decision needs, and does the model beat the obvious baseline? Bring your slides on a laptop; 8 minutes plus 2 for questions.
07 // PRACTICE

Test Yourself

Exam-style questions for the ideas in this session — Trees, Forests & Boosting and The Prediction Lifecycle. Every wrong answer names the misconception behind it.

Q25 99.6% train, 74% test. Which tree ships? Q26 Why a forest deliberately hides features from its own trees. Q27 Validation loss bottoms out at tree 500. Training loss keeps falling. Now what? Q28 The #1 feature is a customer ID hash. Which importance lied? Q29 GBDT vs neural net vs tabular foundation model on 40k rows — the 2026 answer. Q30 Parallel or sequential, variance or bias: bagging vs boosting in one line. Q01 Four analytics projects on the roadmap. Only one of them predicts. Q02 Unit, target, horizon, decision — the framing step everyone skips. Q03 A model beats "predict the majority" by two points. Is that a win? Q04 Train error falls, test error rises. Name the disease. Q05 Why the single most important line in the notebook is the split. Q06 Stratify or not? A 1% fraud rate makes the answer obvious — once you see it.

All of Ensembles → · All of Foundations →

Coming Next

Session 13: Ship It — Deployment, Monitoring & Your Prediction Story

Persist the pipeline, track experiments with MLflow, put a Gradio front end on a model in ten lines, watch for drift with Evidently, and the one-slide guide to the EU AI Act — then your presentations and the Signal Award.

DeploymentMonitoringFinal Presentations