Skip to content

Commit 0fa09d4

Browse files
committed
update
1 parent e9510c0 commit 0fa09d4

3 files changed

Lines changed: 16 additions & 15 deletions

File tree

tests/test_examples/test_tfts_inputs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_encoder_array(self):
2323
y_valid = np.random.rand(1, predict_sequence_length, 1)
2424

2525
for m in self.test_models:
26-
logger.info(f"Test model {m}")
26+
print(f"==== Test model {m} ====")
2727
config = AutoConfig.for_model(m)
2828
model = AutoModel.from_config(config, predict_sequence_length=predict_sequence_length)
2929
trainer = KerasTrainer(model)
@@ -65,6 +65,7 @@ def test_encoder_decoder_array2(self):
6565
n_decoder_feature = 3
6666

6767
x_train = (
68+
# x, encoder, decoder
6869
np.random.rand(1, train_length, 1),
6970
np.random.rand(1, train_length, n_encoder_feature),
7071
np.random.rand(1, predict_sequence_length, n_decoder_feature),
@@ -78,6 +79,7 @@ def test_encoder_decoder_array2(self):
7879
y_valid = np.random.rand(1, predict_sequence_length, 1)
7980

8081
for m in self.test_models:
82+
print(f"==== Test model {m} ====")
8183
config = AutoConfig.for_model(m)
8284
model = AutoModel.from_config(config, predict_sequence_length=predict_sequence_length)
8385
trainer = KerasTrainer(model)
@@ -116,6 +118,7 @@ def test_encoder_decoder_tfdata(self):
116118
valid_loader = valid_loader.batch(batch_size=1)
117119

118120
for m in self.test_models:
121+
print(f"==== Test model {m} ====")
119122
config = AutoConfig.for_model(m)
120123
model = AutoModel.from_config(config, predict_sequence_length=predict_sequence_length)
121124
trainer = KerasTrainer(model)

tfts/models/seq2seq.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ def __init__(
214214
self.num_attention_heads = num_attention_heads
215215
self.attention_probs_dropout_prob = attention_probs_dropout_prob
216216

217-
def build(self, decoder_features_shape, decoder_init_input_shape, init_state_shape, **kwargs):
218-
rnn_input_size = decoder_features_shape[-1] + decoder_init_input_shape[-1]
217+
def build(self, input_shape, **kwargs):
218+
batch_size = input_shape[0]
219+
rnn_input_size = input_shape[-1] + 1
219220

220221
if self.use_attention:
221222
encoder_output_shape = kwargs.get("encoder_output_shape")
@@ -228,21 +229,18 @@ def build(self, decoder_features_shape, decoder_init_input_shape, init_state_sha
228229
)
229230
self.attention.build(encoder_output_shape)
230231

231-
# Add attention output size to RNN input size
232-
rnn_input_size += encoder_output_shape[-1]
233-
234232
if self.rnn_type == "gru":
235233
self.rnn_cell = GRUCell(self.rnn_size)
236234
elif self.rnn_type == "lstm":
237235
self.rnn_cell = LSTMCell(units=self.rnn_size)
238236
else:
239237
raise ValueError(f"Unsupported rnn type: {self.rnn_type}")
240238

241-
self.rnn_cell.build([None, rnn_input_size])
239+
self.rnn_cell.build([batch_size, rnn_input_size])
242240

243241
self.dense = Dense(units=1, activation=None)
244-
self.dense.build([None, self.rnn_size])
245-
super().build(decoder_features_shape)
242+
self.dense.build([batch_size, self.rnn_size])
243+
super().build(input_shape)
246244

247245
def call(
248246
self,

tfts/models/wavenet.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ def __call__(
111111
encoder_state, encoder_outputs = self.encoder(encoder_feature)
112112
decoder_outputs = self.decoder(
113113
decoder_features=decoder_feature,
114-
decoder_init_input=x[:, -1],
114+
# imagine the first dim is the predict
115+
decoder_init_input=x[:, -1, 0:1],
115116
teacher=teacher,
116117
encoder_outputs=encoder_outputs,
117118
)
118-
119119
return decoder_outputs
120120

121121

@@ -200,9 +200,9 @@ def __init__(
200200
self.dilation_rates = dilation_rates
201201
self.dense_hidden_size = dense_hidden_size
202202

203-
def build(self, decoder_features_shape, decoder_init_input_shape, encoder_outputs_shape=None, **kwargs):
204-
batch_size = decoder_features_shape[0]
205-
decoder_input_size = decoder_features_shape[-1] + decoder_init_input_shape[-1]
203+
def build(self, input_shape, **kwargs):
204+
batch_size = input_shape[0]
205+
decoder_input_size = input_shape[-1] + 1
206206

207207
self.dense1 = Dense(self.filters, activation="tanh")
208208
self.dense1.build([batch_size, decoder_input_size])
@@ -223,7 +223,7 @@ def build(self, decoder_features_shape, decoder_init_input_shape, encoder_output
223223
self.dense6 = Dense(1)
224224
self.dense6.build([batch_size, self.dense_hidden_size])
225225

226-
super().build(decoder_features_shape)
226+
super().build(input_shape)
227227

228228
def call(
229229
self,

0 commit comments

Comments
 (0)