r/learnmachinelearning • • 1d ago

Visual intuition for SGD vs. Momentum vs. Adam: 30 noisy runs escaping the same saddle point

4 Upvotes

When you first learn optimizers, the equations for SGD, Momentum, and Adam look abstract on paper. I built this side-by-side visualization to actually *watch* how they behave on the same saddle point when every run gets identical mini-batch noise.

**Setup**

- **Surface:** `L(x, y) = (x² − 1)² + 3y²` - a saddle point at `(0, 0)` (`L = 1.0`) flanked by two symmetric minima at `(−1, 0)` and `(+1, 0)` (`L = 0`).

- **Start:** all 30 runs begin at `(0, 1)` (`L = 4.0`), right on the unstable ridge, so symmetry breaking comes purely from gradient noise.

- **Identical conditions:** shared learning rate `η = 0.02`, identical per-step Gaussian gradient noise `σ = 0.10` across all three optimizers, 90 steps.

- **Standard update rules:** Momentum uses `γ = 0.90`; Adam uses `β₁ = 0.9, β₂ = 0.999, ε = 1e-8`.

**What jumps out when you run 30 seeds at once**

  1. **SGD stalls on the saddle plateau.** The steep `y`-slope pulls every run straight down to `(0, 0)`, where `∂L/∂x ≈ 0`. You can see the amber median line flatline at `L = 1.0` for ~50 steps while it waits for random noise to push it off the ridge. By step 90, only **22/30** reach `L < 0.05` (median **82** steps).
  2. **Momentum is fastest - and wildest.** Carrying vertical velocity (`γ = 0.90`) launches it straight through the saddle up the far wall (`y ≈ −0.65`) and whips it into both valleys first (**30/30** solved, median **31** steps), trading speed for heavy oscillation around the minimum.
  3. **Adam moves in eerie lockstep.** Dividing each axis by its running RMS gradient turns both the steep `y`-wall and the flat `x`-ridge into roughly equal `±η` steps. That's why all 30 emerald runs slice diagonally into both valleys almost together (**30/30** solved, median **60** steps) with a razor-thin interquartile band.

