Why?

A good question to ask is why? Why bother with this separation of processes? After all, the preceding code could be rewritten as the previous chapter's Predict function:

func (nn *NN) Predict(a tensor.Tensor) (int, error) {  if a.Dims() != 1 {    return nil, errors.New("Expected a vector")  }  var m maybe  act0 := m.sigmoid(m.matVecMul(nn.hidden, a))  pred := m.sigmoid(m.matVecMul(nn.final, act0))  if m.err != nil {    return -1, m.err  }  return argmax(pred.Data().([]float64)), nil}

Here, we define the network in Go, and when we run the Go code, the neural network is run as it is being defined. What's the problem we face that we need to introduce the idea of separating the definition of the neural network and running it? We've already seen the problem ...

Get Go Machine Learning Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.