在MLP的情况下,Tensor-flow如何使用填充和遮罩层? [英] Tensor-flow how to use padding and masking layer in case of MLPs?

查看:136
本文介绍了在MLP的情况下,Tensor-flow如何使用填充和遮罩层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用MLP解决回归问题.

I want to use MLPs to solve regression problem.

我有可变长度的输入来解决此问题,我想对遮罩层使用零填充.

I have inputs with variable length to fix this I want to use Zero-padding with masking layer.

我使用 pandas 库读取了来自 csv 文件的输入.这是我的数据.

I read the inputs from csv file using pandas library. Here is how my data look like.

我只知道如何使用此命令x_train.fillna(0.0).values

I know only how to fill NaN values with 0 using this command x_train.fillna(0.0).values

就像第一行一样:

[4, 0, 0, 512, 1.0, 0.0, 1.0, 0.0, 128.0 , NaN]

填充后:

[4, 0, 0, 512, 1.0, 0.0, 1.0, 0.0, 128.0 , 0.0]

面具应该是这样的:

[1, 1, 1, 1, 1, 1, 1, 1, 1, 0]

但是我不知道如何添加遮罩层并将其填充到我的MLP中.

But I do not know how to add the mask layer and feed them into my MLPs.

如果我有固定的输入长度.我的程序看起来像这样

If i have fixed input length. My program will look like this

...
n_input = 10 #number og inputs

train_X = pd.read_csv('x_train.csv')
train_Y = pd.read_csv('y_train.csv')


X = tf.placeholder("float", [None, n_input])
Y = tf.placeholder("float", [None, n_output])

...
y_pred = multilayer_perceptron(X)
...

with tf.Session() as sess:
    sess.run(init)

            _, c = sess.run([train, loss], feed_dict={X: train_X,
                                                      Y: train_Y})
          ...

我不知道如何在零填充和遮罩层之间进行组合?

I do not know how to combine between Zero padding and masking layer?

推荐答案

您不能忽略MLP中的单个功能.数学上,我们谈论的是矩阵乘法.您唯一可以忽略"的维度是循环图层中的时间维度,因为权重的数量不随时间维度而变化,因此单个图层在时间维度上可以采用不同的大小.

You cannot ignore a single Features in an MLP. Mathematically we are talking about a matrix multiplication. The only dimensions you can "ignore" are time dimensions in recurrent layers since the number of weights does not scale with the dimension of time and so a single layer can take different sizes in the time dimension.

如果仅使用密集层,则不能跳过任何内容,因为唯一的尺寸(除批尺寸外)直接与重量数成比例.

If you are only using Dense layers you cannot skip anything because your only dimension (besides the batch dimensions) scales directly with the number of weights.

这篇关于在MLP的情况下,Tensor-flow如何使用填充和遮罩层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