ApolloResearch / rib

Library for methods related to the Local Interaction Basis (LIB)
MIT License
2 stars 0 forks source link

Add option to add node_labels to graph #250

Closed stefan-apollo closed 10 months ago

stefan-apollo commented 10 months ago

Labelled graphs

Description

Allows node labels to be passed (as csv file) to be plotting script, example:

python plot_lm_graph.py /mnt/ssd-apollo/stefan/modular_arithmetic_interaction_graph.pt --nodes_per_layer 10 --labels_file test.csv  --out_file test.png

Also added other parameters as command line arguments.

Motivation

We can now generate labels (interp repo) with

python generate_labels_mod_add.py /mnt/ssd-apollo/stefan/modular_arithmetic_interaction_graph.pt --out_file=test.csv

and want to add them to our graphs.

Labels currently only available for mod add, but this setup works for any model.

Tested

Made labelled and unlabelled plots.

Breaking changes

No

The only think I am confused about is: plot_interaction_graph's docstring says that layer_names should include the output, but results["config"]["node_layers"] doesn't necessarily do that. I have modified the code as below, does this make sense?

REMOVED THIS NOW


    layer_names = results["config"]["node_layers"]

    # plot_interaction_graph() demands that layer_names includes "output"
    if layer_names[-1] != "output":
        layer_names.append("output")

    plot_interaction_graph(
        raw_edges=results["edges"],
        layer_names=layer_names,
        exp_name=results["exp_name"],
        nodes_per_layer=nodes_per_layer,
        out_file=out_file,
        node_labels=node_labels,
    )
stefan-apollo commented 10 months ago

I removed the "output" related legacy code