code: def get_google_word2vec_W(fname, vocab, index_from=2):
      """
      Extract the embedding matrix from the given word2vec binary file and use this
      to initalize a new embedding matrix for words found in vocab.
  
      Conventions are to save indices for pad, oov, etc.:
      index 0: pad
      index 1: oov (or <unk>)
      Often cases, the <eos> has already been in the preprocessed data, so no need
      to save an index for <eos>
      """
      f = open(fname, "rb")
      header = f.readline()
      orig_w2v_size, embedding_dim = map(int, header.split())
      binary_len = np.dtype("float32").itemsize * embedding_dim
      vocab_size = len(vocab) + index_from
      W = np.zeros((vocab_size, embedding_dim))
  
      found_words_idx = defaultdict(int)
      found_words = defaultdict(int)
  
      for i in range(vocab_size):
          word = []
          while True:
              ch = f.read(1)
              if ch == b" ":
                  word = (b"".join(word)).decode("utf-8")
                  break
              if ch != b"\n":
                  word.append(ch)
          if word in vocab:
              wrd_id = vocab[word] + index_from
              if wrd_id < vocab_size:
                  W[wrd_id] = np.fromstring(
                      f.read(binary_len), dtype="float32"
                  )
                  found_words_idx[wrd_id] += 1
                  found_words[word] += 1
          else:
              f.read(binary_len)
  
      cnt = 0
      for wrd_id in range(vocab_size):
          if wrd_id not in found_words_idx:
              cnt += 1
              W[wrd_id] = np.random.uniform(-1.0, 1.0, embedding_dim)
  
      unfound_words = list()
      for wrd in vocab:
          if wrd not in found_words:
              unfound_words += [wrd]
  
      assert cnt + len(found_words_idx) == vocab_size
  
      f.close()
  
      return W, embedding_dim, found_words
  
imports: import os
  import numpy
  from collections import defaultdict, OrderedDict
  from neon.layers import LookupTable, RecurrentSum, RecurrentLast, Linear, Bias, GeneralizedCost
  from neon.initializers import Gaussian, Constant
  from neon.data import ArrayIterator
  from neon.data.text_preprocessing import clean_string
  from neon.optimizers import GradientDescentMomentum
  from neon.transforms import SumSquared
  from neon.callbacks.callbacks import Callbacks
  from neon.models import Model
  from neon.util.persist import load_obj, save_obj
  from neon import logger
label_desc: Use image node_id 3 for calling a global function with example usage: get_google_word2vec_W(fname, vocab, index_from) and returns: W,  embedding_dim,  found_words