luozhouyang / keras-crf

A more elegant and convenient CRF built on tensorflow-addons.
Apache License 2.0
27 stars 3 forks source link

how to use sample weight with CRF as sample weight is a 2D array? #9

Open ShamilaNasreen opened 2 years ago

ShamilaNasreen commented 2 years ago

I am building a model for sequence tagging using BiLSTM and CRF. I am using the Keras-CRF provided in this project. I successfully run the code and below is the summary of my model. While the Keras_model support sample weight as 1D but we have to assign different weights at each time step as I want to give higher weights to less frequent tag class. so my weight_sample shape is (1114,100). It gives error as to compute the loss the function is: if sample_weight is not None: crf_loss = crf_loss * sample_weight and an error occued of 'required broadcast shape'. image

Can you please suggest how to use 2D sample weight within this code.