Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlbertXiebnu/7a1e2521d5963550ff3c381474d4034b to your computer and use it in GitHub Desktop.
Save AlbertXiebnu/7a1e2521d5963550ff3c381474d4034b to your computer and use it in GitHub Desktop.
## from github discuss
ngram_filters = [3, 4, 5, 6, 7, 8]
conv_filters = []
for n_gram in ngram_filters:
conv_filters.append(Sequential())
conv_filters[-1].add(Convolution2D(nb_feature_maps, 1, n_gram, wv_sz))
conv_filters[-1].add(MaxPooling2D(poolsize=(nb_tokens - n_gram + 1, 1)))
conv_filters[-1].add(Flatten())
model = Sequential()
model.add(Merge(conv_filters, mode='concat'))
model.add(Dropout(0.5))
model.add(Dense(nb_feature_maps * len(ngram_filters), 1))
model.add(Activation('sigmoid'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment