HemanM commited on
Commit
2b38854
·
verified ·
1 Parent(s): 2695546

Update evo_transformer.py

Browse files
Files changed (1) hide show
  1. evo_transformer.py +13 -15
evo_transformer.py CHANGED
@@ -1,5 +1,6 @@
1
  # evo_transformer.py
2
  import random
 
3
  import json
4
 
5
  class EvoTransformer:
@@ -16,7 +17,7 @@ class EvoTransformer:
16
  def mutate(self):
17
  new_config = self.config.copy()
18
  trait = random.choice(list(new_config.keys()))
19
-
20
  if trait == "layers":
21
  new_config[trait] = max(1, new_config[trait] + random.choice([-1, 1]))
22
  elif trait == "attention_heads":
@@ -31,27 +32,24 @@ class EvoTransformer:
31
  self.config = new_config
32
  self.history.append(new_config.copy())
33
 
34
- def evolve(self, generations=3):
35
  for _ in range(generations):
36
  self.mutate()
37
 
38
- def get_history(self):
39
- return self.history
40
-
41
  def evaluate(self):
42
- score = round(random.uniform(0.85, 0.95), 4)
43
- return {"accuracy": score, "params": self.estimate_params()}
 
 
44
 
45
  def estimate_params(self):
46
  return round(10 + self.config["layers"] * self.config["ffn_dim"] * 0.001, 2)
47
 
48
- def export_csv(self):
49
- headers = list(self.history[0].keys())
50
- lines = [",".join(headers)]
51
- for config in self.history:
52
- line = ",".join([str(config[h]) for h in headers])
53
- lines.append(line)
54
- return "\n".join(lines)
55
 
56
- def export_json(self):
57
  return json.dumps(self.history, indent=2)
 
 
 
 
1
  # evo_transformer.py
2
  import random
3
+ import pandas as pd
4
  import json
5
 
6
  class EvoTransformer:
 
17
  def mutate(self):
18
  new_config = self.config.copy()
19
  trait = random.choice(list(new_config.keys()))
20
+
21
  if trait == "layers":
22
  new_config[trait] = max(1, new_config[trait] + random.choice([-1, 1]))
23
  elif trait == "attention_heads":
 
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