*(Side note: I built this visualizer in Dart/Flutter as an interactive mini-lab I'm adding to Epoch Idle, an ML-themed simulation game for iOS and Android - https://epoch.loyallogic.org. Happy to answer questions about the math or implementation!)*


r/learnmachinelearning • • 1d ago

How am i supposed to learn machine learning

5 Upvotes

I was learning machine learning from andrew ng's course on coursera, but i could access only one week worth of material and i am currently relying on his youtube playlist of the same course. The problem is, i don't know what actually am i supposed to know. He taught about the theory and had optional labs where he has implemented them in python code. Am i supposed to be able to hard code all of it on my own? which level of knowledge should i have?


r/learnmachinelearning • • 23h ago

Help How can I extend a food recognition system toward personalized nutrition recommendations?

1 Upvotes

Hello everyone!

I'm working on a project that uses YOLO to recognize food from images and retrieve its nutritional information (calories, protein, fat, and carbohydrates) from a structured dataset.

Now, I would like to take the project further by introducing a user medical profile containing information such as diabetes, obesity, cardiovascular conditions, dietary restrictions, and personal preferences.

My goal is to evaluate food suitability for each user and provide personalized nutritional recommendations.

I'm looking for advice on a few points:

  1. How should I design and represent the user's medical profile?
  2. How can I translate medical conditions into nutritional constraints or rules?
  3. Should I use rule-based systems, knowledge-based approaches, or machine learning?
  4. How can I integrate these constraints into a personalized recommendation system?

Are there any relevant research papers, frameworks, or existing projects I should explore?

I'd really appreciate your suggestions and experiences. Thank you!


r/learnmachinelearning • • 23h ago

[R] Marulho: Learning Hierarchical Representations and Continual Classifiers Without Backpropagation (Zenodo Preprint + Apache-2.0 Code)

Thumbnail
reddit.com
1 Upvotes

r/learnmachinelearning • • 1d ago

ask for machine learning books for lecture

5 Upvotes

Hi. I'm a student of year 3. And we have a lecture about machine learning which is more focus on mathematical modelling . I 'm looking for some useful book to learn by myself. It would be better if it focuses on the mathematical sides. Here are the syllabus:

Week 4 Linear Models 1 - regression

Week 5 Linear Models 2 – ANOVA1

Week 6 Linear Models 3 – ANOVA2

Week 7 Likelihood And EM 1

Week 8 Likelihood And EM 2

Week 9 Tree Based Methods

Week 10 Boost Methods

Week 11 Cluster Analysis: 1

Week 12 Cluster Analysis: 2

Week 13 Logistic Regression

Week 14 Classification, ROC and AUC

Week 15 Neural Networks: 1 Basic

Week 16 Neural Networks: 2 Advanced


r/learnmachinelearning • • 1d ago

Request Critical TeamCity flaw lets unauthenticated attackers pose as build agents, grab secrets (CVE-2026-136858)

1 Upvotes

CVE-2026-136858 in TeamCity allows unauthenticated attackers to register as build agents and pull secrets from the build server — no credentials required. Once registered, the rogue agent looks identical to a legitimate one at the pipeline level. It can exfiltrate environment variables, signing keys, and deployment credentials before any human is alerted. The underlying problem is not unique to TeamCity: most CI/CD systems authenticate the pipeline runner at registration time and then implicitly trust every subsequent action that runner takes. A compromised or spoofed agent inherits that trust wholesale. The blast radius is whatever secrets the legitimate agent was allowed to touch — which in a typical prod pipeline is everything. How are you validating the runtime identity of your build agents on an ongoing basis, not just at registration?


r/learnmachinelearning • • 1d ago

I built a side pane that rewrites jargon in Claude Code's answers when you click it

Post image
2 Upvotes
**Body:**
I'm the author. My problem: I'd read an answer from Claude Code twice because of terms I didn't know, or get a pile of generated code and not know which part did what.


HoT reads the session file of Claude Code or Codex (read-only) and shows it in a second pane:
- click a highlighted term and that sentence is rewritten in plain words, in place
- ask which code does X and it shows those lines, colored by purpose
- tags paragraphs, and lists the real tool calls behind a claim


Honest limits: you need Pi (another terminal coding agent) to run it; each action costs a model call; a rewrite can be wrong (a second call checks it, which is not proof); I've only tested on macOS.


Repo: https://github.com/tinxai/hot_terminal


What would make this useful for you, or what makes you not want to install it?

r/learnmachinelearning • • 1d ago

RAG AND LLM LERANING JOURNEY

Thumbnail reddit.com
0 Upvotes

r/learnmachinelearning • • 1d ago

Realised I was learning about AI Engineering completely the wrong way! But seems like I got a good head start now. Looking for more suggestions to make learning better.

Thumbnail reddit.com
1 Upvotes

r/learnmachinelearning • • 1d ago

Discussion Try solving Advent of Code Day 3... but with PyTorch >:)

1 Upvotes

Was doing my first Advent of Code this year, and day 3 is solvable in pytorch its really fun!!! good practice run for whoever might have covered a certain portion of d2l.ai :>

try it: https://adventofcode.com/2026/

ill share my solution in comments


r/learnmachinelearning • • 2d ago

Project I rebuilt PyTorch's core to understand how it works, and wrote a series that explains each piece

Thumbnail
gallery
99 Upvotes

Hey all!

I use PyTorch almost every day, and for a long time the engine underneath was a black box to me: what actually happens when you add two tensors, and how is it so fast on so many CPUs and GPUs? Three and a half years ago, in my free time, I started trying to answer that.

How I made it. I started small, writing my own versions of the parts I thought I understood (an autograd engine in Python, then one in C++ on top of libtorch), and each one showed me how much I was still missing. In the end the only way forward was reading PyTorch's own source. It's huge, and part of the path from Python to the kernels is generated at build time, so it isn't even in the repo: it took me a long time just to find my way around. What made it click was rebuilding each piece myself, in C++ with Python bindings: the tensor and its strides, the loop behind almost every operation (TensorIterator), SIMD kernels, reductions and threads, autograd and, in the end, CUDA. Every operation is tested against PyTorch and timed next to it, so I knew when I had understood something and when I had not.

Piece by piece, that rebuild became Raxis, a library you can use much like PyTorch: it's about as fast, it's on PyPI (pip install raxis), and it trains real models like CNNs, Vision Transformers and nanoGPT. At some point it stopped being just for me, and I wanted it to be the code I would have liked to find when I started: it keeps the techniques that make PyTorch fast and little else, with no generated code and far fewer layers, so you can follow a call from Python to the kernel in your editor. It doesn't try to replace PyTorch: there's no distributed training, no torch.compile, no float16/bfloat16, and only NVIDIA GPUs. Much of what makes PyTorch's source hard to read exists because of exactly those features.

