# technion-cs-nlp/peap architecture

> Architecture diagram of the GitHub repository technion-cs-nlp/peap, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/technion-cs-nlp/peap
- Repository: https://github.com/technion-cs-nlp/peap

## Overview

PEAP is a research toolkit for discovering position-aware circuits in transformer models. The principal workflow is to prepare task data, compute edge-attribution scores over token spans, select a circuit, then evaluate its faithfulness with ablation. Separate capabilities generate task datasets and infer/apply span schemas, with input attribution helping identify important tokens. The source index and README establish the main module relationships; several internal details are unsampled, so the graph omits uncertain links rather than inferring them.

Main entry points: [`src/eval.py`](https://github.com/technion-cs-nlp/peap/blob/main/src/eval.py) (Faithfulness evaluation), [`src/pos_aware_edge_attribution_patching.py`](https://github.com/technion-cs-nlp/peap/blob/main/src/pos_aware_edge_attribution_patching.py) (PEAP scoring), [`src/exp.py`](https://github.com/technion-cs-nlp/peap/blob/main/src/exp.py) (Task experiments), [`data`](https://github.com/technion-cs-nlp/peap/tree/main/data) (Task datasets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Task data"]
  node_taskdata[("Task datasets")]
  node_generator["Dataset generation<br/>[data_generation.py]"]
  node_experiment["Task experiments<br/>[exp.py]"]
end

subgraph group_schema["Span schemas"]
  node_schema_gen["Schema generation"]
  node_input_attr["Input attribution"]
end

subgraph group_attribution["Attribution"]
  node_peap["PEAP scoring"]
  node_scorefile["Attribution results"]
end

subgraph group_circuits["Circuit analysis"]
  node_discovery["Circuit discovery<br/>[eval_utils.py]"]
  node_evaluator["Faithfulness evaluation<br/>[eval.py]"]
  node_reports["Evaluation results"]
end

node_researcher(("Researcher"))
node_model["Transformer model"]

node_researcher -->|"generates data"| node_generator
node_generator -->|"writes datasets"| node_taskdata
node_researcher -->|"defines spans"| node_schema_gen
node_schema_gen -->|"uses attribution"| node_input_attr
node_researcher -->|"runs scoring"| node_peap
node_taskdata -.->|"supplies examples"| node_experiment
node_experiment -->|"provides datasets"| node_peap
node_peap -->|"scores activations"| node_model
node_peap -->|"saves scores"| node_scorefile
node_researcher -->|"runs evaluation"| node_evaluator
node_evaluator -->|"loads scores"| node_scorefile
node_evaluator -->|"gets eval data"| node_experiment
node_evaluator -->|"selects circuits"| node_discovery
node_discovery -->|"builds model graph"| node_model
node_evaluator -->|"tests ablations"| node_model
node_evaluator -->|"saves metrics"| node_reports

click node_taskdata "https://github.com/technion-cs-nlp/peap/tree/main/data"
click node_generator "https://github.com/technion-cs-nlp/peap/blob/main/src/data_generation.py"
click node_experiment "https://github.com/technion-cs-nlp/peap/blob/main/src/exp.py"
click node_schema_gen "https://github.com/technion-cs-nlp/peap/blob/main/src/schema_generation.py"
click node_input_attr "https://github.com/technion-cs-nlp/peap/blob/main/src/input_attribution.py"
click node_peap "https://github.com/technion-cs-nlp/peap/blob/main/src/pos_aware_edge_attribution_patching.py"
click node_discovery "https://github.com/technion-cs-nlp/peap/blob/main/src/eval_utils.py"
click node_evaluator "https://github.com/technion-cs-nlp/peap/blob/main/src/eval.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_taskdata,node_generator,node_experiment toneBlue
class node_schema_gen,node_input_attr toneAmber
class node_peap,node_scorefile toneMint
class node_discovery,node_evaluator,node_reports toneRose
class node_researcher,node_model toneIndigo
```

## Components

### Task data

- [Task datasets](https://github.com/technion-cs-nlp/peap/tree/main/data): `data`
- [Dataset generation](https://github.com/technion-cs-nlp/peap/blob/main/src/data_generation.py): `src/data_generation.py`
- [Task experiments](https://github.com/technion-cs-nlp/peap/blob/main/src/exp.py): `src/exp.py`

### Span schemas

- [Schema generation](https://github.com/technion-cs-nlp/peap/blob/main/src/schema_generation.py): `src/schema_generation.py`
- [Input attribution](https://github.com/technion-cs-nlp/peap/blob/main/src/input_attribution.py): `src/input_attribution.py`

### Attribution

- [PEAP scoring](https://github.com/technion-cs-nlp/peap/blob/main/src/pos_aware_edge_attribution_patching.py): `src/pos_aware_edge_attribution_patching.py`
- **Attribution results**

### Circuit analysis

- [Circuit discovery](https://github.com/technion-cs-nlp/peap/blob/main/src/eval_utils.py): `src/eval_utils.py`
- [Faithfulness evaluation](https://github.com/technion-cs-nlp/peap/blob/main/src/eval.py): `src/eval.py`
- **Evaluation results**

### Other components

- **Researcher**
- **Transformer model**

## Connections

- Researcher → Dataset generation: generates data (evidence: `README.md`)
- Dataset generation → Task datasets: writes datasets (evidence: `README.md`)
- Researcher → Schema generation: defines spans (evidence: `README.md`)
- Schema generation → Input attribution: uses attribution (evidence: `src/schema_generation.py`)
- Researcher → PEAP scoring: runs scoring (evidence: `README.md`)
- Task datasets → Task experiments: supplies examples
- Task experiments → PEAP scoring: provides datasets (evidence: `src/pos_aware_edge_attribution_patching.py`)
- PEAP scoring → Transformer model: scores activations (evidence: `src/pos_aware_edge_attribution_patching.py`)
- PEAP scoring → Attribution results: saves scores (evidence: `README.md`)
- Researcher → Faithfulness evaluation: runs evaluation (evidence: `README.md`)
- Faithfulness evaluation → Attribution results: loads scores (evidence: `src/eval.py`)
- Faithfulness evaluation → Task experiments: gets eval data (evidence: `src/eval.py`)
- Faithfulness evaluation → Circuit discovery: selects circuits (evidence: `src/eval.py`)
- Circuit discovery → Transformer model: builds model graph (evidence: `src/eval_utils.py`)
- Faithfulness evaluation → Transformer model: tests ablations (evidence: `src/eval.py`)
- Faithfulness evaluation → Evaluation results: saves metrics (evidence: `README.md`)
