I need assistance with resolving an error I encountered while training a model for a chat-bot. Any suggestions on troubleshooting this issue would be highly appreciated. Thank you.
Here is the code snippet:
Initializing the Neural Network:
var model = await tf.sequential();
model.add(tf.layers.dense({
units: 8,
inputShape: training[0].length
}));
// console.log(model);
model.add(tf.layers.dense({
units: 8
}));
model.add(tf.layers.dense({
units: 8
}));
model.add(tf.layers.dense({
units: output[0].length,
activation: 'softmax'
}))
model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});
await model.fit(tf.stack(training), tf.stack(output), {
epochs: 1000,
batchSize: 8
}).then(printCall => {
// Immediately Invoked Function Expression to solicit user input.
(function () {
console.log("(Type 'quit' to stop)");
while (true) {
let inp = "Hi";
if (inp.toLowerCase() == "quit")
break;
var results = model.predict(tf.tensor(bagOfWords(inp, uniq_words)));
console.log(result);
}
})();
})
Providing Data Details: training data in a 2d array format with dimensions of (23, 38) output data in a 2d array format with dimensions of (23, 6)
Bag of Words Methodology:
function bagOfWords(s, words) {
var bag = [];
for (var i = 0; i < uniq_words.length; i++) {
bag.push(0);
}
var sWords = tokenizer.tokenize(s);
var s_words = [];
sWords.map(each => {
s_words.push(natural.LancasterStemmer.stem(each));
});
for (var se in s_words) {
for (var w in uniq_words) {
if (uniq_words[w] == s_words[se])
bag[w] = 1;
}
}
return bag;
}
The bagOfWords function above generates a 1D array with dimensions of (38, 1).
If additional information or clarification is needed to better understand the problem, please feel free to ask. Appreciate your help.