# How to pass each column of a Matrix(which is the output of an NN) onto a layer seperately

**URL:** <https://discourse.julialang.org/t/how-to-pass-each-column-of-a-matrix-which-is-the-output-of-an-nn-onto-a-layer-seperately/72574>\
**Category:** Machine Learning\
**Tags:** question, flux\
**Created:** [December 4, 2021, 11:24am UTC](https://discourse.julialang.org/t/how-to-pass-each-column-of-a-matrix-which-is-the-output-of-an-nn-onto-a-layer-seperately/72574 "2021-12-04T11:24:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qfl3x](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qfl3x/32/224645_2.png) [@Qfl3x](https://discourse.julialang.org/u/Qfl3x)\
**Post date:** [December 4, 2021, 11:24am UTC](https://discourse.julialang.org/t/how-to-pass-each-column-of-a-matrix-which-is-the-output-of-an-nn-onto-a-layer-seperately/72574/1 "2021-12-04T11:24:31Z")

</div>

Hello,

I have a net as follows:

```julia
model = Chain(Embed(200,37),Dense(200,150),Dense(150,100))

```

The output of `Embed` (From Transformers.jl) is an embedding matrix of size (200,100) for a size 100 input vector. Meaning at the end of this model, the result is a 100x100 matrix.

I want for each character(line in matrix) along dimension 2 to have one of 14 possibilities (perhaps through a `softmax` or similar). Meaning that I need to run a `Dense(100,14),softmax` through each column (first dimension) of the output matrix. How to do that? The Dense is preferably the same for all lines, the model is already a bit too big.

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [December 4, 2021, 5:21pm UTC](https://discourse.julialang.org/t/how-to-pass-each-column-of-a-matrix-which-is-the-output-of-an-nn-onto-a-layer-seperately/72574/2 "2021-12-04T17:21:17Z")

</div>

Does 100 represent the number of characters? If so, you’re missing a batch dimension. I’d have a look at your input and make sure it has the correct shape (`sequence_length x batch`).

---

<div class="post-metadata">

**Author:** ![Qfl3x](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qfl3x/32/224645_2.png) [@Qfl3x](https://discourse.julialang.org/u/Qfl3x)\
**Post date:** [December 5, 2021, 4:46pm UTC](https://discourse.julialang.org/t/how-to-pass-each-column-of-a-matrix-which-is-the-output-of-an-nn-onto-a-layer-seperately/72574/3 "2021-12-05T16:46:14Z")

</div>

I solved it!

Each input array is of length 100, and each output array (From the network) is of dimensions (23x100). I simply turned my problem into a classification problem for each character (One of the 100), so the data labels are now of size (23x100) each. (One Hot arrays)

My input is now a tensor of dimensions (100xN), and my output is a tensor of dimensions (23x100xN), where N is the lines in my document. I then use `DataLoader` to cut it into batches and feed it to the network. My issue now is low memory (I only have 8GB, 1.8 of which is used to load 20% of the training dataset), but I’m going to use another computer for it.

Also, in my case since I’m interested in the classification of 100 elements, I suppose it’s fine for the loss is around ~2.1 per line (input array).
