[Solved]: Index out of range using input dim 2,when implement crf

This is because the crf layer expects the labels in a different shape.

Normally your labels would be of shape (num_samples, max_length) 

but the crf layer expects them in the form (num_samples, max_length, 1) .

An easy fix is to reshape your labels as follows:

labels = labels.reshape((labels.shape[0], labels.shape[1], 1))