Code: https://github.com/pgmesa/raxis

I also wrote "Rebuilding PyTorch", a series that explains what I learned, in the order I learned it, for anyone as curious as I was who opened PyTorch's codebase and didn't know where to start:

  • What a tensor really is, and why slicing it costs nothing
  • How PyTorch walks a tensor of any shape
  • TensorIterator, the loop behind almost every operation
  • SIMD kernels for every CPU
  • Reductions and threads
  • The autograd engine
  • The same operations on a GPU

Each article starts from a question and walks through PyTorch's code step by step, with Raxis and measurements side by side: https://blog.pgmesa.com/series/rebuilding-pytorch/

It's dense material, more to study than to read in one sitting: it took me years to understand all of it and to let it sink in, and I hope it takes you much less. To start you only need to have written some PyTorch (some C/C++ helps), and the rest is curiosity and going one piece at a time. Feedback and questions are more than welcome, and I hope it helps you learn as much as it helped me!


r/learnmachinelearning • • 1d ago

Project Neural Network built from scratch with NumPy

Post image
2 Upvotes

This 👉interactive 𝐦𝐞𝐦𝐨𝐫𝐲_𝐠𝐫𝐚𝐩𝐡 demo visualizes 1,000 training steps of a neural network learning to solve the XOR problem. Watch how the weights evolve as the network learns.

Use the "Step Into" button to explore the implementation in neural_net.py and see the details of the forward and back-propagation. Follow the mathematics behind the implementation in 📑this PDF.

No PyTorch or TensorFlow — just Python, NumPy and mathematics.

Explore 👉other 𝐦𝐞𝐦𝐨𝐫𝐲_𝐠𝐫𝐚𝐩𝐡 visualizations.


r/learnmachinelearning • • 1d ago

Help me collect handwritten digits for a Deep Learning project!

0 Upvotes

Hey everyone!

I'm currently working on a Deep Learning project, and I need your help with something simple: collecting handwritten digits!

I built a small web app where anyone can write digits (0–9) using their mouse, trackpad, or touchscreen and submit them to contribute to my dataset.

The goal is to collect handwritten samples from different people, with different handwriting styles, so I can train and experiment with a digit recognition model.

How to participate:

  1. Open the website: https://malak-meliani.github.io/digits-by-hand/
  2. Write a few digits (0–9).
  3. Submit your samples!

It only takes a minute or two, and every contribution helps, even if you only submit a handful of digits.

I'd really appreciate it if you could give it a try! And if you have any feedback or suggestions about the website, I'd be happy to hear them.

Thank you so much to everyone who takes the time to contribute! ❤️


r/learnmachinelearning • • 1d ago

Discussion Chunk Size in RAG: Too Big vs Too Small

1 Upvotes

A support assistant gets asked: “Can I still get a refund?” It answers, “Yes — within fourteen days.” Confident, polite, and incomplete: refunds only apply if no projects have been exported.

The model is not the only suspect. In RAG, documents are split into chunks before retrieval, and the split decides what the retriever can even find:

• Chunks too big — the refund rule sits in one chunk with billing, cancellations and FAQs. Similar is not the same as correct; retrieval drags in noise.

• Chunks too small — the deadline lands in one chunk, the export condition lands in another. All the pieces are there; the meaning is not.

What helps in practice: keep related information together (rule + condition + short explanation), use overlap at boundaries as a tool rather than a fix, and test like an engineer — collect real questions, run retrieval with different strategies, inspect what comes back, check whether answers are supported, refine.

Two clarifications that come up often: chunking is not the model's tokenizer (it is a separate splitting decision made during preparation), and there is no universal chunk size — it depends on your documents, your questions and your embedding model.


r/learnmachinelearning • • 1d ago

Project I made a browser tool that shows a classifier before and after training: each picture is a dot that moves to its class corner

2 Upvotes

I'm the developer. This is a free page for learning what a classifier does, aimed at students and at teachers who want one lesson on it. No account, nothing uploaded, the training runs in the tab.

