Hands-on: Turning a Network into Coordinates
Two families of embedding, built from scratch, then judged on the same task.
NoteWhere the code lives
This course keeps its lecture note free of runnable code. Everything you execute lives in a marimo notebook, so it stays interactive and reactive instead of being a wall of output frozen into a web page.
Hosted notebook: coming soon. This one uses a compiled package that the browser runtime cannot load, so it needs molab or a local environment. The hosted link is not up yet.
In the meantime, the notebook is in the repository at notebooks/m08-network-embedding/coding.py. Run it with marimo edit notebooks/m08-network-embedding/coding.py.
What you will build
- Three spectral embeddings of Zachary’s karate club — from the adjacency matrix, the modularity matrix, and the Laplacian — each one a single
numpy.linalg.eigcall plus a sort. - The word2vec analogies on a pre-trained model: king - man + woman, and the parallel arrows joining countries to their capitals.
- A random-walk sampler, and then DeepWalk: hand the walks to
gensim’sWord2Vecas if they were sentences. - node2vec’s biased walk, with p and q written out step by step rather than called from a library.
- UMAP projections of both neural embeddings down to two dimensions, and k-means clusters checked against the club’s real two factions.
What to watch for
- Put the three spectral plots side by side. Same 34 people, three matrices, three different pictures. Decide which one you would hand to a clustering algorithm and be able to say why.
- Sweep q from below 1 to above 1 and watch which nodes end up near each other. Low q should recover communities, high q should group nodes by role.
- Train DeepWalk twice with different random seeds and plot both. The coordinates will be completely different while the clusters stay put — an embedding is only defined up to rotation, so a single coordinate never means anything on its own.