code: def load_sent_encoder(
      model_dict,
      expand_vocab=False,
      orig_vocab=None,
      w2v_vocab=None,
      w2v_path=None,
      use_recur_last=False,
  ):
      """
      Custom function to load the model saved from skip-thought vector training
      and reconstruct another model just using the LUT and encoding layer for
      transfering sentence representations.
  
      Arguments:
          model_dict: saved s2v model dict
          expand_vocab: Bool to indicate if w2v vocab expansion should be attempted
          orig_vocab: If using expand_vocab, original vocabulary dict is needed for expansion
          w2v_vocab: If using expand_vocab, w2v vocab dict
          w2v_path: Path to trained w2v binary (GoogleNews)
          use_recur_last: If True a RecurrentLast layer is used as the final layer, if False
                          a RecurrentSum layer is used as the last layer of the returned model.
      """
  
      embed_dim = model_dict["model"]["config"]["embed_dim"]
      model_train = Model(model_dict)
  
      # RecurrentLast should be used for semantic similarity evaluation
      if use_recur_last:
          last_layer = RecurrentLast()
      else:
          last_layer = RecurrentSum()
  
      if expand_vocab:
          assert orig_vocab and w2v_vocab, (
              "All vocabs and w2v_path "
              + "need to be specified when using expand_vocab"
          )
  
          neon_logger.display("Computing vocab expansion regression...")
          # Build inverse word dictionary (word -> index)
          word_idict = dict()
          for kk, vv in orig_vocab.items():
              # Add 2 to the index to allow for padding and oov tokens as 0 and 1
              word_idict[vv + 2] = kk
          word_idict[0] = ""
          word_idict[1] = "UNK"
  
          # Create dictionary of word -> vec
          orig_word_vecs = get_embeddings(
              model_train.layers.layer_dict["lookupTable"], word_idict
          )
  
          # Load GooleNews w2v weights
          w2v_W, w2v_dim, _ = get_google_word2vec_W(w2v_path, w2v_vocab)
  
          # Compute the expanded vocab lookup table from a linear mapping of
          # words2vec into RNN word space
          init_embed = compute_vocab_expansion(
              orig_word_vecs, w2v_W, w2v_vocab, word_idict
          )
  
          init_embed_dev = model_train.be.array(init_embed)
          w2v_vocab_size = len(w2v_vocab)
  
          table = LookupTable(
              vocab_size=w2v_vocab_size,
              embedding_dim=embed_dim,
              init=init_embed_dev,
              pad_idx=0,
          )
  
          model = Model(
              layers=[
                  table,
                  model_train.layers.layer_dict["encoder"],
                  last_layer,
              ]
          )
  
      else:
          model = Model(
              layers=[
                  model_train.layers.layer_dict["lookupTable"],
                  model_train.layers.layer_dict["encoder"],
                  last_layer,
              ]
          )
      return model
  
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 9 for calling a global function with example usage: load_sent_encoder(model_dict, expand_vocab, orig_vocab, w2v_vocab, w2v_path, use_recur_last) and returns: model