# passing the dataset to the fit method of the MultiLayerNetwork class

**URL:** https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535
**Category:** DL4J
**Created:** [April 26, 2023, 7:01am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535 "2023-04-26T07:01:43Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Arasaka](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arasaka/32/1190_2.png) [@Arasaka](https://community.konduit.ai/u/Arasaka)
#### Post date: [April 26, 2023, 7:01am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/1 "2023-04-26T07:01:43Z")

</div>

Hello everyone, I am forming a dataset from INDArray 3 ranks, the dataset is formed without errors. But when passing it to the fit method of the MultiLayerNetwork class, an error occurs: Rank is [3]; columns() call is not valid. What could be the problem?

---

<div class="post-metadata">

### Author: ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)
#### Post date: [April 26, 2023, 7:06am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/2 "2023-04-26T07:06:42Z")

</div>

@Arasaka can you pass more context? You are probably using columns() somewhere. That shortcut is only available for matrices. (Hence the name columns()). If you want the last dimension you can also use:  
arr.size(-1)

---

<div class="post-metadata">

### Author: ![Arasaka](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arasaka/32/1190_2.png) [@Arasaka](https://community.konduit.ai/u/Arasaka)
#### Post date: [April 26, 2023, 7:09am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/3 "2023-04-26T07:09:02Z")

</div>

@agibsonccc thanks for the answer. But the worst part is that I don’t use the columns() method anywhere. Is it possible to pass an INDArray of rank 3 to the fit method? Here is my stack trace:  
Exception in thread “main” java.lang.IllegalStateException: Rank is [3]; columns() call is not valid  
at org.nd4j.linalg.api.ndarray.BaseNDArray.columns(BaseNDArray.java:4054)  
at org.deeplearning4j.nn.layers.feedforward.embedding.EmbeddingLayer.preOutput(EmbeddingLayer.java:85)  
at org.deeplearning4j.nn.layers.feedforward.embedding.EmbeddingLayer.activate(EmbeddingLayer.java:126)  
at org.deeplearning4j.nn.layers.AbstractLayer.activate(AbstractLayer.java:262)  
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.ffToLayerActivationsInWs(MultiLayerNetwork.java:1147)  
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.computeGradientAndScore(MultiLayerNetwork.java:2798)  
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.computeGradientAndScore(MultiLayerNetwork.java:2756)  
at org.deeplearning4j.optimize.solvers.BaseOptimizer.gradientAndScore(BaseOptimizer.java:174)  
at org.deeplearning4j.optimize.solvers.StochasticGradientDescent.optimize(StochasticGradientDescent.java:61)  
at org.deeplearning4j.optimize.Solver.optimize(Solver.java:52)  
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.fitHelper(MultiLayerNetwork.java:1767)  
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.fit(MultiLayerNetwork.java:1688)  
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.fit(MultiLayerNetwork.java:3614)  
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.fit(MultiLayerNetwork.java:3601)  
at Runner.main(Runner.java:58)

---

<div class="post-metadata">

### Author: ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)
#### Post date: [April 26, 2023, 7:11am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/4 "2023-04-26T07:11:43Z")

</div>

@Arasaka ah I see the EmbeddingLayer is calling that. Can you post your network and ideally a reproducer?

It might not be pre processing the data correctly. This is common when you set the inputs manually.

---

<div class="post-metadata">

### Author: ![Arasaka](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arasaka/32/1190_2.png) [@Arasaka](https://community.konduit.ai/u/Arasaka)
#### Post date: [April 26, 2023, 7:13am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/5 "2023-04-26T07:13:37Z")

</div>

@agibsonccc  
Would you like to lay out the network build or dataset assembly?

---

<div class="post-metadata">

### Author: ![Arasaka](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arasaka/32/1190_2.png) [@Arasaka](https://community.konduit.ai/u/Arasaka)
#### Post date: [April 26, 2023, 7:14am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/6 "2023-04-26T07:14:49Z")

</div>

@agibsonccc my network build:  
public static MultiLayerNetwork buildModel() {  
int vocabSize = 10000;  
int embeddingSize = 300;  
int numberHidden = 256;  
int numberClasses = 2;  
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()  
.seed(123)  
.updater(new Adam())  
.list()  
.layer(new EmbeddingLayer.Builder()  
.nIn(vocabSize)  
.nOut(embeddingSize)  
.build())  
.layer(new LSTM.Builder()  
.nIn(embeddingSize)  
.nOut(numberHidden)  
.activation(Activation.TANH)  
.build())  
.layer(new DenseLayer.Builder()  
.nIn(numberHidden)  
.nOut(numberClasses)  
.activation(Activation.SOFTMAX)  
.build())  
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)  
.nIn(numberHidden)  
.nOut(numberClasses)  
.build())  
.build();  
MultiLayerNetwork network = new MultiLayerNetwork(conf);  
network.init();

