- reduced VOCAB
- changed test text
This commit is contained in:
2026-06-07 17:49:05 +02:00
parent 0febd4e6b6
commit 74371975ad
2 changed files with 16 additions and 13 deletions
+14 -11
View File
@@ -24,23 +24,21 @@ from rbm.train import train
from rbm.status import Status
# ── 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)
STRIDE = 1 # sliding-window step size
UNITS = 5
H_SIZE = 128 # hidden units per RBM cell
NUM_EPOCHS = 1000
NUM_ITERATIONS = 1
TRAIN_PARAMS = TrainingParams(
learning_rate = 0.1,
learning_rate = 0.25,
momentum = 0.5,
num_epochs = NUM_EPOCHS,
do_rao_blackwell = False,
num_gibbs_samples= 1
do_rao_blackwell = True,
num_gibbs_samples= 1,
do_gibbs_sample_hidden=True
)
#WIN=3
#STRIDE=1
#UNIT=3
#WIN | |
#U0: "JAY IS COOL"
@@ -168,14 +166,19 @@ if __name__ == "__main__":
model.save()
# test the model
seed_str = '1234'
seed_str = 'CHAP'
state = SPACE*UNITS
result = seed_str
ch = SPACE
# Prime
for s in seed_str:
state, ch = model.forward_step(s, state)
print(f'Prime: {ch}')
for i in range(len(TEXT)):
state, ch = model.forward_step(ch, state)
print(f'Predict: {ch}')
result += ch
state, ch = model.forward_step('_', state)
print(f'Predict: {ch}')
print(result)
+2 -2
View File
@@ -1,7 +1,7 @@
from rbm.matrix import Mat, np
SPACE='_'
VOCAB = SPACE + '-.!?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
SPACE=' '
VOCAB = SPACE + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
_CH2IDX = {ch: i for i, ch in enumerate(VOCAB)}
def clamp(vec: Mat, axis=0):