code: def bidirectional_LSTM(
      inputs,
      hidden_state_dimension,
      initializer,
      sequence_length=None,
      output_sequence=True,
  ):
      """ """
      with tf.variable_scope("bidirectional_LSTM"):
          if sequence_length == None:
              batch_size = 1
              sequence_length = tf.shape(inputs)[1]
              sequence_length = tf.expand_dims(
                  sequence_length, axis=0, name="sequence_length"
              )
          else:
              batch_size = tf.shape(sequence_length)[0]
  
          lstm_cell = {}
          initial_state = {}
  
          for direction in ["forward", "backward"]:
              with tf.variable_scope(direction):
                  # LSTM cell
                  lstm_cell[
                      direction
                  ] = tf.contrib.rnn.CoupledInputForgetGateLSTMCell(
                      hidden_state_dimension,
                      forget_bias=1.0,
                      initializer=initializer,
                      state_is_tuple=True,
                  )
                  # initial state: http://stackoverflow.com/questions/38441589/tensorflow-rnn-initial-state
                  initial_cell_state = tf.get_variable(
                      "initial_cell_state",
                      shape=[1, hidden_state_dimension],
                      dtype=tf.float32,
                      initializer=initializer,
                  )
                  initial_output_state = tf.get_variable(
                      "initial_output_state",
                      shape=[1, hidden_state_dimension],
                      dtype=tf.float32,
                      initializer=initializer,
                  )
                  c_states = tf.tile(
                      initial_cell_state, tf.stack([batch_size, 1])
                  )
                  h_states = tf.tile(
                      initial_output_state, tf.stack([batch_size, 1])
                  )
                  initial_state[
                      direction
                  ] = tf.contrib.rnn.LSTMStateTuple(c_states, h_states)
  
          # sequence_length must be provided for tf.nn.bidirectional_dynamic_rnn due to internal bug
          outputs, final_states = tf.nn.bidirectional_dynamic_rnn(
              lstm_cell["forward"],
              lstm_cell["backward"],
              inputs=inputs,
              dtype=tf.float32,
              sequence_length=sequence_length,
              initial_state_fw=initial_state["forward"],
              initial_state_bw=initial_state["backward"],
          )
  
          if output_sequence == True:
              outputs_forward, outputs_backward = outputs
              output = tf.concat(
                  [outputs_forward, outputs_backward],
                  axis=2,
                  name="output_sequence",
              )
          else:
              # # max pooling
              # outputs_forward, outputs_backward = outputs
              # output = tf.concat([outputs_forward, outputs_backward], axis=2, name='output_sequence')
              # output = tf.reduce_max(output, axis=1, name='output')
              # # last pooling
              final_states_forward, final_states_backward = final_states
              output = tf.concat(
                  [final_states_forward[1], final_states_backward[1]],
                  axis=1,
                  name="output",
              )
  
      return output
  
file_path: NeuroNER/neuroner/entity_lstm.py
imports: import os
  import pickle
  import re
  import time
  import tensorflow
  from neuroner import utils
  from neuroner import utils_tf
  from neuroner import utils_nlp
label_desc: Use image node_id 1 for calling a global function with example usage: bidirectional_LSTM(inputs, hidden_state_dimension, initializer, sequence_length, output_sequence) and returns: output