[JayRnn]
- reduced VOCAB - changed test text
This commit is contained in:
@@ -24,23 +24,21 @@ from rbm.train import train
|
|||||||
from rbm.status import Status
|
from rbm.status import Status
|
||||||
|
|
||||||
# ── Hyper-parameters ──────────────────────────────────────────────────────────
|
# ── Hyper-parameters ──────────────────────────────────────────────────────────
|
||||||
TEXT = "123456789_Call_me_Ishmael._Some_years_ago" # the character sequence to learn (matches diagram example)
|
TEXT = "CHAPTER 1 LOOMINGS CALL ME ISHMAEL SOME YEARS AGO NEVER MIND HOW LONG PRECISELY HAVING LITTLE OR NO" # the character sequence to learn (matches diagram example)
|
||||||
WIN = 2 # sliding-window width (= N in the diagram)
|
WIN = 2 # sliding-window width (= N in the diagram)
|
||||||
STRIDE = 1 # sliding-window step size
|
|
||||||
UNITS = 5
|
UNITS = 5
|
||||||
H_SIZE = 128 # hidden units per RBM cell
|
H_SIZE = 128 # hidden units per RBM cell
|
||||||
NUM_EPOCHS = 1000
|
NUM_EPOCHS = 1000
|
||||||
NUM_ITERATIONS = 1
|
|
||||||
|
|
||||||
TRAIN_PARAMS = TrainingParams(
|
TRAIN_PARAMS = TrainingParams(
|
||||||
learning_rate = 0.1,
|
learning_rate = 0.25,
|
||||||
momentum = 0.5,
|
momentum = 0.5,
|
||||||
num_epochs = NUM_EPOCHS,
|
num_epochs = NUM_EPOCHS,
|
||||||
do_rao_blackwell = False,
|
do_rao_blackwell = True,
|
||||||
num_gibbs_samples= 1
|
num_gibbs_samples= 1,
|
||||||
|
do_gibbs_sample_hidden=True
|
||||||
)
|
)
|
||||||
#WIN=3
|
#WIN=3
|
||||||
#STRIDE=1
|
|
||||||
#UNIT=3
|
#UNIT=3
|
||||||
#WIN | |
|
#WIN | |
|
||||||
#U0: "JAY IS COOL"
|
#U0: "JAY IS COOL"
|
||||||
@@ -168,14 +166,19 @@ if __name__ == "__main__":
|
|||||||
model.save()
|
model.save()
|
||||||
|
|
||||||
# test the model
|
# test the model
|
||||||
seed_str = '1234'
|
seed_str = 'CHAP'
|
||||||
state = SPACE*UNITS
|
state = SPACE*UNITS
|
||||||
|
|
||||||
|
result = seed_str
|
||||||
|
ch = SPACE
|
||||||
# Prime
|
# Prime
|
||||||
for s in seed_str:
|
for s in seed_str:
|
||||||
state, ch = model.forward_step(s, state)
|
state, ch = model.forward_step(s, state)
|
||||||
print(f'Predict: {ch}')
|
print(f'Prime: {ch}')
|
||||||
|
|
||||||
state, ch = model.forward_step('_', state)
|
for i in range(len(TEXT)):
|
||||||
|
state, ch = model.forward_step(ch, state)
|
||||||
print(f'Predict: {ch}')
|
print(f'Predict: {ch}')
|
||||||
|
result += ch
|
||||||
|
|
||||||
|
print(result)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from rbm.matrix import Mat, np
|
from rbm.matrix import Mat, np
|
||||||
|
|
||||||
SPACE='_'
|
SPACE=' '
|
||||||
VOCAB = SPACE + '-.!?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
VOCAB = SPACE + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
||||||
_CH2IDX = {ch: i for i, ch in enumerate(VOCAB)}
|
_CH2IDX = {ch: i for i, ch in enumerate(VOCAB)}
|
||||||
|
|
||||||
def clamp(vec: Mat, axis=0):
|
def clamp(vec: Mat, axis=0):
|
||||||
|
|||||||
Reference in New Issue
Block a user