I am actually implementing a sequential multiclass labeling model of text data and have a very unbalanced training data set. I have the following occurrence of labels in my dataset (rounded):
Label 0: 0.9297
Label 1: 0.0337
Label 2: 0.0337
Label 3: 0.0011
Label 4: 0.0011
My actual model predicts only Label 0, since this unbalanced training data. My code looks like this:
X_trian.shape
-> (784,300,7)
y_train.shape
-> (784,300,1)
model = Sequential()
model.add(LSTM(150, input_shape=(300,7), return_sequences=True))
model.add(Dense(len(label2index)))
model.compile(loss="sparse_categorical_crossentropy",
metrics=['accuracy'])
model.summary()
model.fit(X_train, y_train, epochs=25)
y_pred = model.predict(X_test, verbose=1)
So each timestep consists of 300 tokens and each token is going to be labeled. So I thought maybe I can handle the problem of the unbalanced data with class weights. The first approach of my research was to use the class_weight argument in model.fit together with a dictionary with a weight entry for each label. But this raised an Exception: class_weight not supported for 3+ dimensional targets.
Now I've read that for 3D data you should use sample_weigt instead of class_weight, but how exactly would that apply to my data? The posts I find about this confuse me quite a bit. Does anyone have any tips on how to use this?