lm1b/model/model_nodes.py
def attach_inference_nodes(input_seqs, hparams=None):
  """
  Predict next word for each sequence / timestep in input_seqs
  :param input_seqs: tensor of character encoded words
  :param hparams:
  :return: dict of inference nodes
  """
  with tf.variable_scope(CHAR_EMBEDDING_SCOPE):
    word_embeddings = char_embedding_nodes.attach_char_embedding_nodes(input_seqs, num_shards=NUM_SHARDS,
                                                                       hparams=hparams)
    word_embeddings = tf.reshape(word_embeddings, (-1, hparams.word_embedding_size))

  cell_out = word_embeddings
  cell_state_all_layers = []
  cell_out_all_layers = []
  for layer_num in range(0, 2):
    with tf.variable_scope(LSTM_SCOPE_PREFIX + str(layer_num)):
      cell_out, cell_state = _attach_cached_lstm_nodes(cell_out, hparams=hparams)
      cell_state_all_layers.append(cell_state)
      cell_out_all_layers.append(cell_out)

  lstm_outputs = tf.reshape(cell_out, shape=(-1, hparams.word_embedding_size))

  with tf.variable_scope(SOFTMAX_SCOPE):
    logits, softmax = _attach_projection_nodes(lstm_outputs, hparams=hparams)

  return {
    "word_embeddings": word_embeddings,
    "lstm_outputs": lstm_outputs,
    "lstm_state": cell_state,
    "logits": logits,
    "softmax": softmax,
    "cell_state_all_layers": cell_state_all_layers,
    "cell_out_all_layers": cell_out_all_layers
  }

  Predict next word for each sequence / timestep in input_seqs
  :param input_seqs: tensor of character encoded words
  :param hparams:
  :return: dict of inference nodes
  
Predict next word for each sequence / timestep in input_seqs
Predict next word for each sequence / timestep in input_seqs
def attach_inference_nodes(input_seqs, hparams=None):
  with tf.variable_scope(CHAR_EMBEDDING_SCOPE):
    word_embeddings = char_embedding_nodes.attach_char_embedding_nodes(input_seqs, num_shards=NUM_SHARDS,
                                                                       hparams=hparams)
    word_embeddings = tf.reshape(word_embeddings, (-1, hparams.word_embedding_size))
  cell_out = word_embeddings
  cell_state_all_layers = []
  cell_out_all_layers = []
  for layer_num in range(0, 2):
    with tf.variable_scope(LSTM_SCOPE_PREFIX + str(layer_num)):
      cell_out, cell_state = _attach_cached_lstm_nodes(cell_out, hparams=hparams)
      cell_state_all_layers.append(cell_state)
      cell_out_all_layers.append(cell_out)
  lstm_outputs = tf.reshape(cell_out, shape=(-1, hparams.word_embedding_size))
  with tf.variable_scope(SOFTMAX_SCOPE):
    logits, softmax = _attach_projection_nodes(lstm_outputs, hparams=hparams)
  return {
    "word_embeddings": word_embeddings,
    "lstm_outputs": lstm_outputs,
    "lstm_state": cell_state,
    "logits": logits,
    "softmax": softmax,
    "cell_state_all_layers": cell_state_all_layers,
    "cell_out_all_layers": cell_out_all_layers
  }
def attach_inference_nodes ( input_seqs , hparams = None ) : with tf . variable_scope ( CHAR_EMBEDDING_SCOPE ) : word_embeddings = char_embedding_nodes . attach_char_embedding_nodes ( input_seqs , num_shards = NUM_SHARDS , hparams = hparams ) word_embeddings = tf . reshape ( word_embeddings , ( - 1 , hparams . word_embedding_size ) ) cell_out = word_embeddings cell_state_all_layers = [ ] cell_out_all_layers = [ ] for layer_num in range ( 0 , 2 ) : with tf . variable_scope ( LSTM_SCOPE_PREFIX + str ( layer_num ) ) : cell_out , cell_state = _attach_cached_lstm_nodes ( cell_out , hparams = hparams ) cell_state_all_layers . append ( cell_state ) cell_out_all_layers . append ( cell_out ) lstm_outputs = tf . reshape ( cell_out , shape = ( - 1 , hparams . word_embedding_size ) ) with tf . variable_scope ( SOFTMAX_SCOPE ) : logits , softmax = _attach_projection_nodes ( lstm_outputs , hparams = hparams ) return { "word_embeddings" : word_embeddings , "lstm_outputs" : lstm_outputs , "lstm_state" : cell_state , "logits" : logits , "softmax" : softmax , "cell_state_all_layers" : cell_state_all_layers , "cell_out_all_layers" : cell_out_all_layers }
Predict next word for each sequence / timestep in input_seqs
Predict next word for each sequence / timestep in input_seqs
"""
  Predict next word for each sequence / timestep in input_seqs
  :param input_seqs: tensor of character encoded words
  :param hparams:
  :return: dict of inference nodes
  """
dict of inference nodes
dict of inference nodes
input_seqs
tensor of character encoded words
tensor of character encoded words
hparams
None