```
    return network;
}

```

---

<div class="post-metadata">

### Author: ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)
#### Post date: [April 26, 2023, 7:39am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/7 "2023-04-26T07:39:38Z")

</div>

@Arasaka can you remove the manual nIns and use setInputType?  
Something like:  
.setInputType(InputType.recurrent(W2V\_VECTOR\_SIZE, 1000))

See more here;

> **[Build software better, together](https://github.com/search?q=repo%3Adeeplearning4j%2Fdeeplearning4j-examples%20setInputType&type=code)**
>
> GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 330 million projects.

---

<div class="post-metadata">

### Author: ![Arasaka](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arasaka/32/1190_2.png) [@Arasaka](https://community.konduit.ai/u/Arasaka)
#### Post date: [April 26, 2023, 7:42am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/8 "2023-04-26T07:42:28Z")

</div>

@agibsonccc, i’ll try and post here.

---

<div class="post-metadata">

### Author: ![Arasaka](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arasaka/32/1190_2.png) [@Arasaka](https://community.konduit.ai/u/Arasaka)
#### Post date: [April 26, 2023, 10:11am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/9 "2023-04-26T10:11:40Z")

</div>

@agibsonccc  
I did it like this, is it right?

public static MultiLayerNetwork buildModel() {  
int vocabSize = 10000;  
int embeddingSize = 300;  
int numberHidden = 256;  
int numberClasses = 2;  
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()  
.seed(123)  
.updater(new Adam())  
.list()  
.layer(new EmbeddingLayer.Builder()  
.nIn(vocabSize)  
.nOut(embeddingSize)  
.build())  
.layer(new LSTM.Builder()  
.nOut(numberHidden)  
.activation(Activation.TANH)  
.build())  
.layer(new DenseLayer.Builder()  
.nOut(numberClasses)  
.activation(Activation.SOFTMAX)  
.build())  
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)  
.nOut(numberClasses)  
.build())  
.setInputType(InputType.reccurrent(embeddingSize))  
.build();  
MultiLayerNetwork network = new MultiLayerNetwork(conf);  
network.init();  
return network;  
}

---

<div class="post-metadata">

### Author: ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)
#### Post date: [April 26, 2023, 10:15am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/10 "2023-04-26T10:15:07Z")

</div>

@Arasaka remove your other nIn declaration as well. setInputType goes through each layer and adds pre processors as well as sets the input number for you. Run that let me know if you have any issues.

---

<div class="post-metadata">

### Author: ![Arasaka](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arasaka/32/1190_2.png) [@Arasaka](https://community.konduit.ai/u/Arasaka)
#### Post date: [April 26, 2023, 10:27am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/11 "2023-04-26T10:27:31Z")

</div>

@agibsonccc that is to remove still in EmbeddingLayer?

---

<div class="post-metadata">

### Author: ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)
#### Post date: [April 26, 2023, 10:27am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/12 "2023-04-26T10:27:58Z")

</div>

@Arasaka yes. nIn is not needed anywhere in the network besides in setInputType

---

<div class="post-metadata">

### Author: ![Arasaka](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arasaka/32/1190_2.png) [@Arasaka](https://community.konduit.ai/u/Arasaka)
#### Post date: [April 26, 2023, 10:39am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/13 "2023-04-26T10:39:08Z")

</div>

@agibsonccc understood, thank you. Now I will run in and write to you.

---

<div class="post-metadata">

### Author: ![Arasaka](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arasaka/32/1190_2.png) [@Arasaka](https://community.konduit.ai/u/Arasaka)
#### Post date: [April 26, 2023, 12:06pm UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/14 "2023-04-26T12:06:46Z")

