How to use CTC loss function?
Created by: F0REacH
How to use CTC loss function? I'm planning to extend my dataset with unsegmented data, but cannot figure out how to use ctc_error_evaluator and ctc_layer model:
def stacked_gru_net_with_ctc(input_dim=24,
class_dim=133,
hid_dim=129,
stacked_num=3,
is_predict=False):
"""
"""
assert stacked_num % 2 == 1
linear = LinearActivation()
data = data_layer("word", input_dim)
fc1 = fc_layer(input=data, size=hid_dim, act=linear)
gru1 = grumemory(input=fc1)
inputs = [fc1, gru1]
for i in range(2, stacked_num + 1):
fc = fc_layer(input=inputs, size=hid_dim, act=linear)
gru = grumemory(input=fc, reverse=(i % 2) == 0)
inputs = [fc, gru]
output = fc_layer(input=inputs, size=class_dim, act=SoftmaxActivation())
if is_predict:
outputs(output)
else:
# FIXME? #outputs(classification_cost(input=output, label=data_layer('label', class_dim), evaluator=ctc_error_evaluator))
outputs(classification_cost(input=output, label=data_layer('label', class_dim), evaluator=precision_recall_evaluator))
dataprovider:
settings.input_types = [
dense_vector_sequence(24),
integer_value_sequence(133)]
Also I have no idea how to feed labels to model if sequences are not segmented. With simple classification_cost each timestep has label, but how to use dataprovider with unsegmented sequences and CTC? My current dataset is 180 examples, each is roughly 5000 timesteps (variable length). Each timestep is len=24 float vector labeled with one int label in range 0..132 (133 labels total). Any example/suggestion would be highly appreciated. Thanks