code: def add_bilstm_char_repr(self, nchars=101, dim=25, hidden=25):
      self._char_bilstm_added = True
  
      with tf.compat.v1.device("/gpu:{}".format(self.use_gpu_device)):
          with tf.compat.v1.variable_scope("char_repr_lstm"):
              # 1. Lookup for character embeddings
              char_range = math.sqrt(3 / dim)
              embeddings = tf.compat.v1.get_variable(
                  name="char_embeddings",
                  dtype=tf.float32,
                  shape=[nchars, dim],
                  initializer=tf.compat.v1.random_uniform_initializer(
                      -char_range, char_range
                  ),
                  use_resource=False,
              )
  
              # shape = (batch, sentence, word, char embeddings dim)
              char_embeddings = tf.nn.embedding_lookup(
                  params=embeddings, ids=self.char_ids
              )
              # char_embeddings = tf.nn.dropout(char_embeddings, self.dropout)
              s = tf.shape(input=char_embeddings)
  
              # shape = (batch x sentence, word, char embeddings dim)
              char_embeddings_seq = tf.reshape(
                  char_embeddings, shape=[-1, s[-2], dim]
              )
  
              # shape = (batch x sentence)
              word_lengths_seq = tf.reshape(
                  self.word_lengths, shape=[-1]
              )
  
              # 2. Add Bidirectional LSTM
              model = tf.keras.Sequential(
                  [
                      tf.keras.layers.Bidirectional(
                          layer=tf.keras.layers.LSTM(
                              hidden, return_sequences=False
                          ),
                          merge_mode="concat",
                      )
                  ]
              )
  
              inputs = char_embeddings_seq
              mask = tf.expand_dims(
                  tf.sequence_mask(word_lengths_seq, dtype=tf.float32),
                  axis=-1,
              )
  
              # shape = (batch x sentence, 2 x hidden)
              output = model(inputs, mask=mask)
  
              # shape = (batch, sentence, 2 x hidden)
              char_repr = tf.reshape(
                  output, shape=[-1, s[1], 2 * hidden]
              )
  
              if self.word_repr is not None:
                  self.word_repr = tf.concat(
                      [self.word_repr, char_repr], axis=-1
                  )
              else:
                  self.word_repr = char_repr
  
imports: import math
  import random
  import sys
  import numpy
  import tensorflow
  from .sentence_grouper import SentenceGrouper
  from ..tf2contrib import *
label_desc: Use image node_id 2 for calling the NerModel obj's underlying member method code with example usage: obj.add_bilstm_char_repr(nchars, dim, hidden) without return types