Added coherence fix
This commit is contained in:
parent
c9f37a3781
commit
0716291d9d
30
trainer.py
30
trainer.py
@ -145,18 +145,25 @@ class RubyTrainer:
|
|||||||
raw = self.generate_reply()
|
raw = self.generate_reply()
|
||||||
attempts += 1
|
attempts += 1
|
||||||
|
|
||||||
|
if not raw or len(raw.strip().split()) < 4:
|
||||||
|
continue
|
||||||
|
for _ in range(rounds):
|
||||||
|
raw = self.generate_reply()
|
||||||
if not raw or len(raw.strip().split()) < 4:
|
if not raw or len(raw.strip().split()) < 4:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
rephrased = self.self_rephrase(raw)
|
rephrased = self.self_rephrase(raw)
|
||||||
if len(rephrased.split()) >= len(raw.split()) and rephrased.strip().endswith("."):
|
final = rephrased if (
|
||||||
final = rephrased
|
len(rephrased.split()) >= len(raw.split()) and rephrased.strip().endswith(".")
|
||||||
else:
|
) else raw
|
||||||
final = raw
|
|
||||||
|
|
||||||
self.train_on_tokens_from_text(final)
|
self.train_on_tokens_from_text(final)
|
||||||
thoughts.append(final)
|
thoughts.append(final)
|
||||||
|
|
||||||
|
if self.is_coherent(final):
|
||||||
|
with open("logs/core_dreams.txt", "a", encoding="utf-8") as f:
|
||||||
|
f.write(final.strip() + "\n")
|
||||||
|
|
||||||
with open(log_output, "a", encoding="utf-8") as f:
|
with open(log_output, "a", encoding="utf-8") as f:
|
||||||
for t in thoughts:
|
for t in thoughts:
|
||||||
f.write(f"[DREAM] {t}\n")
|
f.write(f"[DREAM] {t}\n")
|
||||||
@ -186,3 +193,18 @@ class RubyTrainer:
|
|||||||
|
|
||||||
for line in core_memories:
|
for line in core_memories:
|
||||||
self.train_on_tokens_from_text(line)
|
self.train_on_tokens_from_text(line)
|
||||||
|
|
||||||
|
def is_coherent(self, text: str) -> bool:
|
||||||
|
words = text.lower().split()
|
||||||
|
unique = set(words)
|
||||||
|
|
||||||
|
if len(unique) < 5:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not any(w in unique for w in ["i", "you", "they", "we", "it"]):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not any(w in unique for w in ["am", "are", "is", "was", "want", "feel", "know", "see", "learn", "change"]):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return text.strip().endswith(".")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user