Example #1
0
print('Total addition questions:', len(questions))

print('Vectorization...')
convertor = CharacterDataEngine(engine.get_character_set(), maxlen=MAXLEN)
D_X = convertor.encode_dataset(questions, invert=INVERT)
D_y = convertor.encode_dataset(expected, maxlen=DIGITS + 1)

# Shuffle (X, y) in unison as the later parts of X will almost all be larger digits
indices = np.arange(len(D_y))
np.random.shuffle(indices)
D_X = D_X[indices]
D_y = D_y[indices]

# Explicitly set apart 10% for validation data that we never train over
split_at = len(D_X) - len(D_X) / 10
(D_X_train, D_X_val) = (slice_X(D_X, 0, split_at), slice_X(D_X, split_at))
(D_y_train, D_y_val) = (D_y[:split_at], D_y[split_at:])

print(D_X_train.shape)
print(D_y_train.shape)

import dlx.unit.core as U
import dlx.unit.recurrent as R
from dlx.model import Model

print('Build model...')
input_dim = convertor.get_dim()
output_dim = convertor.get_dim()
hidden_dim = HIDDEN_SIZE
input_length = MAXLEN
output_length = DIGITS + 1
Example #2
0
print('Total addition questions:', len(questions))

print('Vectorization...')
convertor = CharacterDataEngine(engine.get_character_set(), maxlen=MAXLEN)
D_X = convertor.encode_dataset(questions, invert=INVERT)
D_y = convertor.encode_dataset(expected, maxlen=DIGITS + 1)

# Shuffle (X, y) in unison as the later parts of X will almost all be larger digits
indices = np.arange(len(D_y))
np.random.shuffle(indices)
D_X = D_X[indices]
D_y = D_y[indices]

# Explicitly set apart 10% for validation data that we never train over
split_at = len(D_X) - len(D_X) / 10
(D_X_train, D_X_val) = (slice_X(D_X, 0, split_at), slice_X(D_X, split_at))
(D_y_train, D_y_val) = (D_y[:split_at], D_y[split_at:])

print(D_X_train.shape)
print(D_y_train.shape)


import dlx.unit.core as U
import dlx.unit.recurrent as R
from dlx.model import Model

print('Build model...')
input_dim = convertor.get_dim()
output_dim = convertor.get_dim()
hidden_dim = HIDDEN_SIZE
input_length = MAXLEN
                                maxlen=MAXLEN,
                                soldier=' ')
D_A = convertor.encode_dataset(As, invert=True, index=True)
D_B = convertor.encode_dataset(Bs, invert=True, index=True)
D_y = convertor.encode_dataset(expected, maxlen=MAXLEN, invert=True)

# Shuffle (X, y) in unison as the later parts of X will almost all be larger digits
indices = np.arange(len(D_y))
np.random.shuffle(indices)
D_A = D_A[indices]
D_B = D_B[indices]
D_y = D_y[indices]

# Explicitly set apart 10% for validation data that we never train over
split_at = len(D_A) - len(D_A) / 10
(D_A_train, D_A_val) = (slice_X(D_A, 0, split_at), slice_X(D_A, split_at))
(D_B_train, D_B_val) = (slice_X(D_B, 0, split_at), slice_X(D_B, split_at))
(D_y_train, D_y_val) = (D_y[:split_at], D_y[split_at:])

print(D_A_train.shape)
print(D_B_train.shape)
print(D_y_train.shape)

import dlx.unit.core as U
import dlx.unit.attention as A
from dlx.model import Model

print('Build model...')
input_dim = convertor.get_dim() + MAXLEN
output_dim = convertor.get_dim()
hidden_dim = HIDDEN_SIZE
print("Vectorization...")
convertor = CharacterDataEngine(engine.get_character_set(), maxlen=MAXLEN, soldier=" ")
D_A = convertor.encode_dataset(As, invert=True, index=True)
D_B = convertor.encode_dataset(Bs, invert=True, index=True)
D_y = convertor.encode_dataset(expected, maxlen=MAXLEN, invert=True)

# Shuffle (X, y) in unison as the later parts of X will almost all be larger digits
indices = np.arange(len(D_y))
np.random.shuffle(indices)
D_A = D_A[indices]
D_B = D_B[indices]
D_y = D_y[indices]

# Explicitly set apart 10% for validation data that we never train over
split_at = len(D_A) - len(D_A) / 10
(D_A_train, D_A_val) = (slice_X(D_A, 0, split_at), slice_X(D_A, split_at))
(D_B_train, D_B_val) = (slice_X(D_B, 0, split_at), slice_X(D_B, split_at))
(D_y_train, D_y_val) = (D_y[:split_at], D_y[split_at:])

print(D_A_train.shape)
print(D_B_train.shape)
print(D_y_train.shape)


import dlx.unit.core as U
import dlx.unit.attention as A
from dlx.model import Model

print("Build model...")
input_dim = convertor.get_dim() + MAXLEN
output_dim = convertor.get_dim()