'lstm different input and output shape

input shape

tf.tensor3d([
    [
      [0.01, 0.02, 0.03],
      [0.01, 0.02, 0.03],
      [0.01, 0.02, 0.03],
      [0.01, 0.02, 0.03],
      [0.01, 0.02, 0.03],
    ],
    [
      [0.02, 0.03, 0.04],
      [0.02, 0.03, 0.04],
      [0.02, 0.03, 0.04],
      [0.02, 0.03, 0.04],
      [0.01, 0.02, 0.03],
    ],
    [
      [0.03, 0.05, 0.06],
      [0.03, 0.05, 0.06],
      [0.03, 0.05, 0.06],
      [0.03, 0.05, 0.06],
      [0.01, 0.02, 0.03],
    ],
  ]);

output shape

  const ys = tf.tensor3d([
    [
      [0.01, 0.02, 0.03],
      [0.01, 0.02, 0.03],
      [0.01, 0.02, 0.03],
    ],
    [
      [0.02, 0.03, 0.04],
      [0.02, 0.03, 0.04],
      [0.02, 0.03, 0.04],
    ],
    [
      [-0.03, 0.05, 0.06],
      [0.03, -0.05, 0.06],
      [0.03, 0.05, -0.06],
    ],
  ]);

I am trying to use the lstm layers to create a prediction model. The problem is that I just know how to change units variable of lstm layers only.

I've been looking for a way to convert to tensor3d but with different rows. I could only find a way to turn it to 1d or 2d shape.

  model.add(
    tf.layers.lstm({
      units: 30,
      returnSequences: true,
      inputShape: [5, 3],
      batchInputShape: [3, 3, 3],
    })
  );
  model.add(tf.layers.lstm({ units: 3, returnSequences: true }));
  // Prepare the model for training: Specify the loss and the optimizer.
  model.compile({ loss: "meanSquaredError", optimizer: "adam" });

Which layers and variables do I have to put in there to turn the input of [3,5,3] to [3,3,3]?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source