Skip to content

Commit

Permalink
Final version of the testings
Browse files Browse the repository at this point in the history
  • Loading branch information
frosinastojanovska committed May 4, 2018
1 parent 23412fe commit 3df4a79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions emotion_detection_deep_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def train_semantic_sentiment_merged_model(split, model_type):
train_y = k.utils.to_categorical(train_y, n_classes)

model1 = create_model(model_type, train_y.shape[1], shape1, embeddings_matrix, 150)
model1.load_weights('models/emotion_bi_lstm_semantic_model-glove-emoji.h5')
model1.load_weights('models/emotion_bi_lstm_semantic_model-w2-emoji.h5')
model1.pop()
model2 = create_model(model_type, train_y.shape[1], shape2, lexicon_matrix, 150)
model2.load_weights('models/emotion_bi_lstm_semantic_lexicon_model.h5')
Expand Down Expand Up @@ -408,10 +408,10 @@ def accuracy_top_n(y_true, y_pred, n=3):
# train_semantic_models(30000, 'bi_lstm')
# train_semantic_lexicon_model(30000, 'bi_lstm')
# transfer_learning(30000, 'bi_lstm')
# test_semantic_model('bi_lstm', 'models/emotion_bi_lstm_semantic_model-glove-emoji.h5', 30000, 'emotion_bi_lstm.txt', False)
# test_semantic_model('bi_lstm', 'models/emotion_bi_lstm_semantic_model-w2-emoji.h5', 30000, 'emotion_bi_lstm.txt', False)
# test_semantic_model('lstm1', 'models/emotion_transfer_lstm1_semantic_model.h5', 30000,
# 'emotion_transfer_lstm1.txt', True)
# train_semantic_sentiment_models(30000, 'cnn_bi_lstm')
# test_semantic_sentiment_model('cnn_bi_lstm', 'models/emotion_cnn_bi_lstm_semantic_sentiment_model-19-2.08-old.h5', 30000, 'emotion_cnn_bi_lstm_sentiment.txt')
train_semantic_sentiment_merged_model(30000, 'bi_lstm')
# test_semantic_sentiment_merged_model('models/emotion_merged_semantic_sentiment_model.h5', 30000, 'emotion_merged_lstm_sentiment.txt')
# train_semantic_sentiment_merged_model(30000, 'bi_lstm')
test_semantic_sentiment_merged_model('models/emotion_merged_semantic_sentiment_model-w2v-emoji.h5', 30000, 'emotion_merged_lstm_sentiment.txt')
12 changes: 6 additions & 6 deletions multi_class_emotion_detection_deep_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ def load_sentiment_data():

print('Lexicon encoding...')
df_train, lexicon_matrix = get_lexicon_values(df_train, lexicon_type=2,
lexicon_name='w2v-dp-BCC-Lex.csv')
lexicon_name='w2v-dp-CC-Lex.csv')
lexicon_features_train = pad_sequences(df_train.lexicon.values.tolist(), maxlen=150, padding='post')
df_val, lexicon_matrix = get_lexicon_values(df_val, lexicon_type=2,
lexicon_name='w2v-dp-BCC-Lex.csv')
lexicon_name='w2v-dp-CC-Lex.csv')
lexicon_features_val = pad_sequences(df_val.lexicon.values.tolist(), maxlen=150, padding='post')
df_test, lexicon_matrix = get_lexicon_values(df_test, lexicon_type=2,
lexicon_name='w2v-dp-BCC-Lex.csv')
lexicon_name='w2v-dp-CC-Lex.csv')
lexicon_features_test = pad_sequences(df_test.lexicon.values.tolist(), maxlen=150, padding='post')
np.save('data_multi_class/train_lexicon', lexicon_features_train)
np.save('data_multi_class/val_lexicon', lexicon_features_val)
Expand Down Expand Up @@ -232,7 +232,7 @@ def train_semantic_sentiment_merged_model():
shape2 = train_X2[0].shape

model1 = cnn_bidirectional_lstm_model(train_y.shape[1], shape1, embedding_matrix, 150)
model1.load_weights('models/multi_emotion_semantic_model-glove-emoji.h5')
model1.load_weights('models/multi_emotion_semantic_model-w2v-emoji.h5')
model1.pop()
model2 = cnn_bidirectional_lstm_model(train_y.shape[1], shape2, lexicon_matrix, 150)
model2.load_weights('models/multi_emotion_semantic_lexicon_model.h5')
Expand Down Expand Up @@ -361,13 +361,13 @@ def test_semantic_sentiment_merged_model(weights_path, file_name):
# load_data()
# train_semantic_models()
# train_semantic_lexicon_model()
# test_semantic_model('models/multi_emotion_semantic_model-22-0.45-old.h5', 'scores/multi_emotion_semantic_model.txt')
# test_semantic_model('models/multi_emotion_semantic_model-w2v.h5', 'scores/multi_emotion_semantic_model.txt')
# transfer_learning_semantic_model()
# test_semantic_model('models/multi_emotion_semantic_model_transfer-67-0.45.h5',
# 'scores/multi_emotion_semantic_model_transfer.txt', True)
# train_semantic_sentiment_models()
# test_semantic_sentiment_model('models/multi_emotion_semantic_sentiment_model-11-0.45.h5',
# 'scores/multi_emotion_semantic_sentiment_model.txt')
# train_semantic_sentiment_merged_model()
test_semantic_sentiment_merged_model('models/multi_emotion_sentiment_semantic_merged_model-23-0.43.h5',
test_semantic_sentiment_merged_model('models/multi_emotion_sentiment_semantic_merged_model.h5',
'scores/multi_emotion_sentiment_semantic_merged_model.txt')
10 changes: 5 additions & 5 deletions preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ def get_word_encoding_and_embeddings(df, include_emojis=False):
# vocab_size=258917, emoji2vec_path='data/emoji2vec-400d.txt'

if include_emojis:
word2index, embedding_matrix = load_glove_embeddings('data/glove.twitter.27B.200d.txt',
embedding_dim=200, vocab_size=1193514,
emoji2vec=True, emoji2vec_path='data/emoji2vec-200d.txt',
word2index, embedding_matrix = load_glove_embeddings('data/w2v.twitter.edinburgh10M.400d.txt',
embedding_dim=400, vocab_size=258917,
emoji2vec=True, emoji2vec_path='data/emoji2vec-400d.txt',
num_emojis=1661)
else:
word2index, embedding_matrix = load_glove_embeddings('data/glove.twitter.27B.200d.txt',
embedding_dim=200, vocab_size=1193514,
word2index, embedding_matrix = load_glove_embeddings('data/w2v.twitter.edinburgh10M.400d.txt',
embedding_dim=400, vocab_size=258917,
emoji2vec=False)
df['encodings'] = df.apply(lambda x: [word2index[token.lower()] if token.lower() in word2index else 0
for sent in x.tokens for token in sent], axis=1)
Expand Down

0 comments on commit 3df4a79

Please sign in to comment.