We will be using the ordinary cross-entropy loss function here, which can be implemented as follows:
losses := gorgonia.Must(gorgonia.HadamardProd(gorgonia.Must(gorgonia.Log(m.out)), y))
cost := gorgonia.Must(gorgonia.Sum(losses))
cost = gorgonia.Must(gorgonia.Neg(cost))
if _, err = gorgonia.Grad(cost, m.learnables()...); err != nil {
log.Fatal(err)
}
Together with that, we will be using the Gorgonia tape machine and the RMSprop solver, as shown here:
vm := gorgonia.NewTapeMachine(g, gorgonia.WithPrecompiled(prog, locMap), gorgonia.BindDualValues(m.learnables()...))
solver := gorgonia.NewRMSPropSolver(gorgonia.WithBatchSize(float64(bs)))