跳到正文
DEV Community· Abhishek Nandy·· 2 小時前AI 評分51

作者打造 FieldTrip 向量微積分實驗室,讓 Gemma 規劃互動實驗

I Wanted to Be Lazy About Calculus. So I Built a Gemma Lab That Does the Experiments for Me

AI 導讀

Abhishek Nandy 打造 FieldTrip,一個以本機 Gemma 選擇向量微積分實驗、再由程式計算並呈現結果的互動實驗室。FieldTrip 提供五種起始場景、參數比較及可重播設定,並設有人工確認步驟,讓用戶檢視 Gemma 選出的實驗。作者以 24 條自建問題測試 Gemma 4 E2B,模型在 15 條支援請求中全部選對場景,但只正確拒絕 9 條範圍外請求中的 1 條。

正文

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 3: Slow and Steady

I asked Gemma to explain a vector field. It was confidently wrong. So I built FieldTrip.

Less setup. More aha. A local Gemma-powered vector calculus lab for the Slow and Steady challenge.

Gemma told me a smooth vector field was singular.

The animation looked convincing. The explanation was wrong.

I had asked it about a rotating field with components (-2y, 2x, 0). Its explanation mixed up the curl, the integrals, and an excluded axis that this field does not have.

That became the most useful failure in this project. I needed a clearer division of work: let the model interpret the question, let math tools calculate, and let me inspect both.

I also wanted to stop doing the repetitive parts of exploring calculus: writing plotting code, rebuilding a scene, changing one parameter, recording the result, and doing it again.

So I built FieldTrip, a small vector calculus lab where one question can become a reviewable experiment, an interactive 3D scene, and a table of comparisons you can replay.

The sloth gets to watch the arrows. The lab does the setup.

What I Built

FieldTrip turns supported natural-language questions into visual investigations of vector fields.

Ask:

Show a rotating field and compare loop sizes.

Local Gemma selects a field and a comparison. FieldTrip shows that selection before running it. After I accept, code supplies the formula, calculates derivatives and integrals, and builds the scene.

The lab includes five starting points:

Field Question to explore
Vortex Can something rotate without expanding?
Source Can something expand without rotating?
Saddle Can a shape stretch while preserving local volume?
Gradient What does following an uphill direction look like?
Excluded-axis vortex Why can zero curl coexist with nonzero circulation?

There are particles to follow, arrows to inspect, a boundary curve, a spanning surface, and controls for radius, strength, surface lift, and orientation. The math panel exposes symbolic divergence and curl. A point probe lets you inspect a location.

Explore for me runs parameter comparisons. Each table row has a replay button that restores its configuration. Investigations can be exported as JSON and imported again; calculations are recomputed rather than accepted from the imported numbers.

FieldTrip running on Render, with the saddle field and its explanation.

The public lab runs curated experiments immediately. Local Gemma inference uses the downloaded app and Ollama.

Demo

The public deployment and the local AI version have different responsibilities. Render hosts the interactive front end. Gemma runs on my laptop through Ollama. Opening the public URL does not provision a model for the visitor.

How I Built It

Give Gemma a small, useful job

The first version gave the model too much freedom. It could produce expressions and explanations that sounded plausible while disagreeing with the calculations.

The current planner returns a small structured object:

{
  "field": "vortex",
  "comparison": "radius"
}

The allowed field IDs correspond to the five examples, plus an outside-scope response. The comparison is radius, surface, orientation, or none. Unknown IDs and extra properties are rejected.

Gemma does not generate the preset formulas. It chooses which supported experiment fits the request.

Before anything changes, a review dialog shows the selected field, comparison, formula, and defaults. I can run it or keep the current experiment.

