← Back to list

Try It Yourself: A Demo App of the Technology That Sparked the Rise of AI!—

misc/nobel at main · GitGhidorah/misc

Outermostkt · 2026-05-26 15:50 · 0 claps · 3.5 min read
#hopfield-network #boltzmann-machines #nobel-prize #rbm #artificial-intelligence
Open on Medium ↗
Wiki topics: AI · AI · General

Try It Yourself: A Demo App of the Technology That Sparked the Rise of AI!— Hopfield Networks & Restricted Boltzmann Machines (RBMs)

misc/nobel at main · GitGhidorah/misc

hopfield_gemini.py

Recommended Experiments (Testing Associative Memory)

[Step 1] Memorize a Target Shape (Training)

  1. Launch the application and click the **Shape 'T'** button. A black dot pattern forming the letter "T" will appear on the grid.
  2. Click the **Memorize Current Pattern** button.
  • What happens under the hood: The network adjusts the connection strengths (weights) between all neurons using Hebbian Learning. This process carves out a deep “valley” in the network’s energy landscape, making the “T” shape the point of lowest energy.

[Step 2] Corrupt the Shape (Injecting Noise)

  1. Click the **Flip 3 Random Pixels** button once or twice (or manually click on some cells) to distort and mess up the clean "T" shape.

[Step 3] Minimize Energy to Restore the Memory (Retrieval)

  1. Try clicking the **Step Update (1 Neuron)** button repeatedly.
  2. A single cell will be randomly chosen (highlighted with a red border). This neuron looks at its neighbors, evaluates the consensus based on the current weights, and decides whether it should flip to black (+1) or white (-1).
  3. If you want to see the final result instantly, click **Run to Convergence**. The network will rapidly run asynchronous updates until it hits a local energy minimum. The corrupted grid will spontaneously snap back into the clean, original "T" shape!

Advanced Experiment: Storing Multiple Memories

One of the coolest features of a Hopfield Network is its capacity to store more than one pattern simultaneously.

  1. Click **Clear Network Weights** to start fresh.
  2. Load **Shape 'T' and click `Memorize Current Pattern`**.
  3. Next, load **Shape 'X' and click `Memorize Current Pattern`** again.
  • Note: The network has now overlaid both shapes into the exact same matrix of weights.

Now, if you distort the grid so it looks like a messy version of “T”, the network will pull the state toward the “T” memory. If you make it look more like a broken “X”, it will converge to the “X” memory. The system naturally recalls the memory that shares the closest features with the input!

rbm_gemini.py

Testing Pattern Reconstruction (Associative Memory) in 4 Steps

[Step 1] Train the RBM First

First, we need to let the RBM memorize the “alternating pattern.”

  1. Launch the app (or click the **Reset Weights & Biases** button to initialize the network).
  2. Ensure the checkboxes at the top-left are set to **V0 [■], V1 [ ], V2 [■], V3 [ ]** (representing the $[1, 0, 1, 0]$ state).
  3. Click the **Train 100 Steps button once**.
  • Note: Now, the RBM’s “brain” (the thickness of the weight lines) has been customized specifically for $[1, 0, 1, 0]$.

[Step 2] Intentionally Create a Messy State (Noise)

Next, to confuse the RBM, we will force an arbitrary pattern that is completely different from what it memorized.

  1. Click the **Randomize States** button a few times.
  2. Keep clicking until the yellow circles (active state [1]) and gray circles (inactive state [0]) on the right side form a completely random sequence other than [1, 0, 1, 0] (for example, all yellow, or [0, 1, 1, 1]).

[Step 3] Let the Hidden Layer Imagine

Now, we start the automatic reconstruction (sampling) process.

  1. Click the **Step Forward (Alternating) button once**.
  2. The Hidden layer (right side) looks at the messy state of the Visible layer and reacts: “Wait, some weird data just came in…” It then recalculates its own probabilities ($p$) and states [0]/[1].
  • Note: At this exact moment, the Visible layer on the left remains messy.

[Step 4] The Visible Layer Restores the Correct Shape!

  1. Click the **Step Forward (Alternating) button one more time**.
  2. This time, the Visible layer (left side) is reverse-sampled based on the newly updated Hidden layer states.
  3. Look at the screen! The nodes in the Visible layer ($V_0$ to $V_3$) have been rewritten. They have shifted from the chaotic state you forced upon them back into the trained pattern: **[1, 0, 1, 0] (On, Off, On, Off)**!

What if it doesn’t restore in one go?

Because the RBM uses probabilities to perform its calculations, it might not completely fix the pattern in just one round-trip (2 clicks) if the initial state was extremely chaotic.

If that happens, try clicking the Step Forward (Alternating) button repeatedly (click, click, click). As the information flows back and forth between left and right, it will eventually settle into the [1, 0, 1, 0] pattern, almost as if drawn by a magnet.

This behavior — spontaneously converging toward the lowest energy state (the most “comfortable” state) — is one of the most fascinating aspects of the Restricted Boltzmann Machine.


메타데이터
post_id
4ce60ca08784
slug
2024-nobel-prize-was-way-too-hard-4ce60ca08784
url
https://medium.com/@outermostkt/2024-nobel-prize-was-way-too-hard-4ce60ca08784
canonical_url
https://medium.com/@outermostkt/2024-nobel-prize-was-way-too-hard-4ce60ca08784
author_url
https://medium.com/@outermostkt
status
ok
fetched_at
2026-06-15 20:49:13