Documentation ¶
Overview ¶
Package ntm implements the Neural Turing Machine architecture as described in A.Graves, G. Wayne, and I. Danihelka. arXiv preprint arXiv:1410.5401, 2014.
Using this package along its subpackages, the "copy", "repeatcopy" and "ngram" tasks mentioned in the paper were verified. For each of these tasks, the successfully trained models are saved under the filenames "seedA_B", where A is the number indicating the seed provided to rand.Seed in the training process, and B is the iteration number in which the trained weights converged.
Index ¶
- func HeadWeights(machines []*NTM) [][][]float64
- func NewEmptyController1(xSize, ySize, h1Size, numHeads, n, m int) *controller1
- func Predictions(machines []*NTM) [][]float64
- func Sigmoid(x float64) float64
- func Sprint2(t [][]float64) string
- type Controller
- type DensityModel
- type Head
- func (h *Head) AddGrad() []float64
- func (h *Head) AddVal() []float64
- func (h *Head) BetaGrad() *float64
- func (h *Head) BetaVal() *float64
- func (h *Head) EraseGrad() []float64
- func (h *Head) EraseVal() []float64
- func (h *Head) GGrad() *float64
- func (h *Head) GVal() *float64
- func (h *Head) GammaGrad() *float64
- func (h *Head) GammaVal() *float64
- func (h *Head) KGrad() []float64
- func (h *Head) KVal() []float64
- func (h *Head) SGrad() *float64
- func (h *Head) SVal() *float64
- type LogisticModel
- type MultinomialModel
- type NTM
- type RMSProp
- type SGDMomentum
- type Unit
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HeadWeights ¶
HeadWeights returns the addressing weights of all memory heads across time. The top level elements represent each head. The second level elements represent every time instant.
func NewEmptyController1 ¶
func NewEmptyController1(xSize, ySize, h1Size, numHeads, n, m int) *controller1
NewEmptyController1 returns a new controller1 which is a single layer feedforward network. The returned controller1 is empty in that all its network weights are initialized as 0.
func Predictions ¶
Predictions returns the predictions of a NTM across time.
Types ¶
type Controller ¶
type Controller interface { // Heads returns the emitted memory heads. Heads() []*Head // YVal returns the values of the output of the Controller. YVal() []float64 // YVal returns the gradients of the output of the Controller. YGrad() []float64 // Forward creates a new Controller which shares the same internal weights, // and performs a forward pass whose results can be retrived by Heads and Y. Forward(reads []*memRead, x []float64) Controller // Backward performs a backward pass, // assuming the gradients on Heads and Y are already set. Backward() // Wtm1BiasVal returns the values of the bias of the previous weight. // The layout is |-- 1st head weights (size memoryN) --|-- 2nd head --|-- ... --| // The length of the returned slice is numHeads * memoryN. Wtm1BiasVal() []float64 Wtm1BiasGrad() []float64 // M1mt1BiasVal returns the values of the bias of the memory bank. // The returned matrix is in row major order. Mtm1BiasVal() []float64 Mtm1BiasGrad() []float64 // WeightsVal returns the values of all weights. WeightsVal() []float64 // WeightsGrad returns the gradients of all weights. WeightsGrad() []float64 // WeightsDesc returns the descriptions of a weight. WeightsDesc(i int) string // NumHeads returns the number of memory heads of a controller. NumHeads() int // MemoryN returns the number of vectors of the memory bank of a controller. MemoryN() int // MemoryM returns the size of a vector in the memory bank of a controller. MemoryM() int }
The Controller interface is implemented by NTM controller networks that wish to operate with memory banks in a NTM.
type DensityModel ¶
type DensityModel interface { // Model sets the value and gradient of Units of the output layer. Model(t int, yHVal []float64, yHGrad []float64) // Loss is the loss definition of this model. Loss(output [][]float64) float64 }
A DensityModel is a model of how the last layer of a network gets transformed into the final output.
type Head ¶
type Head struct { Wtm1 *refocus // the weights at time t-1 M int // size of a row in the memory // contains filtered or unexported fields }
A Head is a read write head on a memory bank. It carriess information that is required to operate on a memory bank according to the NTM architecture.
func (*Head) GVal ¶
GVal: G returns the degree in which we want to choose content-addressing over location-based-addressing.
func (*Head) GammaVal ¶
GammaVal: Gamma returns the degree in which the addressing weights are sharpened.
type LogisticModel ¶
type LogisticModel struct { // Y is the strength of the output unit at each time step. Y [][]float64 }
A LogisticModel models its outputs as logistic sigmoids.
func (*LogisticModel) Loss ¶
func (m *LogisticModel) Loss(output [][]float64) float64
Loss returns the cross entropy loss.
type MultinomialModel ¶
type MultinomialModel struct { // Y is the class of the output at each time step. Y []int }
A MultinomialModel models its outputs as following the multinomial distribution.
func (*MultinomialModel) Loss ¶
func (m *MultinomialModel) Loss(output [][]float64) float64
type NTM ¶
type NTM struct { Controller Controller // contains filtered or unexported fields }
A NTM is a neural turing machine as described in A.Graves, G. Wayne, and I. Danihelka. arXiv preprint arXiv:1410.5401, 2014.
func ForwardBackward ¶
func ForwardBackward(c Controller, in [][]float64, out DensityModel) []*NTM
ForwardBackward computes a controller's prediction and gradients with respect to the given ground truth input and output values.
func MakeEmptyNTM ¶
func MakeEmptyNTM(c Controller) *NTM
MakeEmptyNTM makes a NTM with its memory and head weights set to their bias values, based on the controller.
type RMSProp ¶
type RMSProp struct { C Controller N []float64 G []float64 D []float64 }
RMSProp implements the rmsprop algorithm. The detailed updating equations are given in Graves, Alex (2013). Generating sequences with recurrent neural networks. arXiv preprint arXiv:1308.0850.
func NewRMSProp ¶
func NewRMSProp(c Controller) *RMSProp
type SGDMomentum ¶
type SGDMomentum struct { C Controller PrevD []float64 }
SGDMomentum implements stochastic gradient descent with momentum.
func NewSGDMomentum ¶
func NewSGDMomentum(c Controller) *SGDMomentum
func (*SGDMomentum) Train ¶
func (s *SGDMomentum) Train(x [][]float64, y DensityModel, alpha, mt float64) []*NTM