fixed error for other WIN sizes
This commit is contained in:
@@ -24,16 +24,16 @@ from rbm.train import train
|
||||
from rbm.status import Status
|
||||
|
||||
# ── Hyper-parameters ──────────────────────────────────────────────────────────
|
||||
TEXT = " HALLO SUPER JENS!" # the character sequence to learn (matches diagram example)
|
||||
WIN = 3 # sliding-window width (= N in the diagram)
|
||||
TEXT = " HALLO SUPER JENS UND SUPER MAUSI!" # the character sequence to learn (matches diagram example)
|
||||
WIN = 5 # sliding-window width (= N in the diagram)
|
||||
STRIDE = 1 # sliding-window step size
|
||||
UNITS = 1
|
||||
H_SIZE = 128 # hidden units per RBM cell
|
||||
NUM_EPOCHS = 1000
|
||||
NUM_ITERATIONS = 1
|
||||
H_SIZE = 180 # hidden units per RBM cell
|
||||
NUM_EPOCHS = 100
|
||||
NUM_ITERATIONS = 10
|
||||
|
||||
TRAIN_PARAMS = TrainingParams(
|
||||
learning_rate = 0.25,
|
||||
learning_rate = 0.04,
|
||||
momentum = 0.5,
|
||||
num_epochs = NUM_EPOCHS,
|
||||
do_rao_blackwell = True,
|
||||
@@ -125,14 +125,20 @@ if __name__ == "__main__":
|
||||
model.save()
|
||||
|
||||
# test the model
|
||||
seed = str2vec('HA^')
|
||||
v_forward = seed.flatten()
|
||||
seed_str = 'HA^'
|
||||
seed_padded = ' '*(WIN-len(seed_str)) + seed_str
|
||||
v_forward = str2vec(seed_padded).flatten()
|
||||
context = c_train[0]
|
||||
text_predict = ''
|
||||
for i in range(len(TEXT)+5):
|
||||
v_mat = v_forward.reshape([WIN, vocab_size()])
|
||||
print(f"Forward {i:02d}: {vec2str(v_mat, axis=1)}")
|
||||
v_predict, context = model.forward_step(v_mat, context)
|
||||
v_predict_clamp = clamp(v_predict.reshape([WIN, vocab_size()]), axis=1)
|
||||
print(f"Predict {i:02d}: {vec2str(v_predict_clamp, axis=1)}")
|
||||
v_predict_mat = v_predict.reshape([WIN, vocab_size()])
|
||||
v_predict_clamp = clamp(v_predict_mat, axis=1)
|
||||
v_predict_str = vec2str(v_predict_clamp, axis=1)
|
||||
text_predict += v_predict_str[WIN-1]
|
||||
print(f"Predict {i:02d}: {v_predict_str}")
|
||||
v_forward = shift_left(v_predict_clamp.reshape([1, WIN*vocab_size()]), vocab_size())
|
||||
|
||||
print(seed_padded[0:WIN-1] + text_predict)
|
||||
Reference in New Issue
Block a user