如何学习领域的描述和可能的类别

问题描述:

我有一个看起来像这样如何学习领域的描述和可能的类别

enter image description here

seq2seq一个正确的做法,所以我的模型可以了解在产品的文本之间的关系,产品之间的关系之间的关系(左列)和类别(右列),然后能够根据产品描述预测未来的类别?

Seq2Seq基本上有两种不同的回归神经网络连接在一起:编码器RNN其取得输入text tokens和解码器RNN启动基于来自编码器RNN输出产生text tokens。它是一个序列网络。但是我的看法是,输入是一个序列,输出是基于输入的类别。您最好尝试一个LSTM网络,它将您的输入序列通过embedding layer,然后将LSTM的最后一个hidden state传递到dense layer进行分类。

的LSTM型号为你的使用情况:

占位符输入和输出

# input batch of text sequences of length `seq_length` 
X = tf.placeholder(tf.int32, [None, seq_length], name='input') 

# Output class labels 
y = tf.placeholder(tf.float32, [None], name='labels') 

埋层

# For every word in your vocab you need a embedding vector. 
# The below weights are not trainable as we will `init` with `pre-trained` embeddings. If you dont want to do that set it to True. 
W = tf.get_variable(initializer=tf.random_uniform([vocab_size, embedding_size]), name='embed', trainable=False) 

# Get the embedding representation of the inputs 
embed = tf.nn.embedding_lookup(W, X) 

LSTM层

# Create basic LSTMCell, with number of hidden units as a input param 
def lstm_cell(): 
    return tf.contrib.rnn.BasicLSTMCell(n_hidden) 

# Create a stack of LSTM cells (if you need) 
stacked_lstm = tf.contrib.rnn.MultiRNNCell([lstm_cell() for _ in range(n_layers)]) 

# Create a dynamic RNN to handle the sequence of inputs 
output, _ = tf.nn.dynamic_rnn(stacked_lstm, x, dtype=tf.float32) 

# get the output of the last hidden state 
last_hidden = output[:, -1, :] 

最后的密铺呃

# output dimension should be `n_classes`. 
logits = dense_layer(last_hidden ...) 

这应该是你的型号。

+0

谢谢你看这个。不确定你的意思是“输出是基于输入的类别”。我已经定义了所有类别(输出),我希望网络学习输入描述与类别(输出)文本之间的关系。 – Rikard

+0

抱歉不清楚。阅读它有'每个输出属于你已经定义的一个类别,而不是一个序列'。 –

+0

好的,所以我应该尝试[密集层](https://www.tensorflow.org/api_docs/python/tf/layers/dense)。将查找示例并了解如何使用该图层中的类别文本来帮助网络做出正确的预测。谢谢!我将调查/研究并回来。 – Rikard