title: how to use CRF in tensorflow keras?
body: <p>The code is like this:</p>
  
  <pre><code>import tensorflow as tf
  from keras_contrib.layers import CRF
  from tensorflow import keras
  
  def create_model(max_seq_len, adapter_size=64):
      """Creates a classification model."""
  
      # adapter_size = 64  # see - arXiv:1902.00751
  
      # create the bert layer
      with tf.io.gfile.GFile(bert_config_file, "r") as reader:
          bc = StockBertConfig.from_json_string(reader.read())
          bert_params = map_stock_config_to_params(bc)
          bert_params.adapter_size = adapter_size
          bert = BertModelLayer.from_params(bert_params, name="bert")
  
      input_ids = keras.layers.Input(shape=(max_seq_len,), dtype='int32', name="input_ids")
      # token_type_ids = keras.layers.Input(shape=(max_seq_len,), dtype='int32', name="token_type_ids")
      # output         = bert([input_ids, token_type_ids])
      bert_output = bert(input_ids)
      print("bert_output.shape: {}".format(bert_output.shape))  # (?, 100, 768)
  
      crf = CRF(len(tag2idx))
      logits = crf(bert_output)
      model = keras.Model(inputs=input_ids, outputs=logits)
      model.build(input_shape=(None, max_seq_len))
  
      # load the pre-trained model weights
      load_stock_weights(bert, bert_ckpt_file)
  
      # freeze weights if adapter-BERT is used
      if adapter_size is not None:
          freeze_bert_layers(bert)
  
      model.compile('adam', loss=crf.loss_function, metrics=[crf.accuracy])
  
      model.summary()
  
      return model
  </code></pre>
  
  <p>I am using tensorflow keras and also use keras_contrib package, to do NER. it seems the tensorflow keras package does not work well with keras_contrib package.</p>
  
  <p>The Traceback information is listed below:</p>
  
  <pre><code>Traceback (most recent call last):
    File "F:/_gitclone3/bert_examples/bert_ner_example_eval.py", line 120, in &lt;module&gt;
      model = create_model(max_seq_len, adapter_size=adapter_size)
    File "F:/_gitclone3/bert_examples/bert_ner_example_eval.py", line 101, in create_model
      logits = crf(bert_output)
    File "C:\Users\yuexiang\Anaconda3\lib\site-packages\keras\engine\base_layer.py", line 443, in __call__
      previous_mask = _collect_previous_mask(inputs)
    File "C:\Users\yuexiang\Anaconda3\lib\site-packages\keras\engine\base_layer.py", line 1311, in _collect_previous_mask
      mask = node.output_masks[tensor_index]
  AttributeError: 'Node' object has no attribute 'output_masks'
  </code></pre>
  
  <p>How do I use CRF with tensorflow keras?</p>