Here’s an example of how I set up this module in a working state using this script to train on text data, from a couple months ago for those interested. I didn’t know what I was doing but after some tinkering and back and forth with Anthropics Claude2, with its 100,000 context length and analyzing the code of the RNN module.
-- Load RNN module
local RNN = require('RNN')
-- Sample text
local text = "[[Text data]]"
-- Create mappings
local chars = {}
for c in text:gmatch"." do
table.insert(chars, c)
end
local charToIndex = {}
local indexToChar = {}
for i,c in ipairs(chars) do
charToIndex[c] = i
indexToChar[i] = c
end
-- Convert text to input/target pairs
local inputs, targets = {}, {}
for i=1,#text-1 do
local input = charToIndex[text:sub(i,i)]
table.insert(inputs, input)
local target = charToIndex[text:sub(i+1,i+1)]
table.insert(targets, target)
end
-- Create RNN
local inputSize = #chars
local hiddenSize = 10
local outputSize = #chars
local rnn = RNN.new(100, 0.1, 'tanh', 0.01)
rnn:createLayers(inputSize, hiddenSize, outputSize)
-- Train
for epoch=1,100 do
for i=1,#inputs do
local input = inputs[i]
local target = targets[i]
rnn:train({input}, {target})
end
end
-- Predict
local input = charToIndex['T']
local output = rnn:predict({input})[1]
print(indexToChar[output])
Still learning how to use it but this example runs. Still learning hope to learn more in the future. When I asked ChatGPT what it thought of the result, it said it looks like it needs to train more.
But if I was to use this to train a text-based bot, I think the best it could do on this platform would be akin to search engine optimization. But if we utilize multiple models potentially only trained on a dataset of context specific examples like the one my textbot has it could potentially train the model.
Greetings = {
“Hello, there. I’m pleased to see you.”,
“Wow. You have a remarkable aura about you.”,
“Yay. You’re here. Let’s have some fun.”,
“Hello. I’m curious to meet you.”,
“Hey. You’re amazing. Thanks for coming.”,
“Greetings. I’m honored to have you here.”,
“Howdy. You’re so cool. Let’s be friends.”
}
I also have a massive table of synonyms nested. These two scripts 1 split words into an array, 2. replaces a word with the first synonym in the nested table thus massively reducing vocalbulary size while also maintaining coherence. This would make the data simpler for the machine algorithm to understand, thus decreasing its size and training time. I think a realistic goal could be for it to be able to construct sentence.This architure would need to be worked on to include linear regression to speed up training time, I’m just thinking about it. I got other things to do right now, but i think it could work.
local synonympairs={
-- Introductory
{ "knowledgeable ", "informed", "studied", "well-versed", "practiced", "aware "},{ "smoothly ", "without trial ", "easy ", "relaxing ", "enjoyable "},{ "faring", "riding", "sailing"},{ "ditches ", "pits "},{ "careful ", "insightful ", "cautious ", "steady "}
,{ "events ", "things ", "occurences ", "situations "},{ "Did you know ", "Were you aware ", "Have you heard "},{ "trapped", "stuck ", "immobile "},{ "happening", "occuring", "going on", "preceding"},{ "need", "require ", "desire "},{ "sparkle in your eye! ", "keen eye for adventure! ", "heart of a warrior! ", "unyielding spirit of a legendary warrior! "},{ "legendary ", "mythical ", "fabled", "powerful ", "renowned", "valiant ", "glorious "},{ "unyielding", "determined", "hardened", "battle-ready", "stubborn tenacity"},{ " assistance ", " help "},{ " comment ", " state ", " share ", " tell "},{ "Howerever, ", "Moreover, ", "In addition, ", "Furthermore, "},{ "nothing", "not a single thing"},{ "share ", "spread ", "part "},{ "escape ", "get away "},{ " best ", " greatest "},{ " special ", " unique ", " one of a kind ", " one in a billion "},{ "offering", "bartering", "trading"},{ "giving", "offering"},{ "soul ", "essence ", "mana ", "immortal-soul "},{ " said, "},{ "stocked", "available "},{ "sells ", "barters ", "trades in ", "has available "},{ "find ", "discover ", "uncover "},{ "looking", "searching"},{ "liking ", "enjoyment ", "privy ", "tastes ", "sensitivities "},{ "value ", "worth ",},{ "given ", "bestowed", "relinquished"},{ "quantity ", "amount "},{ "quantities ", "amounts "},{ " devour ", " consume ", " feed-on ", " eat "},{ "warp ", "distort "},{ "strong ", "incredible ", "powerful "},{ "facts ", "knowledge ", "matters "},{ "infinite ", "unlimited"},{ "conjunction ", "along with "},{ " dimension ", " place ", " material plane "},{ "regenerate ", "recouperate ", "restore "},{ "topic ", "subject "},{ "entities ", "monsters "},{ "destructive ", "chaotic "},{ "absorb ", "assimilate ", "sap energy from "},{ "However, ", "Morever, ", "In addition, ", "Also, ", "Not to mention, ", "This includes, "},{ " encounter ", " see "},{ "trap ", "diversion ", "obstacle "},{ "minion ", "disciple "},{ "mindless ", "thoughtless ", "brainless ", "will-less "},{ "used", "harnessed", "portrayed", "pictured"},{ "touches ", "makes with contact with ", "contacts "},{ "feeling", "doing"},{ "infinite", "never-ending", "limitless"},{ "treasures ", "trinkets ", "artifacts ", "loot ", "spoils "},{ "untold ", "unforeseen ", "unspoken ", "unknown "},{ "decieve ", "fool ", "mislead ", "misguide "},{ "underground ", "subterranean "},{ "unsuspecting ", "innocent ", "credulous ", "easy ", "simple ", "unsuspicious "},{ "hungry ", "starving ", "famished"},{ "creature ", "monster ", "entity "},{ "anything", "everything"},{ "shape ", "form ", "structure "},{ "size ", "volume ", "area "},
{ "happy ", "joyful ", "cheerful ", "glad ", "delighted"}}--,...etc"
function chatmodule.splitString(str)
local words = {}
if str~=nil then
if str:gmatch("%w+") then
for word in str:gmatch("%w+") do -- %w+ matches one or more alphanumeric characters
table.insert(words, word) -- insert the word into the words array
end
else return str
end
return words
end
end
function chatmodule.randomizeStringLight(str,interphrases,randomize)
--local interchangedphrases=phrases
-- Split the string into sentences
local sentences = {}
local str=tostring(str)
local words=chatmodule.splitString(str)
if #words>1 then
for s in str:gmatch("[^%.]+") do
table.insert(sentences, s)
end
-- Loop through the sentences and replace any matching phrases with a random one from the table
local newSentences = {}
for i, s in ipairs(sentences) do
local newS = s
for j, phrases in ipairs(interphrases) do
for k, phrase in ipairs(phrases) do
if s:find(phrase) then
-- Pick a random phrase from the same group
local randomPhrase
if randomize==nil then
randomPhrase = phrases[chatmodule.mathrandom(#phrases)]
else
randomPhrase= phrases[randomize]
end
-- Replace the original phrase with the random one
newS = newS:gsub(phrase, randomPhrase)
for i, s in ipairs(chatmodule.splitString(newS)) do
local newS = s
for j, phrases in ipairs(interphrases) do
for k, phrase in ipairs(phrases) do
if s:find(phrase) then
-- Pick a random phrase from the same group
local randomPhrase
if randomize==nil then
randomPhrase = phrases[chatmodule.mathrandom(#phrases)]
else
randomPhrase= phrases[randomize]
end
-- Replace the original phrase with the random one
newS = newS:gsub(phrase, randomPhrase)
-- break
end
end
end
--table.insert(newSentences, newS)
end
--break
end
end
end
table.insert(newSentences, newS)
end
-- Join the new sentences with periods and return the result
return table.concat(newSentences, "")
end
end
These two scripts 1 split words into an array, 2. replaces a word with the first synonym in the nested table thus massively reducing vocalbulary size while also maintaining coherence