This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gensim.models import KeyedVectors | |
# Load gensim word2vec | |
w2v_path = '<Gensim File Path>' | |
w2v = KeyedVectors.load_word2vec_format(w2v_path) | |
import io | |
# Vector file, `\t` seperated the vectors and `\n` seperate the words | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# required tensorflow 0.12 | |
# required gensim 0.13.3+ for new api model.wv.index2word or just use model.index2word | |
from gensim.models import Word2Vec | |
import tensorflow as tf | |
from tensorflow.contrib.tensorboard.plugins import projector | |
# loading your gensim | |
model = Word2Vec.load("YOUR-MODEL") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.models import Graph | |
from keras.layers import containers | |
from keras.layers.core import Dense, Dropout, Activation, Reshape, Flatten | |
from keras.layers.embeddings import Embedding | |
from keras.layers.convolutional import Convolution2D, MaxPooling2D | |
def ngram_cnn(n_vocab, max_length, embedding_size, ngram_filters=[2, 3, 4, 5], n_feature_maps=100, dropout=0.5, n_hidden=15): | |
"""A single-layer convolutional network using different n-gram filters. | |
Parameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.models import Graph | |
from keras.layers import containers | |
from keras.layers.core import Dense, Dropout, Activation, Reshape, Flatten | |
from keras.layers.embeddings import Embedding | |
from keras.layers.convolutional import Convolution2D, MaxPooling2D | |
def ngram_cnn(n_vocab, max_length, embedding_size, ngram_filters=[2, 3, 4, 5], n_feature_maps=100, dropout=0.5, n_hidden=15): | |
"""A single-layer convolutional network using different n-gram filters. | |
Parameters |