The basics of Gorgonia

Gorgonia is a lower-level library, which means that we need to build the equations and the architecture for models ourselves. This means that there isn't a built-in DNN classifier function that will magically create an entire model with several hidden layers and immediately be ready to apply to your dataset.

Gorgonia facilitates DL by being a library that makes working with multidimensional arrays easy. It does this by providing loads of operators to work with so you can build the underlying mathematical equations that make up layers in a DL model. We can then proceed to use these layers in our model.

Another important feature of Gorgonia is performance. By removing the need to think about how to optimize tensor operations, we can focus on building the model and ensuring the architecture is correct, rather than worrying about whether or not our model will be performant.

As Gorgonia is a little lower-level than a typical ML library, building a model takes a few more steps. However, this does not mean that building a model in Gorgonia is difficult. It requires the following three basic steps:

  1. Create a computation graph
  2. Input the data
  3. Execute the graph

Wait, what's a computation graph? A computation graph is a directed graph where each of the nodes is either an operation or a variable. Variables can be fed into operations, which will then produce a value. This value can then be fed into another operation. In more familiar terms, a graph is like a function that takes all of the variables and then produces a result.

A variable can be anything; we can make it a single scalar value, a vector (that is, an array), or a matrix. In DL, we typically work with a more generalized structure called a tensor; a tensor can be thought of as something similar to an n-dimensional matrix.

The following screenshot shows a visual representation of n-dimensional tensors:

We represent equations as graphs because this makes it easier for us to optimize the performance of our model. This is enabled by the fact that, by putting each node in a directed graph, we have a good idea of what its dependencies are. Since we model each node as an independent piece of code, we know that all it needs to execute are its dependencies (which can be other nodes or other variables). Also, as we traverse the graph, we can know which nodes are independent of each other and run those concurrently.

For example, take the following diagram:

As A, B, and C are independent, we can easily compute these concurrently. The computation of V requires both A and B to be ready. However, W only requires B to be ready. This follows into the next level, and so on, up until we are ready to compute the final output in Z.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset