HemanM commited on
Commit
fe5756c
·
verified ·
1 Parent(s): 6842aeb

Update evo_transformer.py

Browse files
Files changed (1) hide show
  1. evo_transformer.py +21 -14
evo_transformer.py CHANGED
@@ -1,6 +1,6 @@
1
  # evo_transformer.py
 
2
  import random
3
- import pandas as pd
4
  import json
5
 
6
  class EvoTransformer:
@@ -25,31 +25,38 @@ class EvoTransformer:
25
  elif trait == "ffn_dim":
26
  new_config[trait] = random.choice([512, 1024, 2048])
27
  elif trait == "dropout":
28
- new_config[trait] = round(min(max(0.0, new_config[trait] + random.uniform(-0.05, 0.05)), 0.5), 2)
 
29
  elif trait == "memory":
30
  new_config[trait] = not new_config[trait]
31
 
32
  self.config = new_config
33
  self.history.append(new_config.copy())
34
 
35
- def evolve(self, generations=5):
36
  for _ in range(generations):
37
  self.mutate()
38
 
 
 
 
39
  def evaluate(self):
40
- # Simulated accuracy and parameter estimate
41
- accuracy = round(random.uniform(0.85, 0.95), 4)
42
- params = self.estimate_params()
43
- return accuracy, params
 
 
44
 
45
  def estimate_params(self):
46
- return round(10 + self.config["layers"] * self.config["ffn_dim"] * 0.001, 2)
 
 
47
 
48
- def get_history_df(self):
49
- return pd.DataFrame(self.history)
 
 
50
 
51
- def get_history_json(self):
52
  return json.dumps(self.history, indent=2)
53
-
54
- def get_final_config(self):
55
- return self.config
 
1
  # evo_transformer.py
2
+
3
  import random
 
4
  import json
5
 
6
  class EvoTransformer:
 
25
  elif trait == "ffn_dim":
26
  new_config[trait] = random.choice([512, 1024, 2048])
27
  elif trait == "dropout":
28
+ change = round(random.uniform(-0.05, 0.05), 2)
29
+ new_config[trait] = round(min(max(0.0, new_config[trait] + change), 0.5), 2)
30
  elif trait == "memory":
31
  new_config[trait] = not new_config[trait]
32
 
33
  self.config = new_config
34
  self.history.append(new_config.copy())
35
 
36
+ def evolve(self, generations=3):
37
  for _ in range(generations):
38
  self.mutate()
39
 
40
+ def get_history(self):
41
+ return self.history
42
+
43
  def evaluate(self):
44
+ # Simulated accuracy and parameter count
45
+ accuracy = round(0.8 + random.uniform(0.01, 0.15), 4)
46
+ return {
47
+ "accuracy": accuracy,
48
+ "params": self.estimate_params()
49
+ }
50
 
51
  def estimate_params(self):
52
+ # Lightweight param estimate formula (not real count)
53
+ multiplier = 1.0 + (0.5 if self.config["memory"] else 0.0)
54
+ return int(self.config["layers"] * self.config["ffn_dim"] * multiplier)
55
 
56
+ def export_csv(self):
57
+ import pandas as pd
58
+ df = pd.DataFrame(self.history)
59
+ return df.to_csv(index=False)
60
 
61
+ def export_json(self):
62
  return json.dumps(self.history, indent=2)