def __init__(self, dict_size: int, embedding_size: int, hidden_units: int): self.layers = [layer.Embedding(dict_size, embedding_size, 'l0-Embedding'), layer.Recursive(embedding_size, hidden_units, 'l1-R'), layer.Tanh(hidden_units, 'l2-Tanh'), layer.Linear(hidden_units, dict_size, 'l3-L'), layer.Softmax(dict_size, 'l4-Softmax')] self.h: list = None return
def __init__(self, dict_size: int, embedding_size: int, hidden_units: int): self.layers = [layer.Embedding(dict_size, embedding_size, 'l0'), layer.Linear(embedding_size, hidden_units, 'l1-0'), layer.Linear(embedding_size, hidden_units, 'l1-1'), layer.Linear(embedding_size, hidden_units, 'l1-2'), layer.Linear(hidden_units, dict_size, 'l2'), layer.Softmax(dict_size, 'l3')] self.h: list = None return
def __init__(self, dict_size: int, embedding_size: int, hidden_units: int): self.layers = [layer.Embedding(dict_size, embedding_size, 'l0'), # layer 0 layer.Linear(embedding_size, hidden_units, 'l1-0'), # layer 1 layer.Linear(embedding_size, hidden_units, 'l1-1'), # layer 2 layer.Linear(embedding_size, hidden_units, 'l1-2'), # layer 3 layer.Tanh(hidden_units, 'l2'), # layer 4 layer.Linear(hidden_units, dict_size, 'l3'), # layer 5 layer.Softmax(dict_size, 'l4')] # layer 6 self.h: list = None return
print('Settings 3') train_settings = TrainSettings(learning_rate=0.005, batch_size=16, momentum=0.0, plot_callback=cb.plot_callback, loss_callback=cb.loss_callback, filename='script-1-1-3', epoch=200, prefix='e16') layers = [ layer.Linear(784, 100), #layer.BN(100, 100), layer.Sigmoid(100), layer.Linear(100, 10), layer.Softmax(10) ] mynn = network.MLP(layers) utf.cross_train(mynn, data_store_train, data_store_valid, train_settings) print('Settings 4') train_settings = TrainSettings(learning_rate=0.01, batch_size=16, momentum=0.0, plot_callback=cb.plot_callback, loss_callback=cb.loss_callback, filename='script-1-1-4', epoch=300, prefix='e16')
import os # format of data # disitstrain.txt contains 3000 lines, each line 785 numbers, comma delimited full_path = os.path.realpath(__file__) path, filename = os.path.split(full_path) data_filepath = '../data' data_train_filename = 'digitstrain.txt' data_valid_filename = 'digitsvalid.txt' data_test_filename = 'digitstest.txt' data_train_filepath = os.path.join(path, data_filepath, data_train_filename) data_valid_filepath = os.path.join(path, data_filepath, data_valid_filename) data_test_filepath = os.path.join(path, data_filepath, data_test_filename) print('start initializing...') network.init_nn(random_seed=1099) x_train, y_train = load_data.load_from_path(data_train_filepath) x_valid, y_valid = load_data.load_from_path(data_valid_filepath) layers = [ layer.Linear(784, 100), layer.Tanh(100, 100), layer.Linear(100, 100), layer.Softmax(10, 10) ] myNN = NN(layers, learning_rate=0.1, regularizer=0.0001, momentum=0.9) myNN.train(x_train, y_train, x_valid, y_valid, epoch=300, batch_size=32)