Пример #1
0
### END SETTINGS ###

# init

if not os.path.exists(work_dir):
    os.makedirs(work_dir)

with open(corpus_file) as f:
    sents = [[twp.split('|')[0].lower() for twp in line.split()] for line in f]

embeddings = helper.char_embeddings(sents)

if timestamp and start_epoch and start_iteration:
    errors = helper.load_errors(
        '%s-%d-%d.errors' % (timestamp, start_epoch, start_iteration),
        work_dir)
    load_weights = '%s-%d-%d.weights' % (timestamp, start_epoch,
                                         start_iteration)
    print('init previous states...')
    print('timestamp: ', timestamp)
    print('start_epoch: ', start_epoch)
    print('start_iteration: ', start_iteration)
else:
    errors = []
    start_epoch = 0
    start_iteration = 0
    timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    load_weights = None
    print('init new states...')
    print('timestamp: ', timestamp)
Пример #2
0
confusion_set = ['than', 'then']

### END SETTINGS ###
       
# init

if not os.path.exists(work_dir):
    os.makedirs(work_dir)
    
with open(corpus_file) as f:
    sents = [[twp.split('|')[0].lower() for twp in line.split()] for line in f]
    
embeddings = helper.char_embeddings(sents)

if timestamp and start_epoch and start_iteration:
    errors = helper.load_errors('%s-%d-%d.errors' % (timestamp, start_epoch, start_iteration), work_dir)
    load_weights = '%s-%d-%d.weights' % (timestamp, start_epoch, start_iteration)
    print('init previous states...')
    print('timestamp: ', timestamp)
    print('start_epoch: ', start_epoch)
    print('start_iteration: ', start_iteration)
else:
    errors = []
    start_epoch = 0
    start_iteration = 0
    timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    load_weights = None
    print('init new states...')
    print('timestamp: ', timestamp)
print()
Пример #3
0
model.add(Dropout(0.5))
model.add(Dense(hidden_layer_size, 1))
model.add(Activation('sigmoid'))

# compile model

print('compile model...')
print()
model.compile(loss='binary_crossentropy', 
              optimizer='rmsprop', 
              class_mode="binary")

# load previous states or continue with random initialization
			  
if timestamp and start_epoch:
    errors = helper.load_errors('%s-%d.errors' % (timestamp, start_epoch), work_dir)
    model.load_weights(os.path.join(work_dir, '%s-%d.weights' % (timestamp, start_epoch)))
    print('init previous states...')
    print('timestamp: ', timestamp)
    print('start_epoch: ', start_epoch)
else:
    errors = []
    start_epoch = 0
    timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    print('init new states...')
    print('timestamp: ', timestamp)
print()

# start training

print('start training...')