November 2018
Beginner to intermediate
348 pages
8h 32m
English
Recall that neural networks built in Gorgonia only take tensor.Tensors as inputs. Therefore, the labels will also have to be converted into tensor.Tensor. The function is quite similar to prepareX:
func prepareY(N []Label) (retVal tensor.Tensor) { rows := len(N) cols := 10 b := make([]float64, 0, rows*cols) for i := 0; i < rows; i++ { for j := 0; j < 10; j++ { if j == int(N[i]) { b = append(b, 1) } else { b = append(b, 0) } } } return tensor.New(tensor.WithShape(rows, cols), tensor.WithBacking(b))}
What we're building here is a matrix with N rows and ten columns. The specifics of why we build a matrix of (N,10) will be explored in the next chapter, but for now let's zoom into an imaginary row. Imagine the first ...
Read now
Unlock full access