![Reviewing Gemma's selected vortex and radius comparison before execution.

Schema validation checks the shape of the answer. The review step checks whether that answer matches what I meant.

Explicit expressions such as F=(x,y,z) take a separate path through a restricted parser. That route does not need an AI call. The interface distinguishes it from a Gemma-selected experiment.

Make the calculations inspectable

The browser uses math.js for symbolic differentiation and numerical evaluation, Three.js for the scene, and GSAP for interface animation. Particle paths use a fourth-order Runge–Kutta step.

The expression evaluator permits a limited mathematical syntax and known symbols. It does not execute arbitrary generated JavaScript.

For Stokes comparisons, the application independently samples the boundary line integral and the curl flux through a parameterized surface. The boundary is a circle in z=0; the surface lift bends its interior while keeping that boundary fixed.

At the default resolution, the line integral uses 128 angular samples and the surface integral uses 32 radial by 128 angular samples.

The scene is an aid to inspection. Particle density is not presented as a measurement of divergence. Numerical agreement is not presented as a proof.

Automate the repetition

For the vortex F=(-y,x,0), the curl is (0,0,2). Around a counterclockwise circle of radius R, circulation is 2πR².

FieldTrip produces this comparison:

Radius Boundary circulation Sampled curl flux
0.5 1.5708 1.5708
1.0 6.2832 6.2832
1.5 14.1372 14.1372
2.0 25.1327 25.1327

Doubling the radius quadruples the result. Reversing the boundary orientation and surface normal changes both signs. Lifting the interior of the spanning surface preserves the boundary and, for this smooth example, preserves the matching flux.

Automatically calculated radius comparisons with replay controls.

One request becomes four computed configurations. Clicking a row brings that configuration back into the scene.

That is the laziness I wanted: less parameter bookkeeping, more time noticing what changes.

The Example That Makes Me Stop Scrolling

The excluded-axis field is

F = (-y/(x²+y²), x/(x²+y²), 0).

Away from the z-axis, its curl is zero. Yet a positively oriented circle around that axis has circulation 2π.

The excluded-axis field, with its missing axis and domain warning visible.

This does not contradict Stokes' theorem. The spanning disk crosses the axis where the field is undefined, so the theorem's smoothness requirements are not satisfied.

The numerical sampler can miss that axis and return a curl-flux value of zero. A finite set of successful evaluations cannot establish that the entire surface is admissible.

FieldTrip therefore marks the known example ASSUMPTIONS FAIL. The exported invalid flag reports sampled evaluation failures; it is not a certificate that the domain is valid.

Nonzero circulation, sampled zero curl flux, and the assumptions-fail warning.

This is a classic counterexample to an unchecked inference, not a new mathematical discovery.

That distinction became a design rule: show the values and the conditions under which they mean something.

I Tested the Planner, Including the Uncomfortable Results

I created a frozen set of 24 questions: 15 supported requests and 9 outside the lab's scope. I ran the same bounded-planner prompt and dataset against two local models.

A fully correct plan requires both the expected field ID and comparison ID.

Measure Gemma 3 1B Gemma 4 E2B
Correct field, all 24 questions 9/24 16/24
Correct field and comparison, all 24 5/24 14/24
Correct field on supported requests 9/15 15/15
Correct field and comparison on supported requests 5/15 13/15
Correct rejection of unsupported requests 0/9 1/9

Gemma 4 selected every supported field correctly in this small test. It was poor at rejecting unsupported requests.

It also made two comparison mistakes: adding a radius comparison where none was requested, and missing an orientation comparison.

Those failures explain two features in the app: the review step and a conservative code-based scope gate. Known requests such as “solve the heat equation” are stopped before inference. Ambiguous requests such as “change the surface” ask for a field or behavior instead of silently replacing the current experiment.

The scope gate was added after these measurements. Its behavior is not an improvement in the model's rejection score. Its phrase rules are incomplete and can overblock wording; they are a boundary for this small lab, not a general intent detector.

Earlier formula-translation tests also informed the redesign. On a separate 30-question development set, the small model-only approach passed 2/30. A hybrid route passed 27/30, but all 27 successes came from the direct parser. Calling that “90% AI accuracy” would misrepresent what happened.

These are author-created development tests, not an independent benchmark or an end-to-end accuracy claim. The repository includes questions, runners, raw responses, timings, and results. The bounded runs record matching dataset and prompt hashes so the comparison can be inspected.

Why Open Innovation Matters

I built and tested the local version on a Windows laptop with an Intel i7-8565U, 16 GB RAM, and integrated graphics.

With the model and app dependencies downloaded, the local workflow can run without an internet connection. I tested an offline investigation and exported its results. Prompts sent through the local Ollama configuration stay on the laptop; a cloud model key is not required.

Local inference still consumes hardware resources and electricity. The benefit is no per-request cloud inference fee, rather than a claim that computation is free.

Gemma's open weights let me compare models on my own task and keep the inference under my control. The source lets someone change the planner, inspect the formulas, replace a model adapter, or challenge a calculation without waiting for a service provider to expose those decisions.

The original application code is MIT-licensed. Gemma's weights and the third-party libraries retain their own licenses and terms.

Open innovation mattered most when the first approach failed: I could inspect the raw outputs, narrow the model's responsibility, and keep the useful parts of the workflow.

The Lazy Payoff—and the Limits

FieldTrip saves the repetitive setup of a supported investigation: selecting an example, creating its scene, calculating operators, running comparisons, and collecting configurations for replay.

I have not measured learning gains or a manual-versus-automated time saving, so I am not claiming either.

It does not solve arbitrary vector calculus problems, PDEs, quantum equations, or arbitrary surface geometries. It does not prove theorems. Custom non-polynomial domains still need review. Local model requests can take several seconds, and a valid plan can still be the wrong interpretation.

The useful outcome is smaller and concrete: ask for an experiment, review the setup, and spend your attention exploring it.

Run It Yourself

For the public curated lab, open FieldTrip on Render.

For local AI, install Ollama and Python, download the repository, then pull the model:

ollama pull gemma4:e2b

Run start-windows.cmd, open http://localhost:8765, and select gemma4:e2b in the Gemma settings. Use the local /api/generate proxy described in the README. A successful settings save alone does not demonstrate inference; submit a supported question and inspect the plan review.

Try this first:

Show a rotating field and compare loop sizes.

Then try the loophole. The missing axis is the part worth slowing down for.

Prize Categories

  • Best Use of Gemma: local, structured experiment planning with measured model comparisons and a review step.
  • Best Use of Render: hosting the public interactive lab so visitors can explore curated experiments without installing the local AI stack.

Built for Slow and Steady: let the lab handle the repetition, and keep the curiosity for yourself.

來源:DEV Community · dev.to