</div>

@agibsonccc now when transferring the dataset for training to the model, the following error occurs:  
“Cannot do forward pass for embedding layer with input more than one column. Expected input shape: [numExamples,1] with each entry being an integer index (layer name: layer0, layer index: 0, layer type: EmbeddingLayer)”. As I understand it, the error occurs because the input data has the dimension [numExamples, maxLength, vectorLength], and the EmbeddingLayer expects input data of the dimension [numExamples, 1], where each element is the index of the word in the dictionary.

---

<div class="post-metadata">

### Author: ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)
#### Post date: [April 26, 2023, 12:18pm UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/15 "2023-04-26T12:18:35Z")

</div>

> [@Arasaka](#):
>
> annot do forward pass for embedding layer with input more than one column. Expected input shape: [numExamples,1] with each entry being an integer index (layer name: layer0, layer index: 0, layer type: EmbeddingLayer)”. As I understand it, the error occurs because the input data has the dimension [numExamples, maxLength, vectorLength], and the EmbeddingLayer expects input data of the dime

@Arasaka switch to using the EmbeddingSequenceLayer instead. Sorry I wasn’t thinking about that earlier. You can find tests and the class here: [https://github.com/search?q=repo%3Adeeplearning4j%2Fdeeplearning4j%20%20EmbeddingSequenceLayer&type=code](https://github.com/search?q=repo%3Adeeplearning4j%2Fdeeplearning4j%20%20EmbeddingSequenceLayer&type=code)

---

<div class="post-metadata">

### Author: ![Arasaka](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arasaka/32/1190_2.png) [@Arasaka](https://community.konduit.ai/u/Arasaka)
#### Post date: [April 26, 2023, 12:43pm UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/16 "2023-04-26T12:43:46Z")

</div>

@agibsonccc i changed EmbeddingLayer to EmbeddingSequenceLayer. What will be the result - I will write.

---

<div class="post-metadata">

### Author: ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)
#### Post date: [April 26, 2023, 12:49pm UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/17 "2023-04-26T12:49:48Z")

</div>

@Arasaka since you’re using 3d the sequence layer expects 3d. That’s why we had the 2d columns assumption in there.

---

<div class="post-metadata">

### Author: ![Arasaka](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arasaka/32/1190_2.png) [@Arasaka](https://community.konduit.ai/u/Arasaka)
#### Post date: [April 26, 2023, 12:55pm UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/18 "2023-04-26T12:55:42Z")

</div>

@agibsonccc i replaced like this:  
public static MultiLayerNetwork buildModel() {  
int vocabSize = 10000;  
int embeddingSize = 300;  
int numberHidden = 256;  
int numberClasses = 2;  
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()  
.seed(123)  
.updater(new Adam())  
.list()  
.layer(new EmbeddingSequenceLayer.Builder() //change  
.nOut(embeddingSize)  
.build())  
.layer(new LSTM.Builder()  
.nOut(numberHidden)  
.activation(Activation.TANH)  
.build())  
.layer(new DenseLayer.Builder()  
.nOut(numberClasses)  
.activation(Activation.SOFTMAX)  
.build())  
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MCXENT)  
.nOut(numberClasses)  
.build())  
.setInputType(InputType.reccurrent(embeddingSize))  
.build();  
MultiLayerNetwork network = new MultiLayerNetwork(conf);  
network.init();  
return network;  
}

I hope I did it right

---

<div class="post-metadata">

### Author: ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)
#### Post date: [April 26, 2023, 1:00pm UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/19 "2023-04-26T13:00:05Z")

</div>

@Arasaka at first glance that looks good. Give that a shot and I"ll check on you tomorrow.

---

<div class="post-metadata">

### Author: ![Arasaka](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arasaka/32/1190_2.png) [@Arasaka](https://community.konduit.ai/u/Arasaka)
#### Post date: [April 27, 2023, 2:46am UTC](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535/20 "2023-04-27T02:46:28Z")

</div>

@agibsonccc hello, today and tomorrow will have to wait a while with this. I hope you wait.

[Next page](https://community.konduit.ai/t/passing-the-dataset-to-the-fit-method-of-the-multilayernetwork-class/2535.md?page=2)
