if len(saved_weights) == 0: print("network hasn't been trained!") sys.exit() else: test_sample_num = 0 test_sentences = pickle.load(open('./pickle-dumps/sentences_test', 'rb')) test_roots = pickle.load(open('./pickle-dumps/rootwords_test', 'rb')) test_features = pickle.load(open('./pickle-dumps/features_test', 'rb')) y1, y2, y3, y4, y5, y6, y7, y8 = load_data_for_features(test_features) features = [y1, y2, y3, y4, y5, y7, y8] complete_list, X_test, X_vcab_len, X_wrd_to_ix, X_ix_to_wrd, y_test, y_vcab_len, y_wrd_to_ix, y_ix_to_wrd, \ X_left1, X_left2, X_left3, X_left4, X_right1, X_right2, X_right3, X_right4, X_phonetic_features = \ load_data_for_seq2seq(test_sentences, test_roots, X_test_phonetics, features, labels, test=True, context4=True) X_orig, y_orig, y1, y2, y3, y4, y5, y7, y8 = complete_list to_be_padded = [ X_test, X_left1, X_right1, X_left2, X_right2, X_left3, X_right3, X_left4, X_right4, y_test ] X_test, X_left1, X_right1, X_left2, X_right2, X_left3, X_right3, X_left4, X_right4, y_test= \ [pad_sequences(i, maxlen=X_max_len, dtype='int32', padding='post') for i in to_be_padded] y_test_seq = process_data(y_test, X_max_len, y_word_to_ix) y1, n1, y2, n2, y3, n3, y4, n4, y5, n5, y7, n7, y8, n8, enc, lab = process_features( y1, y2, y3, y4, y5, y7, y8, n, enc) # pass previous encoders as args
model.compile(optimizer=Adadelta(epsilon=1e-06), loss='categorical_crossentropy', metrics=['accuracy'], loss_weights=[1., 1., 1., 1., 1., 1., 1.]) return model sentences = pickle.load(open('./pickle-dumps/sentences_intra', 'rb')) rootwords = pickle.load(open('./pickle-dumps/rootwords_intra', 'rb')) features = pickle.load(open('./pickle-dumps/features_intra', 'rb')) n_phonetics, X_train_phonetics, X_test_phonetics, X_val_phonetics, _, _, _ = returnTrainTestSets() # we keep X_idx2word and y_idx2word the same # X_left & X_right = X shifted to one and two positions left and right for context2 X, X_vocab_len, X_word_to_ix, X_ix_to_word, y, y_vocab_len, y_word_to_ix, y_ix_to_word, X_left1, X_left2, X_left3, X_left4, \ X_right1, X_right2, X_right3, X_right4 = load_data_for_seq2seq(sentences, rootwords, test=False, context4=True) y1, y2, y3, y4, y5, y6, y7, y8 = load_data_for_features(features) y1, n1, y2, n2, y3, n3, y4, n4, y5, n5, y7, n7, y8, n8, enc, labels = process_features(y1, y2, y3, y4, y5, y7, y8) n = [n1, n2, n3, n4, n5, n7, n8] X_max = max([len(word) for word in X]) y_max = max([len(word) for word in y]) X_max_len = max(X_max, y_max) print("Zero padding .. ") X = pad_sequences(X, maxlen= X_max_len, dtype = 'int32', padding='post') X_left1 = pad_sequences(X_left1, maxlen = X_max_len, dtype='int32', padding='post') X_left2 = pad_sequences(X_left2, maxlen = X_max_len, dtype='int32', padding='post')
model = Model(input=all_inputs, output=all_outputs) return model sentences = pickle.load(open('./pickle_dumps/train_words', 'rb')) rootwords = pickle.load(open('./pickle_dumps/train_roots', 'rb')) features = pickle.load(open('./pickle_dumps/train_features', 'rb')) n_phonetics, X_train_phonetics, X_test_phonetics, X_val_phonetics = returnTrainTestSets( ) # we keep X_idx2word and y_idx2word the same # X_left & X_right = X shifted to one and two positions left and right for context2 X, X_vocab_len, X_word_to_ix, X_ix_to_word, y, y_vocab_len, y_word_to_ix, y_ix_to_word, X_left1, X_left2, X_left3, X_left4, \ X_right1, X_right2, X_right3, X_right4 = load_data_for_seq2seq(sentences, rootwords, test=False, context4=True) y1, y2, y3, y4, y5, y6 = load_data_for_features(features) y1, n1, y2, n2, y3, n3, y4, n4, y5, n5, y6, n6, enc, labels = process_features( y1, y2, y3, y4, y5, y6) n = [n1, n2, n3, n4, n5, n6] # X_max = max([len(word) for word in X]) # y_max = max([len(word) for word in y]) # X_max_len = max(X_max, y_max) # print(X_max_len) # print(X_vocab_len)