AmnaHassan commited on
Commit
7796c8a
·
verified ·
1 Parent(s): d240aa6

Create agents.py

Browse files
Files changed (1) hide show
  1. agents.py +32 -0
agents.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # agents.py
2
+ from typing import List
3
+
4
+
5
+ class ExperimentAgent:
6
+ def __init__(self, model, db):
7
+ self.model = model
8
+ self.db = db
9
+
10
+
11
+ def run(self, prompt, experiment_type="story_continuation"):
12
+ generated = self.model.generate_text(prompt)
13
+ layer_scores = self.model.layer_importance(prompt, experiment_type=experiment_type)
14
+ exp_id = self.db.save_experiment(prompt, generated, layer_scores)
15
+ return exp_id, generated, layer_scores
16
+
17
+
18
+ class ExplanationAgent:
19
+ def __init__(self):
20
+ pass
21
+
22
+
23
+ def explain_layer_importance(self, layer_scores: List[float]) -> str:
24
+ # Very simple heuristic explanation: report top-k layers and give short natural-lang summary
25
+ import numpy as np
26
+ arr = np.array(layer_scores)
27
+ if arr.size == 0:
28
+ return "No layer scores available."
29
+ top_idx = arr.argsort()[-3:][::-1]
30
+ top_layers = ", ".join([str(int(i)) for i in top_idx])
31
+ summary = f"Top influencing layers (proxy): {top_layers}. Layers with higher scores changed the model's next-token logits the most when ablated. This suggests they strongly affect immediate generation behavior for the provided prompt."
32
+ return summary