Updated DayDream to let her dream more
This commit is contained in:
parent
3020e230ff
commit
3829ca8d01
2
main.py
2
main.py
@ -65,6 +65,8 @@ class Ruby(discord.Client):
|
||||
for guild in self.guilds:
|
||||
for channel in guild.text_channels:
|
||||
if channel.permissions_for(guild.me).send_messages:
|
||||
if not thought.endswith("."):
|
||||
thought += "."
|
||||
await channel.send(f"(dreaming) {thought}")
|
||||
break
|
||||
break # only post to one server/channel
|
||||
|
25
model.py
25
model.py
@ -2,7 +2,7 @@ import torch
|
||||
import torch.nn as nn
|
||||
import torch.nn.functional as F
|
||||
import os
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class MiniGPT(nn.Module):
|
||||
@ -90,7 +90,7 @@ class RubyTrainer:
|
||||
|
||||
print(f"[TRAIN] Tokens: {tokens} | Loss: {loss.item():.4f}")
|
||||
|
||||
def generate_reply(self, max_tokens=30, temperature=1.0, top_k=5):
|
||||
def generate_reply(self, max_tokens=50, temperature=1.2, top_k=10):
|
||||
self.model.eval()
|
||||
|
||||
input_ids = torch.tensor([[self.tokenizer.vocab["<START>"]]], dtype=torch.long, device=self.device)
|
||||
@ -112,6 +112,9 @@ class RubyTrainer:
|
||||
next_token = next_token.view(1, 1)
|
||||
input_ids = torch.cat([input_ids, next_token], dim=1)
|
||||
|
||||
if input_ids.size(1) < 5: # prevent ending too early
|
||||
logits[0, self.tokenizer.vocab["<END>"]] = float("-inf")
|
||||
|
||||
if next_token.item() == self.tokenizer.vocab["<END>"]:
|
||||
break
|
||||
|
||||
@ -144,9 +147,14 @@ class RubyTrainer:
|
||||
def daydream(self, rounds=5, log_output="logs/dreams.log", say_thought=False):
|
||||
print("[DAYDREAM] Ruby is imagining new thoughts...")
|
||||
thoughts = []
|
||||
for _ in range(rounds):
|
||||
max_attempts = rounds * 3 # allows retries for short/empty outputs
|
||||
attempts = 0
|
||||
|
||||
while len(thoughts) < rounds and attempts < max_attempts:
|
||||
thought = self.generate_reply()
|
||||
if thought.strip():
|
||||
attempts += 1
|
||||
|
||||
if thought and len(thought.strip().split()) >= 4:
|
||||
self.train_on_tokens_from_text(thought)
|
||||
thoughts.append(thought)
|
||||
|
||||
@ -154,10 +162,15 @@ class RubyTrainer:
|
||||
for t in thoughts:
|
||||
f.write(f"[DAYDREAM] {t}\n")
|
||||
|
||||
print(f"[DAYDREAM] Complete. {len(thoughts)} thoughts imagined.")
|
||||
# Loop dreams back into message log (optional)
|
||||
with open("logs/messages.log", "a", encoding="utf-8") as f:
|
||||
for t in thoughts:
|
||||
f.write(f"{datetime.utcnow().isoformat()} | Ruby | {t}\n")
|
||||
|
||||
print(f"[DAYDREAM] Complete. {len(thoughts)} thoughts imagined (in {attempts} attempts).")
|
||||
|
||||
if say_thought and thoughts:
|
||||
return thoughts[-1] # last thought spoken aloud
|
||||
return thoughts[-1]
|
||||
return None
|
||||
|
||||
def reinforce_core_memory(self, log_output="logs/dreams.log"):
|
||||
|
Loading…
x
Reference in New Issue
Block a user