Fixed it to save the vocab and brainmap every time we train to prevent loss
This commit is contained in:
parent
26fbf85a90
commit
9ab043dc78
31
main.py
31
main.py
@ -4,7 +4,7 @@ import threading
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import os
|
import os
|
||||||
from model.trainer import train_on_message
|
from model.trainer import train_on_message
|
||||||
from model.brain import generate_response
|
from model.brain import generate_response, daydream
|
||||||
from model.cleanup import full_cleanup
|
from model.cleanup import full_cleanup
|
||||||
from model.dream_replay import replay_dreams
|
from model.dream_replay import replay_dreams
|
||||||
from model.rehearsal import simulate_conversation
|
from model.rehearsal import simulate_conversation
|
||||||
@ -22,6 +22,8 @@ intents.message_content = True
|
|||||||
|
|
||||||
client = discord.Client(intents=intents)
|
client = discord.Client(intents=intents)
|
||||||
|
|
||||||
|
empty_response_counter = 0
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
@ -30,12 +32,24 @@ async def on_ready():
|
|||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_message(message):
|
async def on_message(message):
|
||||||
if message.author.bot:
|
global empty_response_counter
|
||||||
|
|
||||||
|
if message.author == client.user:
|
||||||
return
|
return
|
||||||
|
|
||||||
content = message.content.strip()
|
if not message.content.strip():
|
||||||
train_on_message(content)
|
return
|
||||||
|
|
||||||
|
train_on_message(message.content, source="user")
|
||||||
response = generate_response()
|
response = generate_response()
|
||||||
|
|
||||||
|
if not response.strip():
|
||||||
|
empty_response_counter += 1
|
||||||
|
if empty_response_counter % 10 == 0: # only every 10 failures
|
||||||
|
print(f"[Brain] Skipped {empty_response_counter} empty replies so far.")
|
||||||
|
return
|
||||||
|
|
||||||
|
empty_response_counter = 0 # reset counter when Ruby replies
|
||||||
await message.channel.send(response)
|
await message.channel.send(response)
|
||||||
|
|
||||||
|
|
||||||
@ -49,15 +63,16 @@ async def background_cleanup_loop():
|
|||||||
async def dream_replay_loop():
|
async def dream_replay_loop():
|
||||||
while True:
|
while True:
|
||||||
replay_dreams()
|
replay_dreams()
|
||||||
set_next_action(900, "Dreaming new dreams")
|
set_next_action(90, "Dreaming new dreams")
|
||||||
await asyncio.sleep(900) # Replay every 15 minutes
|
await asyncio.sleep(90) # Replay every 15 minutes
|
||||||
|
daydream()
|
||||||
|
|
||||||
|
|
||||||
async def rehearsal_loop():
|
async def rehearsal_loop():
|
||||||
while True:
|
while True:
|
||||||
simulate_conversation()
|
simulate_conversation()
|
||||||
set_next_action(1200, "Practicing Conversations")
|
set_next_action(120, "Practicing Conversations")
|
||||||
await asyncio.sleep(1200) # Every 20 minutes
|
await asyncio.sleep(120) # Every 20 minutes
|
||||||
|
|
||||||
|
|
||||||
# Start Ruby's Brain Loops in a separate thread
|
# Start Ruby's Brain Loops in a separate thread
|
||||||
|
@ -2,7 +2,8 @@ import torch
|
|||||||
import time
|
import time
|
||||||
from model.dynamic_expand import expand_model_if_needed, _last_expansion_time, get_optimizer, expand_lock
|
from model.dynamic_expand import expand_model_if_needed, _last_expansion_time, get_optimizer, expand_lock
|
||||||
from model.brain_state import model, tokenizer, DEVICE, loss_fn
|
from model.brain_state import model, tokenizer, DEVICE, loss_fn
|
||||||
from model.brainmap import add_to_brainmap
|
from model.brainmap import add_to_brainmap, save_brainmap
|
||||||
|
from model.tokenizer import save_vocab
|
||||||
from context.context import add_to_context, get_recent_context
|
from context.context import add_to_context, get_recent_context
|
||||||
|
|
||||||
LOSS_FILE = "data/logs/loss.log"
|
LOSS_FILE = "data/logs/loss.log"
|
||||||
@ -70,6 +71,8 @@ def train_on_message(text: str, source: str = "user"):
|
|||||||
log_vocab_growth()
|
log_vocab_growth()
|
||||||
add_to_context(text, source=source)
|
add_to_context(text, source=source)
|
||||||
add_to_brainmap(augmented_text.split())
|
add_to_brainmap(augmented_text.split())
|
||||||
|
save_brainmap()
|
||||||
|
save_vocab(tokenizer.vocab)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
expand_lock.release()
|
expand_lock.release()
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
|
from model.tokenizer import save_vocab, Tokenizer
|
||||||
|
from model.brainmap import save_brainmap
|
||||||
from model.trainer import train_on_message
|
from model.trainer import train_on_message
|
||||||
from model.scheduler import set_next_action
|
from model.scheduler import set_next_action
|
||||||
from reader.filter import is_valid_line
|
from reader.filter import is_valid_line
|
||||||
@ -10,6 +12,7 @@ PROGRESS_FILE = "data/memory/book_progress.json"
|
|||||||
READ_DELAY = 0.2 # seconds between paragraphs
|
READ_DELAY = 0.2 # seconds between paragraphs
|
||||||
PARAGRAPH_MIN_LENGTH = 20
|
PARAGRAPH_MIN_LENGTH = 20
|
||||||
END_PUNCTUATION = {".", "!", "?"}
|
END_PUNCTUATION = {".", "!", "?"}
|
||||||
|
tokenizer = Tokenizer()
|
||||||
|
|
||||||
|
|
||||||
def get_books():
|
def get_books():
|
||||||
@ -18,8 +21,15 @@ def get_books():
|
|||||||
|
|
||||||
def load_progress():
|
def load_progress():
|
||||||
if os.path.exists(PROGRESS_FILE):
|
if os.path.exists(PROGRESS_FILE):
|
||||||
with open(PROGRESS_FILE, "r", encoding="utf-8") as f:
|
try:
|
||||||
return json.load(f)
|
with open(PROGRESS_FILE, "r", encoding="utf-8") as f:
|
||||||
|
data = f.read().strip()
|
||||||
|
if not data:
|
||||||
|
return {"progress": {}, "completed": []}
|
||||||
|
return json.loads(data)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[Reader] Failed to load progress file: {e}")
|
||||||
|
return {"progress": {}, "completed": []}
|
||||||
return {"progress": {}, "completed": []}
|
return {"progress": {}, "completed": []}
|
||||||
|
|
||||||
|
|
||||||
@ -81,7 +91,10 @@ async def read_books_forever():
|
|||||||
await asyncio.sleep(READ_DELAY)
|
await asyncio.sleep(READ_DELAY)
|
||||||
set_next_action(READ_DELAY, "Reading")
|
set_next_action(READ_DELAY, "Reading")
|
||||||
|
|
||||||
print(f"[Reader] Finished reading {book}.")
|
print(f"[Reader] Finished reading {book}. Taking a break to dream...")
|
||||||
|
save_vocab(tokenizer.vocab)
|
||||||
|
save_brainmap()
|
||||||
|
await asyncio.sleep(120) # 💤 2 minute nap after each book
|
||||||
completed_books.append(book)
|
completed_books.append(book)
|
||||||
progress_data["completed"] = list(set(completed_books))
|
progress_data["completed"] = list(set(completed_books))
|
||||||
save_progress(progress_data)
|
save_progress(progress_data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user