I have a neural network (which I am making from scratch). In order to make the neural network "learn" I need to conduct back-propagation. Using the code at the below how would I conduct back-propagation.

FYI: I have tried using the tf.train functions and .minimize(loss) but I got this error message: The f passed in variableGrads(f) must be a function.

var X = tf.tensor([[1,2,3], [4,5,6], [7,8,9]])
var Y = tf.tensor([[0,0,1]])
var m = X.shape[0]
var a0 = tf.zeros([1,3])

var parameters = {
    "Wax": tf.randomUniform([3,3]),
    "Waa": tf.randomUniform([3,3]),
    "ba": tf.zeros([1,3]),
    "Wya": tf.randomUniform([3,3]),
    "by": tf.zeros([1,3])

function RNN_cell_Foward(xt, a_prev, parameters){
    var Wax = parameters["Wax"]
    var Waa = parameters["Waa"]
    var ba = parameters["ba"]

    var a_next = tf.sigmoid(tf.add(tf.add(tf.matMul(xt, Wax), tf.matMul(a_prev , Waa)),ba) )

    return a_next
function RNN_FowardProp(X, a0, parameters){
    var T_x  = X.shape[0]
    var a_next = a0
    var i = 1
    var Wya = parameters["Wya"]
    var by = parameters["by"]
    for(; i <= T_x; i++){
        var xt = X.slice([i-1,0],[1,-1])
        a_next = RNN_cell_Foward(xt, a_next, parameters)
    var y_pred = tf.sigmoid(tf.add(tf.matMul(a_next, Wya), by))
  return y_pred
const learningRate = 0.01;
var optimizer = tf.train.sgd(learningRate);
var model = RNN_FowardProp(X, a0, parameters)
var loss = tf.losses.meanSquaredError(Y, model)
for (let i = 0; i < 10; i++) {
  • 1
    $\begingroup$ Hi. This site focuses on theoretical, philosophical, and social aspects of AI, not on programming issues/bugs. Please, read ai.stackexchange.com/help/on-topic for more details. I suggest that you ask this question on Stack Overflow, given that yours is a programming issue. $\endgroup$ – nbro Aug 14 at 10:53
  • $\begingroup$ Ok, I was not aware of that. I have posted this question on stack-overflow too. Please answer it if you can: stackoverflow.com/questions/63410617/… $\endgroup$ – jr123456jr987654321 Aug 14 at 11:22
  • $\begingroup$ I will leave this question open because you opened a bounty, but, please, next time, do not start a bounty on a question that is off-topic. $\endgroup$ – nbro Aug 16 at 10:37
  • $\begingroup$ @nbro, Thanks. Sorry about the inconvenience I did not see your comment before setting a bounty. $\endgroup$ – jr123456jr987654321 Aug 16 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.