Computational, applied machine learning

Machine learning projects

Machine-learning projects I have built while learning the field. The code is on GitHub.

Setting
Self-directed, alongside my physics work
Period
2026
Stack
Python, PyTorch, scikit-learn, Hugging Face Transformers, LangChain, ChromaDB, FastAPI
Code

Dialogue summarisation with a fine-tuned T5

The goal was a model that turns a chat conversation into a one- or two-sentence summary. I fine-tunedt5-small on SAMSum, a dataset of messenger-style dialogues with human-written summaries, and wrapped the result in a small web app.

Approach

  • Sampled 4,000 training and 500 validation dialogues from SAMSum (fixed random seed).
  • Cleaned the text (line breaks, extra whitespace, HTML tags, lower case) and tokenised it with the T5 tokenizer: 512 tokens for dialogues, 150 for summaries.
  • Fine-tuned with the Hugging Face Trainer for 6 epochs, batch size 8, weight decay 0.01 and 500 warm-up steps, on a CUDA GPU.
  • Served the model with FastAPI: a POST /summarize/ endpoint and a simple HTML front end, decoding with 4-beam search.

Results

Epoch123456
Validation loss0.3810.3590.3550.3510.3500.350

From the trainer log of the main run. Most of the improvement comes in the first two epochs.

Validation loss of T5-small falling from 0.381 to 0.350 over six epochs.
Validation loss per epoch while fine-tuning T5-small on SAMSum. Drawn from trainer_state.json.

Retrieval-augmented generation over PDFs

A question-answering pipeline over my own documents. Instead of asking a language model directly, it first finds the passages most relevant to the question and gives them to the model as context.

Approach

  • Loaded PDFs and text with LangChain loaders and split them into 500-character chunks with 50 characters of overlap.
  • Embedded the chunks with the sentence-transformer all-MiniLM-L6-v2 (384 dimensions) and stored them in a persistent ChromaDB collection with per-chunk metadata.
  • Wrote small classes for the embedding model, the vector store and the retriever.
  • For a question, retrieved the top-k chunks and prompted an LLM served through the Groq API (openai/gpt-oss-120b) to answer from that context.
Diagram of the RAG pipeline: PDFs, chunks, embeddings and a Chroma vector store feed a retriever, prompt and LLM.
The pipeline as built in the notebook: ingestion (top row) and answering a question (bottom row). Diagram of RAG_pipeline.ipynb.

Supervised learning projects

Three end-to-end classification problems on tabular data, each with cleaning, encoding, scaling, a train–test split and a comparison of several models.

Loan approval

Predicting whether a loan application is approved from 1,000 records with 20 columns. After imputing missing values and encoding categories, I compared logistic regression, KNN and Gaussian Naive Bayes, then added engineered features such as a squared credit score and log-transformed income.

F1 scores of three loan-approval classifiers before and after feature engineering.
Test F1 before and after feature engineering. Logistic regression improved most, from 0.78 to 0.81. Values from the saved notebook outputs.

Health-risk classification

Classifying 9,800 health records as healthy or unhealthy, comparing single models with ensembles. Random forest did best, with gradient boosting close behind.

Accuracy and recall of five classifiers for health-risk prediction; random forest highest at 0.938 accuracy.
Test accuracy and recall on 1,910 held-out records. Values from the saved notebook outputs.

Purchase intent

Predicting whether an online shopping session ends in a purchase, from 12,330 sessions. A pruned decision tree in a scikit-learn pipeline with class balancing reached F1 0.628, against a target of 0.55; a grid search over depth and leaf size gave 0.634.

ProjectBest modelTest result
Loan approvalLogistic regression, engineered featuresAccuracy 0.88, F1 0.81
Health riskRandom forest, 200 treesAccuracy 0.938, recall 0.959
Purchase intentPruned decision tree, grid searchF1 0.634
Employee turnoverLogistic regression, L1Accuracy 0.870

Neural networks in PyTorch

Four networks written in PyTorch, each trained and evaluated on a held-out test set: feed-forward networks for a classification and a regression problem, a convolutional network for images and a recurrent network for text.

Test results of four PyTorch networks: 95.6% and R² 0.935 for feed-forward networks, 72.5% on CIFAR-10, 85.2% on IMDB.
Held-out test results. Values from the saved notebook outputs.
NetworkTaskTest result
Feed-forwardDate-fruit variety, 7 classesAccuracy 95.6%
Feed-forwardPower-plant energy output (regression)R² 0.935
Convolutional, 10 epochsCIFAR-10 images, 10 classesAccuracy 72.5%
Recurrent, TF-IDF inputsIMDB review sentimentAccuracy 85.2%

Machine learning from scratch

To understand what the libraries do, I wrote several algorithms in NumPy alone: KNN for classification and regression, linear regression by gradient descent and by ordinary least squares, and logistic regression by gradient descent. Alongside these are notebooks on clustering (K-means, hierarchical, DBSCAN), PCA, anomaly detection and SVMs.

Known gaps

  • The summariser has not been scored with ROUGE yet, so the losses above are its only evaluation.

    The padding tokens in the labels are not masked out, so the loss values are not comparable to published SAMSum results.

  • The RAG similarity score is computed as 1 − distance on Chroma's default L2 distance, so it is not a true cosine similarity.

    Creating the collection with cosine distance would fix this.

  • The recurrent network classifies TF-IDF vectors rather than word sequences, and the stop-word step strips some characters from words.

    Visible in the preprocessing outputs of the notebook.