Qu

simple_rnn_classifier

Builtin index · Statistics & ML

result = simple_rnn_classifier(input_size, hidden_size, n_classes, [seed=])

Input: input_size, hidden_size, n_classes, seed · Output: result

What it is

Builds an untrained GRU-backed sequence classifier: input_size/hidden_size/n_classes positive integers (features per timestep, hidden width, and number of classes), plus an optional integer seed=.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = simple_rnn_classifier(input_size, hidden_size, n_classes, [seed=])
input_size numbernot documented yet
hidden_size numbernot documented yet
n_classes numbernot documented yet
seed number, optionalnot documented yet
result Model or vector
Returns a kind="simple_rnn_classifier" Model with .fit(sequences, labels, [epochs=], [lr=]), where sequences is a tuple of (input_size, seq_len) matrices and labels a length-M integer vector; .predict(sequences) returns a length-M vector of predicted classes.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

net = simple_cnn([6, 6], 2, seed = 3)
img1 = zeros(6, 6)
img1[2, 2] = 1.0
img1[2, 3] = 1.0
img1[3, 2] = 1.0
img1[3, 3] = 1.0
img2 = zeros(6, 6)
img2[1, 2] = 1.0
img2[2, 1] = 1.0
img2[2, 3] = 1.0
img2[3, 2] = 1.0
net = net.fit((img1, img2), [0, 1], epochs = 5, lr = 0.1)
print("simple_cnn predict rows: {rows(net.predict((img1, img2)))}")

rnn = simple_rnn_classifier(1, 6, 2, seed = 5)
seq1 = [0.1, 0.3, 0.5, 0.7, 0.9] as matrix(1, 5)
seq2 = [0.9, 0.7, 0.5, 0.3, 0.1] as matrix(1, 5)
rnn = rnn.fit((seq1, seq2), [0, 1], epochs = 5, lr = 0.1)
print("simple_rnn_classifier predict rows: {rows(rnn.predict((seq1, seq2)))}")
output
simple_cnn predict rows: 2
simple_rnn_classifier predict rows: 2

from statistics-ml

How it works

simple_rnn_classifier(input_size, hidden_size, n_classes, [seed=]) — gru_init's own weights plus a softmax-ready dense readout on the LAST hidden state (gru_forward(...)'s final list entry). out_w is (hidden_size, n_classes) — the standard dense(x, w, b) orientation — applied to the transposed (row-shaped) last hidden state via tt, since gru_forward's own hidden state is column-shaped (see gru_cell_compute's doc comment): dense(tt(h_last), out_w, out_b). Reuses gru_init directly (reseeding self.rng once up front so seed= covers both the GRU weights and the readout layer, not just the former).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.