pulsatrix 1.1.0
Loading...
Searching...
No Matches
attribution_graph.hpp File Reference

Attribution graphs in the JSON that Neuronpedia's graph viewer and circuit-tracer's local viewer read (VIZ-4): nodes on a layer by token-position grid, and weighted links between them. More...

#include <cstdint>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include "pulsatrix/viz/document.hpp"
Include dependency graph for attribution_graph.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pulsatrix::AttributionGraph
 An attribution graph as Neuronpedia's schema (graph-schema.json) and circuit-tracer's create_graph_files describe it. More...
 
struct  pulsatrix::AttributionGraph::Node
 
struct  pulsatrix::AttributionGraph::Link
 

Namespaces

namespace  pulsatrix
 

Functions

std::string pulsatrix::ToNeuronpediaJson (const AttributionGraph &graph)
 The graph as Neuronpedia/circuit-tracer JSON, including circuit-tracer's optional node fields (token_prob, is_target_logit) and an empty qParams.
 
AttributionGraph pulsatrix::ParseNeuronpediaGraph (std::string_view json)
 Reads a graph written by ToNeuronpediaJson, circuit-tracer or Neuronpedia. Unknown fields are ignored.
 
void pulsatrix::ComputeInfluence (AttributionGraph &graph, const std::vector< double > &scores)
 Sets each node's influence the way circuit-tracer's pruning does: nodes other than embeddings and logits, by |score| largest first, get the cumulative fraction of the total |score| up to and including them. The viewer keeps nodes whose influence is at most its threshold, so a threshold of 0.8 keeps the fewest nodes holding 80% of the score.
 
void pulsatrix::PruneLinks (AttributionGraph &graph, double edge_threshold)
 Keeps the fewest links, largest |weight| first, whose |weight| sums to at least edge_threshold of the total; ties keep their order. Links into a logit node are always kept.
 
AttributionGraph pulsatrix::FromCircuitGraph (const CircuitGraphDocument &doc, const std::string &slug, const std::string &scan)
 A circuit graph (a chain of operations scored by ablation) for the viewer: two columns, "input" holding an embedding node and "network" holding each operation one layer up, with the last operation as the output. Influence comes from the ablation effects.
 

Detailed Description

Attribution graphs in the JSON that Neuronpedia's graph viewer and circuit-tracer's local viewer read (VIZ-4): nodes on a layer by token-position grid, and weighted links between them.