|
smollerGraph 0.20.2
A small graph database, from scratch
|
Accepted
Episode 15 trained a graph neural network on the mammals and birds, to tell which species are threatened from what's known about their relatives. Neo4j's Graph Data Science library offers GraphSAGE, and its pipelines train a model to classify nodes inside the database, from their embeddings and properties, and write each prediction back to its node, as a property. Episode 15 gives no reason for going another way beyond showing how it works: ours is "a vanilla version of that, a script that trains outside the database, and sg load to write the predictions back".
sg export writes a graph into a folder (ep015/step-1): nodes.jsonl, a line of JSON for each node with its id, name, label and properties, "so a reader can take the file a line at a time", and relationships.csv, the ids of the two nodes each relationship joins, and its type.tools/gnn.py trains a GraphSAGE of four layers in PyTorch, run with uv, as four hops reach a species' relatives through its genus and its family. With the label trick, statuses go in as features: each epoch, half of the training species show theirs, and the network learns to predict the other half from them, so no species sees its own answer. 70% of the species with a status are for training, 15% to pick the best epoch, and 15% to test on.gnn.py).sg load adds to the graph (0004).uv run --with torch --with numpy brings them in for the script.