'Windows in tensorflow dataset with sequence AND constant input
I have a dataset of the following form:
import tensorflow as tf
num_inputs = 3
num_outputs = 5
num_params = 5
num_samples = 32
sequence_length = 50
input_sequences = tf.random.normal((num_samples, sequence_length, num_inputs))
output_sequences = tf.random.normal((num_samples, sequence_length, num_outputs))
input_params = tf.random.normal((num_samples, num_params))
dataset = tf.data.Dataset.from_tensor_slices((
{'sequence': input_sequences, 'parameters': input_params},
output_sequences
))
And I want to train a model on this that takes two inputs: a window of say 10 consecutive steps in a sequence, and the corresponding parameters (which do not have a sequence dimension, but vary from sample to sample). It should output the 10th step of the output sequence.
So I want to create from this a new dataset of samples of the form
windows = {'sequence': (10 steps), 'parameters': (single constant vector of parameters)}, (single output step 10)
What is the clean way to do this, ideally without just copying the sequence into many overlapping windows, and for each window copying the corresponding parameters.
I know there is the window method, but I don't know how to apply it to this case. All the examples I've seen just apply it to a toy dataset that has only one type of data, not an input and output, never mind two inputs as here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