What it actually trains: a frozen image encoder (CLIP ViT-B/32, int8, running with onnxruntime-web) turns each picture into 512 numbers, and the only thing trained is a small softmax classifier on top (optionally one hidden layer of 64). So this is transfer learning with a linear probe, not a network trained from pixels. The page says that too.

The part I'd like feedback on is "Look inside the network": it draws the real classifier before training (small random weights from a fixed seed, so the four shape classes read 23%, 27%, 27%, 22%) and after. A slider replays training from weight snapshots. On the answer map every example is a dot placed by its class probabilities: the middle is "not sure", a corner is "sure". Test pictures show up as diamonds, including some picked to be ambiguous: a square with round corners comes out Square 49%, Circle 44% and lands between the two corners.

Five demos open without any model download (the features are bundled), and three are built to fail first:

- "Something it never saw": it knows sun, tree, house. A fish gets "Tree", 94%. One click adds a "Something else" class; after retraining, 8 of 8 new pictures are right.

- "Background trap": every circle on red, every square on blue. 4 of 4 on its own held-out test, 3 of 6 when the backgrounds are swapped. Mixed backgrounds fix it (6 of 6).

- "Too few examples": four of each digit in one handwriting. 5 of 5 on its own held-out test, 5 of 10 on new handwriting; more varied examples bring it to 10 of 10.

The point the demos are built to land: a model is only as good as its examples, enough of them and a good mix, including examples of what it should say no to.

Limits: the demo datasets are tiny (20 to 80 examples) and the held-out tests are 4 to 15 pictures, so the scores are rough, and the page says so. Most answers read "99%+" because the classes are easy and the head trains until it saturates; it never rounds up to 100%. Your own project (webcam or photos) downloads the encoder once: 89 MB, or 26 MB for a ResNet-50 option. English only.

https://image-trainer.skillsafe.ai/?utm_source=reddit-learnml

Question: for someone meeting softmax for the first time, is the "dot between corners" picture a fair way to show probability, or does it hide something I should show instead?


r/learnmachinelearning • • 1d ago

Hey! Learner Learning AI/ML , drop your answer

Thumbnail reddit.com
2 Upvotes

r/learnmachinelearning • • 1d ago

Qui sont vos meilleurs agents IA ?

Thumbnail reddit.com
0 Upvotes

Who are your best AI agents ?


r/learnmachinelearning • • 1d ago

Lost in Theory - Need Help Grounding to Reality

Thumbnail reddit.com
1 Upvotes

r/learnmachinelearning • • 1d ago

Discussion Same dataset, same LightGBM, one line changed: RMSE jumped 4.53x (0.723 C to 3.274 C) and R^2 dropped from 0.993 to 0.688

2 Upvotes

When a time-series model crushes offline cross-validation and falls apart in production, the bug is rarely the model architecture. Most of the time, the evaluation code quietly turned forecasting (extrapolating into the future) into interpolation (filling in a blank between yesterday and tomorrow).

To quantify how big that illusion gets on real data, I ran a controlled test on a single public file: 2024 hourly temperatures from the NOAA NCEI Central Park weather station (72505394728).

Fixed setup across all runs:

  • Raw CSV: 11,590 UTC rows. Cleaned 13 duplicate timestamps and 419 9999 placeholders, aligned to all 8,784 hourly slots of 2024 (41 missing hours / 0.47%, longest consecutive gap 24h).
  • No backfilling or interpolation. Purely causal features only: 1/3/6/12/24/48/168h lagged temperatures, causal 6/24/168h rolling mean and std, and calendar sin/cos. That leaves 7,082 clean samples.
  • Target: mean temperature over the next 24 hours ([t+1, t+24]).
  • Model: identical LightGBM (seed = 42).

Only the split protocol changed:

Evaluation ProtocolTrain / Test RowsTest RMSETest R2What It Actually Measures
Random 80/20 split (shuffle=True)5,665 / 1,4170.723 C0.993Interpolation between neighboring hours
Chronological last 20% + 24h Purge5,641 / 1,4173.274 C (4.53x)0.688Honest forward forecasting
168h seasonal naive baseline (same hour last week)1,417 test6.182 C-0.113Zero-training baseline

