$ show HandsOnLLM/Hands-On-Large-Language-Models
This repository is the companion code for the O'Reilly book 'Hands-On Large Language Models' by Jay Alammar and Maarten Grootendorst. It provides 12 chapters of Jupyter notebooks covering fundamental and advanced LLM topics including tokenization, embeddings, text classification, clustering, prompt engineering, semantic search, multimodal models, fine-tuning, and generation. All notebooks are designed to run on Google Colab with free GPU resources and rely heavily on Hugging Face libraries (transformers, datasets, sentence-transformers, TRL) and external APIs (OpenAI, Cohere). The code is educational in nature, with clear step-by-step explanations and visualizations. While it is not a production application or a novel research pipeline, it serves as a high-quality, reproducible tutorial resource for practitioners learning LLM workflows. The repository includes pinned dependencies, Conda environment setup, and local installation guides, making it relatively easy to reproduce in a controlled environment, though API keys are required for some sections.
The LLM identified 3 files worth highlighting for reuse:
Demonstrates a clean, reusable fine-tuning pipeline for BERT using Hugging Face Trainer. Covers full fine-tuning, frozen classifier, SetFit few-shot, masked language modeling, and NER. The pattern of loading tokenizer, defining data collator, setting training arguments, and using Trainer is universally applicable to any Hugging Face model. The SetFit pattern for few-shot is particularly valuable as a non-obvious technique. The notebook is well-commented and structured for easy extraction.
Provides a complete workflow for training and fine-tuning text embedding models using SentenceTransformers. Covers supervised losses (SoftmaxLoss, CosineSimilarityLoss, MultipleNegativesRankingLoss), unsupervised TSDAE, and augmented SBERT. The pattern of using SentenceTransformerTrainer with evaluators and MTEB benchmark is directly reusable for any embedding model training task. Includes data preparation for MNLI and STSB datasets.
Implements multiple text classification approaches: zero-shot with RoBERTa, few-shot with Flan-T5, and standard classification with GPT-3.5. Includes a reusable evaluation function using classification_report and comparison of model outputs. The pattern of using Hugging Face pipelines and prompt-based classification is adaptable to any text classification task.