The exact same question has been posted a few times, but unfortunately haven't found the answer. What I'm trying to do is to build a one-to-one RNN, where the previous timestep's output is the input of the current timestep with the layers API. Here's my example code, tried to make it as simple as possible:
const cells = [
tf.layers.simpleRNNCell({units: 4, activation: 'relu'}),
tf.layers.simpleRNNCell({units: 3, activation: 'relu'}),
];
const rnn = tf.layers.rnn({cell: cells, returnSequences: true});
const x = tf.tensor([
[
[10, 8, 5],
],
[
[0, 2, 0],
],
]);
const y = tf.tensor([
[
[0.3, 0.5, 0.4],
],
[
[0.1, 0, 0]
]
])
const model = tf.sequential();
model.add(tf.layers.inputLayer({ inputShape: [1, 3] }))
for (let i = 0; i < 10; i++) {
model.add(rnn)
};
model.compile({
loss: 'categoricalCrossentropy',
optimizer: 'adam',
metrics: ['accuracy']
});
model.fit(x, y, {
epochs: 10,
batchSize: x.shape[0],
yieldEvery: 'batch'
});
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>
You can try it as well, it will throw an error (in browser it throws: Error: 'slice' not yet implemented or not found in the registry. This kernel may not be supported by the tfjs backend you have chosen, in node it throws what's in the question title).
What am I doing wrong?