Skip to content

Commit 89e3138

Browse files
author
xuming06
committed
update keras with fasttext network embeding. xuming 20180226
1 parent 4fcc039 commit 89e3138

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

07keras/09fasttext_multi_classification.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def add_ngram(sequences, token_indice, ngram_range=2):
8282
max_features = 20000
8383
max_len = 400
8484
batch_size = 32
85-
embedding_dims = 200
85+
embedding_dims = 50
8686
epochs = 10
8787
SAVE_MODEL_PATH = 'fasttext_multi_classification_model.h5'
8888
pwd_path = os.path.abspath(os.path.dirname(__file__))
@@ -94,8 +94,8 @@ def add_ngram(sequences, token_indice, ngram_range=2):
9494
print('loading data...')
9595
x_train, y_train = get_corpus(train_data_dir)
9696
x_test, y_test = get_corpus(test_data_dir)
97-
y_train = keras.utils.to_categorical(y_train)
98-
y_test = keras.utils.to_categorical(y_test)
97+
y_train = keras.utils.to_categorical(y_train, num_classes=num_classes)
98+
y_test = keras.utils.to_categorical(y_test, num_classes=num_classes)
9999

100100
sent_maxlen = max(map(len, (x for x in x_train + x_test)))
101101
print('-')
@@ -157,8 +157,8 @@ def add_ngram(sequences, token_indice, ngram_range=2):
157157
model.add(Embedding(max_features, embedding_dims, input_length=max_len))
158158
# pooling the embedding
159159
model.add(GlobalAveragePooling1D())
160-
# output
161-
model.add(Dense(3, activation='softmax'))
160+
# output multi classification of num_classes
161+
model.add(Dense(num_classes, activation='softmax'))
162162

163163
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
164164
model.fit(x_train, y_train,

0 commit comments

Comments
 (0)