multilabel, load_previous = sys.argv[1:] print multilabel, load_previous if multilabel == 'multi': multilabel = True else: multilabel = False if load_previous == 'load': load_previous = True else: load_previous = False train_set = Corpus(DATA_DIR + TRAIN_FILE, DATA_DIR + TRAIN_LABS) X_train, X_val, y_train, y_val, nb_classes, word_index = load_data( train_set, multilabel) if load_previous: model = load_model(STAMP, multilabel) else: model = build_model(nb_classes, word_index, EMBEDDING_DIM, MAX_SEQUENCE_LENGTH, STAMP, multilabel) if multilabel: monitor_metric = 'val_f1_score' else: monitor_metric = 'val_loss'
return model if __name__ == '__main__': epochs = 2000 max_len = 40 batch_size = 512 data_sample = 0.5 skip = 3 STAMP = 'language_model' data_set = Corpus(train_data,val_data, max_len=max_len, batch_size=batch_size, data_sample=data_sample, skip=skip) with open('char2id.json', 'w') as fp: json.dump(data_set.char2id, fp) with open('id2char.json', 'w') as fp: json.dump(data_set.id2char, fp) model = build_model(max_len,data_set.vocab_size) print(STAMP) model_json = model.to_json() with open(STAMP + ".json", "w") as json_file: json_file.write(model_json)