explaingit

bentrevett/pytorch-sentiment-analysis

4,605Jupyter NotebookAudience · developerComplexity · 2/5Setup · easy

TLDR

Four hands-on tutorials teaching you how to classify text as positive or negative using PyTorch, progressing from a simple word-bag model through LSTM, CNN, and finally fine-tuned BERT.

Mindmap

mindmap
  root((pytorch-sentiment-analysis))
    Tutorials
      Bag of words
      LSTM model
      CNN model
      BERT fine-tuning
    Tech Stack
      Python PyTorch
      Jupyter Notebook
    Audience
      ML learners
      Developers
    Use Cases
      Text classification
      NLP learning
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Learn how to build a sentiment classifier for movie reviews using PyTorch, from a bag-of-words baseline up to BERT.

USE CASE 2

Fine-tune a pre-trained BERT model for your own text classification task by following the fourth notebook.

USE CASE 3

Understand the practical difference between LSTM and CNN when applied to text by running the second and third notebooks side by side.

USE CASE 4

Run all four notebooks directly in a browser without any local setup via Colab.

Tech stack

PythonPyTorchJupyter NotebookBERTLSTM

Getting it running

Difficulty · easy Time to first run · 30min

Requires Python 3.9, install all dependencies with a single pip command or run notebooks directly in Colab.

In plain English

This repository is a set of four step-by-step tutorials that teach you how to build models that can read text and decide whether it carries a positive or negative tone. The specific task throughout is predicting the sentiment of movie reviews, which is a classic and well-understood problem that makes it easy to see whether a model is working. Each tutorial is a self-contained notebook you can open directly in a browser and run without setting up anything on your own computer. The first tutorial introduces the simplest possible approach: a neural bag-of-words model, which treats a sentence as an unordered collection of words and learns which words tend to signal positive or negative meaning. The second adds a recurrent neural network, a type of model that reads words one at a time and tries to remember context as it goes, using a popular variant called LSTM. The third tutorial switches to a convolutional approach, which scans over small windows of words rather than reading the whole sequence at once. The fourth and final tutorial loads a pre-trained BERT model, a large transformer that was trained on enormous amounts of text before being fine-tuned for this specific task. Each tutorial builds conceptually on the one before it, so reading them in order gives a clear progression from simple to sophisticated. The tutorials are written for Python 3.9 and use PyTorch as the core framework. Dependencies install with a single command. An older set of tutorials exists in a legacy folder for anyone who worked through the previous version and wants to reference it, but the main four notebooks are the current recommended path. This is a learning resource aimed at people who want to understand how text classification works in practice, not just in theory. It does not ship a production tool or a web interface. If you want to understand how modern language models approach simple classification tasks, this is a clear and hands-on starting point.

Copy-paste prompts

Prompt 1
Using the bentrevett/pytorch-sentiment-analysis tutorials, show me how to build a bag-of-words text classifier in PyTorch.
Prompt 2
How do I fine-tune BERT for sentiment analysis using the fourth notebook in bentrevett/pytorch-sentiment-analysis?
Prompt 3
What are the main differences between the LSTM and CNN approaches in the pytorch-sentiment-analysis tutorials?
Prompt 4
Help me adapt the LSTM sentiment model from these tutorials to classify my own dataset of product reviews.
Prompt 5
Walk me through why BERT outperforms LSTM on sentiment analysis based on the progression in these four notebooks.
Open on GitHub → Explain another repo

← bentrevett on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.