Compare commits

..

2 Commits

4 changed files with 24 additions and 3 deletions

1
.gitignore vendored
View File

@ -170,3 +170,4 @@ cython_debug/
/tokenizer_vocab.txt /tokenizer_vocab.txt
/logs/core_dreams.txt /logs/core_dreams.txt
/logs/best_dream.txt

View File

@ -12,6 +12,13 @@ def tail(filepath, num_lines=10):
return f.readlines()[-num_lines:] return f.readlines()[-num_lines:]
def get_best_dream():
if not os.path.exists("logs/best_dream.txt"):
return "No high-scoring dream yet."
with open("logs/best_dream.txt", encoding="utf-8") as f:
return f.read().strip()
@app.route("/") @app.route("/")
def home(): def home():
vocab_size = 0 vocab_size = 0
@ -22,6 +29,7 @@ def home():
dreams = [line.strip() for line in tail("logs/dreams.log", 10)] dreams = [line.strip() for line in tail("logs/dreams.log", 10)]
messages = [line.strip() for line in tail("logs/messages.log", 10)] messages = [line.strip() for line in tail("logs/messages.log", 10)]
errors = [line.strip() for line in tail("logs/error.log", 15)] errors = [line.strip() for line in tail("logs/error.log", 15)]
best_dream = get_best_dream()
return render_template_string(""" return render_template_string("""
<!DOCTYPE html> <!DOCTYPE html>
@ -39,6 +47,8 @@ def home():
<body> <body>
<h1>🌸 Ruby's Dashboard</h1> <h1>🌸 Ruby's Dashboard</h1>
<p><b>Vocabulary Size:</b> {{ vocab_size }}</p> <p><b>Vocabulary Size:</b> {{ vocab_size }}</p>
<h3>🏆 Highest Scoring Dream</h3>
<p><b>{{ best_dream }}</b></p>
<h3>🧠 Recent Daydreams</h3> <h3>🧠 Recent Daydreams</h3>
<ul> <ul>
@ -60,9 +70,10 @@ def home():
{{ err }} {{ err }}
{% endfor %} {% endfor %}
</pre> </pre>
</body> </body>
</html> </html>
""", dreams=dreams[::-1], messages=messages[::-1], errors=errors[::-1], vocab_size=vocab_size) """, best_dream=best_dream, dreams=dreams[::-1], messages=messages[::-1], errors=errors[::-1], vocab_size=vocab_size)
def start_dashboard(): def start_dashboard():

View File

@ -1,5 +1,6 @@
from datetime import datetime from datetime import datetime
class RubyState: class RubyState:
def __init__(self): def __init__(self):
self.last_message_time = datetime.utcnow() self.last_message_time = datetime.utcnow()

View File

@ -19,6 +19,7 @@ class RubyTrainer:
self.criterion = torch.nn.CrossEntropyLoss() self.criterion = torch.nn.CrossEntropyLoss()
self.rebuild_model_if_needed() self.rebuild_model_if_needed()
self.best_dream = ("", 0.0)
def rebuild_model_if_needed(self): def rebuild_model_if_needed(self):
vocab_size = len(self.tokenizer.vocab) vocab_size = len(self.tokenizer.vocab)
@ -156,7 +157,8 @@ class RubyTrainer:
score_raw = self.score_sentence(raw) score_raw = self.score_sentence(raw)
score_re = self.score_sentence(rephrased) score_re = self.score_sentence(rephrased)
if score_re >= self.best_dream[1]:
self.best_dream = (rephrased.strip(), score_re)
final = rephrased if score_re >= score_raw else raw final = rephrased if score_re >= score_raw else raw
self.train_on_tokens_from_text(final) self.train_on_tokens_from_text(final)
@ -182,6 +184,8 @@ class RubyTrainer:
f.write(f"{datetime.utcnow().isoformat()} | Ruby | {t}\n") f.write(f"{datetime.utcnow().isoformat()} | Ruby | {t}\n")
print(f"[DAYDREAM] Complete. {len(thoughts)} thoughts imagined.") print(f"[DAYDREAM] Complete. {len(thoughts)} thoughts imagined.")
with open("logs/best_dream.txt", "w", encoding="utf-8") as f:
f.write(f"{self.best_dream[1]:.2f} | {self.best_dream[0]}\n")
if say_thought and thoughts: if say_thought and thoughts:
return thoughts[-1] return thoughts[-1]
@ -246,4 +250,8 @@ class RubyTrainer:
if len(set(words)) > len(words) * 0.75: if len(set(words)) > len(words) * 0.75:
score += 1 # diversity bonus score += 1 # diversity bonus
word_counts = {w: words.count(w) for w in set(words)}
if any(count >= 3 for count in word_counts.values()):
score -= 1 # repetition penalty
return score # max 5.0 return score # max 5.0