Hi @XiaoquanKong, thank you for this response. I have looked at the notebook and have used the CRFModelWrapper method to try and incorporate a CRF into my project, using a sample weight of approximately 4.2 in unpack_training_data() as there are far fewer 1s, indicating syllable breaks, than 0s. In addition, instead of using tf.data.Dataset for my input data, I have been using NumPy arrays of inputs and outputs for my training and validation data - this also appears to work fine as I can train the model without errors and the loss and CRF loss do decrease. The final modification that I have made is that I changed the input shape in the base model from (None,) to (15,) as all inputs in my dataset are padded to length 15, and I presume that this will not lead to any errors.
However, I have experienced a problem when trying to add the metric binary_accuracy, which I want to use as my labels are strings of 0s and 1s hence this is appropriate, plus I have used it successfully in my model without the CRF. I’m not sure as to where or how I can add this metric - I tried to add it as such:
# This is referring to the full model (base + CRF).
model.compile(optimizer=tf.keras.optimizers.Adam(0.02), metrics=['binary_accuracy'])

When I do this, I get the error:
ValueError: Can not squeeze dim[1], expected a dimension of 1, got 15 for '{{node Squeeze_1}} = Squeeze[T=DT_FLOAT, squeeze_dims=[-1]](Cast_7)' with input shapes: [?,15].

This is a concern for me as the main metric I want to measure is binary accuracy and how the model performs with predicting syllable breaks - any help with how I can integrate this would be much appreciated. When I received this error I did also look at Method one: Using the CRF layer in a custom training loop; in the code there is a reference to Define optimizer, metrics and train_step function, but again I’m not sure as to how I would include binary accuracy as a metric to measure.