Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function train(inputs, test_result, iterations) {
for(var i = 0; i < iterations; i++) {
var layer_zero = inputs;
var layer_one = nj.sigmoid( layer_zero.dot(weights_zero) );
var layer_two = nj.sigmoid( layer_one.dot(weights_one) );
var layer_two_error = test_result.subtract(layer_two);
if ((i % 10000) == 0) {
console.log(i + " - Error: " + nj.mean(nj.abs(layer_two_error)));
}
// Backpropagation (sending back layer_two errors to layer_one)
var layer_two_delta = layer_two_error.multiply( curve(layer_two) );
var layer_one_error = layer_two_delta.dot( weights_one.T );
var layer_one_delta = layer_one_error.multiply( curve(layer_one) );
// Adjusting weights
weights_one = weights_one.add(
layer_one.T.dot(layer_two_delta).multiply(alpha)
);
function think(sentence) {
var x = bow(sentence, words);
var l0 = x;
var l1 = nj.sigmoid(nj.dot(l0, synapse_0));
var l2 = nj.sigmoid(nj.dot(l1, synapse_1));
return l2;
}
function think(inputs) {
var layer_one = nj.sigmoid( inputs.dot(weights_zero) );
var layer_two = nj.sigmoid( layer_one.dot(weights_one) );
return layer_two;
}
function think(inputs) {
var layer_one = nj.sigmoid( inputs.dot(weights_zero) );
var layer_two = nj.sigmoid( layer_one.dot(weights_one) );
return layer_two;
}
LSTMCell.prototype.forward = function(x, h, c) {
var concat = nj.concatenate([x, h]);
var hidden = nj.add(nj.dot(concat, this.Wfull), this.bias);
var num_units = this.num_units;
var forget_bias = this.forget_bias;
var i = nj.sigmoid(hidden.slice([0 * num_units, 1 * num_units]));
var g = nj.tanh(hidden.slice([1 * num_units, 2 * num_units]));
var f = nj.sigmoid(nj.add(hidden.slice([2 * num_units, 3 * num_units]), forget_bias));
var o = nj.sigmoid(hidden.slice([3 * num_units, 4 * num_units]));
var new_c = nj.add(nj.multiply(c, f), nj.multiply(g, i));
var new_h = nj.multiply(nj.tanh(new_c), o);
return [new_h, new_c];
};
LSTMCell.prototype.encode = function(sequence) {
function think(inputs) {
var layer_one = nj.sigmoid( inputs.dot(weights_zero) );
var layer_two = nj.sigmoid( layer_one.dot(weights_one) );
return layer_two;
}