A few details worth keeping in mind when auditing forecasting code:

  1. The model itself is still genuinely useful (3.274 C beats the 6.182 C seasonal naive baseline by almost half). What hurts teams in production is the fake +0.305 R2 bonus from random shuffling creating false confidence.
  2. A plain chronological cut still leaks at the seam. Because the target at timestamp t averages [t+1, t+24], the last 24 rows of the training slice have target windows that physically overlap the test period. Train rows dropped from 5,665 to 5,641 after purging those 24 overlapping rows.
  3. Purge vs. Embargo are distinct mechanisms (Lopez de Prado 2018):

    • Purge drops training rows whose label horizon [t+1, t+H] overlaps the test block. Needed even on a single forward holdout.
    • Embargo adds a buffer after the test fold in multi-fold time-series CV, when another training fold follows in time and serial autocorrelation can leak backwards.
  4. Three silent zero-exception leaks to grep for before shipping:

    • StandardScaler().fit_transform(df) or bfill() applied before splitting.
    • rolling(..., center=True) or forgetting .shift(1) on rolling statistics.
    • Training on offline reanalysis or post-hoc corrected tables that are not available at live forecast origin t_0.

One guardrail that has saved me repeatedly: add assert (feature_timestamp < forecast_origin).all() at the end of feature generation, and always report RMSE in physical units next to a naive baseline rather than R2 alone.

What is the sneakiest time-series leakage bug you have caught in real projects? Centered rolling stats and pre-split target encoding seem to slip through code review most often.


r/learnmachinelearning • • 2d ago

Question 🧠 ELI5 Wednesday

10 Upvotes

Welcome to ELI5 (Explain Like I'm 5) Wednesday! This weekly thread is dedicated to breaking down complex technical concepts into simple, understandable explanations.

You can participate in two ways:

  • Request an explanation: Ask about a technical concept you'd like to understand better
  • Provide an explanation: Share your knowledge by explaining a concept in accessible terms

When explaining concepts, try to use analogies, simple language, and avoid unnecessary jargon. The goal is clarity, not oversimplification.

When asking questions, feel free to specify your current level of understanding to get a more tailored explanation.

What would you like explained today? Post in the comments below!


r/learnmachinelearning • • 2d ago

What separates a great AI engineer from someone who simply builds with LLM APIs?

5 Upvotes

I’ve been studying AI engineering, and one question keeps coming to mind.

With the availability of powerful LLM APIs, agent frameworks and AI coding assistants, building AI-powered applications has become increasingly accessible.

However, I want to develop a deeper understanding of the engineering behind these systems rather than simply knowing how to integrate existing tools.

I’m currently focusing on Python, LLM fundamentals, embeddings, retrieval systems and backend engineering.

For experienced AI engineers:

  • What fundamentals have made the biggest difference in your career?
  • How deeply should an AI engineer understand model architecture and mathematics?
  • What skills distinguish an exceptional AI engineer from an average one?
  • What would you learn differently if you were starting today?

I’m interested in building long-term engineering competence, not just keeping up with the latest AI frameworks.

I’d love to hear your perspectives.


r/learnmachinelearning • • 1d ago

Discussion Starting LLMOps CampusX

1 Upvotes

I will be starting LLMOps for CampusX from 10th dec. Planning to complete this within a month. Anyone wants to join for competitive study / discussion are welcome.

If more people join we can form a group.

Please DM if anyone is interested.

To be precise I am planning for a job switch.


r/learnmachinelearning • • 1d ago

Need campusx dsmp lecture number 269

1 Upvotes

Data leakage


r/learnmachinelearning • • 1d ago

Discussion 87.4% or 95.3%? Both scores came from the same 350 MedQA questions

Post image
0 Upvotes

A creator ran a quantized LingSante-3.1-flash on one 128 GB DGX Spark and gave it 350 multiple-choice medical questions from MedQA. It got 306 right. The scorecard also says 95.3% correct. I wanted to know which questions had disappeared from that second number.

The run had a 16K-token limit for reasoning. On 29 questions the local model hit the cap, and the test counted those as wrong. So 306 out of all 350 is 87.4%. Keep only the 321 questions it finished and those same 306 correct answers give you 95.3%. The full model, tested through an API, got 324 out of 350 and hit the cap six times.

For a comparison of the two versions, I’d keep all 350 in the denominator. For deciding what to run next, I’d keep a separate list of the 29 cutoffs and retry them with more room. Some might finish and still choose the wrong answer. That’s the part these two percentages can’t tell you.