Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 8 min read How-to mediumAdept

Simple considerations for simple people building fancy neural networks

Building and debugging neural networks goes best with a disciplined workflow: inspect the data before modeling, establish simple baselines such as logistic regression on word2vec or fastText embeddings, and verify the implementation by overfitting a small batch (e.g. 16 examples) to near-zero loss with regularization off. Common silent bugs include wrong tensor indexing, forgetting model.eval() or zero_grad(), passing probabilities instead of logits to the loss, symmetric initialization, unused parameters, and bad tokenization. Plotting losses, parameters and gradients and printing model outputs during training helps catch problems. For hyperparameters, a random search over a manually defined grid is a strong baseline, and understanding each component beats blind tuning.

Assumes: neural network training basicsPyTorch basics

Related posts

  • The N Implementation Details of RLHF with PPO

    Hugging Face hardMaster

    A from-scratch PyTorch reproduction of OpenAI's 2019 lm-human-preferences RLHF codebase closely matches the original learning curves on stylistic tasks like sentiment and descriptiveness. Along the way it catalogs the implementation details that matter for faithful replication: reward model and value head scoring the concatenated query and response, a dedicated out-of-vocabulary padding token, position-index adjustment for padding, fixed-length sampling that ignores EOS, learning-rate annealing, per-process seeds, reward normalization, rejection sampling and reward whitening. It also documents a TensorFlow vs PyTorch Adam numerical difference that causes overly aggressive updates, and how different base models behave when reward labels come from gpt2-large. Practical notes show how to replicate each behaviour with Hugging Face transformers, along with the hardware constraints of running the original TF1 code.

  • Train a Sentence Embedding Model with 1B Training Pairs

    Hugging Face hardMaster

    Sentence embedding models trained with a contrastive multiple-negatives ranking loss (InfoNCE) on up to 1 billion sentence pairs, using in-batch negatives, a scaled similarity (C≈20), and cosine vs. dot-product tradeoffs for clustering and ANN search. Batch composition drives quality: larger batches, hard negatives, and batches drawn mostly from one dataset but mixing at least two to learn both local and global topic structure. Training ran on TPU v3-8s with JAX/Flax and produced 20 general-purpose Sentence Transformers models (MiniLM, RoBERTa, DistilBERT, MPNet) reported as state of the art on sentence similarity tasks, plus 8 datasets and a Spaces demo.

  • Generating Human-level Text with Contrastive Search in Transformers 🤗

    Hugging Face mediumAdept

    Contrastive search is a decoding method for neural text generation that picks each token from the model's top-k candidates by balancing model confidence against a degeneration penalty: the maximum cosine similarity between the candidate's hidden representation and those of prior context tokens. Greedy and beam search tend to produce repetitive text, and nucleus sampling tends to lose coherence. Contrastive search avoids both and is available in Hugging Face transformers via `penalty_alpha` and `top_k` in `generate()`. GPT-2 examples (k=4, α=0.6) and token-similarity matrices show it removes the off-diagonal repetition patterns that greedy search produces, and α=0 reduces it to greedy search.

  • Build a Domain-Specific Embedding Model in Under a Day

    Hugging Face mediumAdept

    A single-GPU pipeline fine-tunes Llama-Nemotron-Embed-1B-v2 for a specific domain in under a day without manual labels. An LLM generates synthetic single- and multi-hop QA pairs from raw documents, which are quality-filtered. The base model then mines hard negatives, using a 95% margin ceiling to avoid false negatives. Training is a contrastive biencoder run at temperature 0.02, followed by BEIR evaluation, ONNX/TensorRT export and serving through NIM. On NVIDIA docs this gave about 10% gains in NDCG@10 and Recall@10, and Atlassian raised Jira Recall@60 from 0.751 to 0.951. The guide also covers practical defaults: 1–2 epochs for real data, LR 1e-5, and 1 positive plus 4 hard negatives per query.

  • Comparing the Performance of LLMs: A Deep Dive into Roberta, Llama 2, and Mistral for Disaster Tweets Analysis with Lora

    Hugging Face mediumAdept

    RoBERTa-large (355M parameters), Mistral-7B and Llama-2-7B are fine-tuned with LoRA for binary classification of disaster tweets on a single 48GB A6000 GPU, using Hugging Face transformers, peft and datasets, with Weights & Biases for hyperparameter sweeps. The walkthrough covers the full pipeline: splitting and tokenizing the dataset, setting pad tokens to EOS for the decoder models, and computing class weights for a weighted-loss custom Trainer. It also covers LoRA configuration for each model. With rank 2 and alpha 16, LoRA trains only about 0.64% of RoBERTa's parameters.

The quest for software engineering knowledge.

Look:
Layout: