|
30 | 30 | from keras.callbacks import ModelCheckpoint |
31 | 31 | from keras.wrappers.scikit_learn import KerasClassifier |
32 | 32 | from keras.models import Sequential |
33 | | -from keras.layers import Dense, Conv1D, MaxPooling1D, Flatten, Embedding, Reshape, Input, SimpleRNN, LSTM |
| 33 | +from keras.layers import Dense, Conv1D, Conv2D, MaxPooling1D, Flatten, Embedding, Reshape, Input, SimpleRNN, LSTM, InputLayer, GRU |
34 | 34 | import torch.nn as nn |
35 | 35 | import torch.nn.functional as F |
36 | 36 |
|
@@ -103,13 +103,19 @@ def transform(self, X): |
103 | 103 |
|
104 | 104 | X_train, X_val, Y_train, Y_val, Emb_train, Emb_val = train_test_split(np.asarray(list_of_sentences), np.asarray(list_of_labels), np.asarray(list_of_embeddings), test_size = 0.30, stratify = list_of_labels, random_state=42) |
105 | 105 |
|
106 | | -print(list_of_embeddings[1].size) |
| 106 | +print(Emb_train.shape[1:]) |
107 | 107 |
|
108 | 108 | def create_model(optimizer='adam', kernel_initializer='glorot_uniform', epochs = 5): |
109 | 109 | model = Sequential() |
110 | | - #model.add(Reshape((137, 1, 400), input_shape = (137, 400))) |
111 | | - #model.add(Conv1D(64, 1, activation='relu')) |
112 | | - model.add(Dense(list_of_embeddings[1].size, activation='relu',kernel_initializer='he_uniform', use_bias = False)) |
| 110 | + #model.add(InputLayer(input_shape=(153, 1, 300))) |
| 111 | + #print(model.output_shape) |
| 112 | + model.add(Reshape((1, list_of_embeddings[1].size), input_shape = Emb_train.shape[1:])) ##magical fucking stupid keras BS |
| 113 | + #print(model.output_shape) |
| 114 | + #model.add(Conv1D(filters=12, kernel_size=1, activation='relu')) ##works now |
| 115 | + model.add(GRU(list_of_embeddings[1].size)) |
| 116 | + #print(model.output_shape) |
| 117 | + #model.add(Flatten()) |
| 118 | + #model.add(Dense(list_of_embeddings[1].size, activation='relu',kernel_initializer='he_uniform', use_bias = False)) |
113 | 119 | #model.add(LSTM(list_of_embeddings[1].size, return_sequences = True,)) |
114 | 120 | model.add(Dense(len(np.unique(Y_val)),activation='softmax',kernel_initializer=kernel_initializer, use_bias = False)) |
115 | 121 | model.compile(loss='categorical_crossentropy',optimizer=optimizer, metrics=['accuracy']) |
|
0 commit comments