- changed sample text
- changed model params
This commit is contained in:
@@ -24,17 +24,20 @@ from rbm.train import train
|
|||||||
from rbm.status import Status
|
from rbm.status import Status
|
||||||
|
|
||||||
# ── Hyper-parameters ──────────────────────────────────────────────────────────
|
# ── Hyper-parameters ──────────────────────────────────────────────────────────
|
||||||
TEXT = " HALLO SUPER JENS. SUPER! " # the character sequence to learn (matches diagram example)
|
TEXT = " HALLO SUPER JENS. SUPPE! " # the character sequence to learn (matches diagram example)
|
||||||
WIN = 3 # sliding-window width (= N in the diagram)
|
WIN = 3 # sliding-window width (= N in the diagram)
|
||||||
STRIDE = 1 # sliding-window step size
|
STRIDE = 1 # sliding-window step size
|
||||||
UNITS = 1
|
UNITS = 1
|
||||||
H_SIZE = 120 # hidden units per RBM cell
|
H_SIZE = 128 # hidden units per RBM cell
|
||||||
|
NUM_EPOCHS = 100
|
||||||
|
NUM_ITERATIONS = 100
|
||||||
|
|
||||||
TRAIN_PARAMS = TrainingParams(
|
TRAIN_PARAMS = TrainingParams(
|
||||||
learning_rate = 0.05,
|
learning_rate = 0.25,
|
||||||
momentum = 0.9,
|
momentum = 0.5,
|
||||||
num_epochs = 1000,
|
num_epochs = NUM_EPOCHS,
|
||||||
do_rao_blackwell = True,
|
do_rao_blackwell = True,
|
||||||
|
num_gibbs_samples= 1
|
||||||
)
|
)
|
||||||
#WIN=3
|
#WIN=3
|
||||||
#STRIDE=1
|
#STRIDE=1
|
||||||
@@ -78,7 +81,8 @@ class RnnModel(Model):
|
|||||||
for unit in self.units:
|
for unit in self.units:
|
||||||
train(unit, vc, status)
|
train(unit, vc, status)
|
||||||
# Update context portion of vc
|
# Update context portion of vc
|
||||||
vc[1:, WIN*vocab_size():] = unit.forward(vc)[0:-1,:]
|
_c = unit.forward(vc)
|
||||||
|
vc[1:, WIN*vocab_size():] = _c[0:-1,:]
|
||||||
|
|
||||||
def forward_step(self, _vc: Mat):
|
def forward_step(self, _vc: Mat):
|
||||||
for unit in self.units:
|
for unit in self.units:
|
||||||
@@ -115,8 +119,9 @@ if __name__ == "__main__":
|
|||||||
# context will be updated after training
|
# context will be updated after training
|
||||||
c_train = np.zeros([len(batch), H_SIZE])
|
c_train = np.zeros([len(batch), H_SIZE])
|
||||||
vc_train = concat(batch, c_train, axis=1)
|
vc_train = concat(batch, c_train, axis=1)
|
||||||
model.train(vc_train, status=Status())
|
for k in range(NUM_ITERATIONS):
|
||||||
model.save()
|
model.train(vc_train, status=Status())
|
||||||
|
model.save()
|
||||||
|
|
||||||
# test the model
|
# test the model
|
||||||
seed = str2vec('HA^')
|
seed = str2vec('HA^')
|
||||||
|
|||||||
Reference in New Issue
Block a user