Error: Labels and preOutput must have equal shapes

Hello,

I am having trouble fitting a model. I keep getting the error: Labels and preOutput must have equal shapes: got shapes [39, 9] vs [780, 9]. I am not sure why I’m getting the error and was wondering if anyone could help out.

My model configuration looks like:

new NeuralNetConfiguration.Builder()
                .weightInit(WeightInit.NORMAL)
                .activation(Activation.RELU)
                .updater(new Adam.Builder().build())
                .list()
                .setInputType(InputType.feedForward(1000))
                .layer(new EmbeddingSequenceLayer.Builder()
                        .nOut(16)
                        .inputLength(20)
                        .build())
                .layer(new DenseLayer.Builder()
                        .nOut(16)
                        .activation(Activation.RELU)
                        .build())
                .layer(new DenseLayer.Builder()
                        .nOut(16)
                        .activation(Activation.RELU)
                        .build())
                .layer(new OutputLayer.Builder()
                        .nOut(9)
                        .activation(Activation.SOFTMAX)
                        .lossFunction(LossFunctions.LossFunction.RECONSTRUCTION_CROSSENTROPY)
                        .build())
                .backpropType(BackpropType.Standard)

I have a training set (INDArray) which is 39 x 20 matrix where the features represent a tokenized sequence of words. My training labels are a 39 x 9 matrix with each row representing a one-hot encoded vector of specific classes.

Problem Description

I am trying to essentially port this medium article to DL4J.

Please let me know if I need to add anything to the description to clarify the question!

@SanchG could you try to give a more complete example with dummy data end to end I could see? That would make it easier to run/diagnose your problem. Let’s break this up a bit.

@agibsonccc Hi, thank you for the quick response.

Here’s the dummy data in JSON format: {"intents": [ {"tag": "greeting", "patterns": ["Hi", "Hey", "Is anyon - Pastebin.com .

Here’s the code I’m using to load the data and to fit the model: import com.google.gson.JsonElement;import com.google.gson.JsonObject;import - Pastebin.com (excuse all the messiness, I tried to shove everything into one class to make it easier to share).

The problem is treated as a classification problem, so the labels are the “tags” (in the dummy data provided), and the features are tokenized versions of the “patterns”. You can ignore the “responses” part of the dummy data as that’s not used in the model.

The pattern strings are tokenized via the keras tokenizer and then are padded to so that each pattern is a vector of length 20. The labels are one hot encoded (via a naive one hot encoder implementation) so that they end up in vector of length 8 (it’s originally 9, but I removed a label for personal purposes).

Let me know if you need anything else!