Initializing tensorflow Variable with an array larger than 2GB

前端 未结 3 991
无人及你
无人及你 2020-12-01 04:30

I am trying to initialize a tensorflow Variable with pre-trained word2vec embeddings.

I have the following code:

import ten         


        
3条回答
  •  青春惊慌失措
    2020-12-01 05:04

    try this:

    import tensorflow as tf
    from gensim import models
    
    model = models.KeyedVectors.load_word2vec_format('./GoogleNews-vectors-negative300.bin', binary=True)
    X = model.syn0
    
    embeddings = tf.Variable(tf.random_uniform(X.shape, minval=-0.1, maxval=0.1), trainable=False)
    
    sess = tf.Session()
    sess.run(tf.global_variables_initializer())
    embeddings.load(model.syn0, sess)
    

提交回复
热议问题