如何在CNTK中实现一个序列分类LSTM网络?
How to implement a sequence classification LSTM network in CNTK?
我正在为序列 classification 实施 LSTM 神经网络。我想设计一个具有以下参数的网络:
- 输入:一系列
n
单热向量。
- 网络拓扑结构:二层LSTM网络。
- 输出:给定序列属于class(二进制-class化)的概率。我只想考虑第二个 LSTM 层的最后输出。
我需要在 CNTK 中实现它,但我很挣扎,因为它的文档写得不是很好。有人可以帮我吗?
我对 CNTK 不熟悉。但是既然这个问题这么久都没有得到解答,我也许可以提出一些建议来帮助您实施?
我不确定您对这些架构有多少经验;但在转向 CNTK(似乎社区不太活跃)之前,我建议查看其他流行的存储库(如 Theano、tensor-flow 等)
例如,这里给出了 theano 中的一个类似任务:kyunghyuncho tutorials。只需查找 "def lstm_layer" 的定义。
可以在 Karpathy's very popular tutorials
中找到火炬示例
希望对您有所帮助..
sequence classification example 正好符合您的要求。
唯一的区别是它只使用一个 LSTM 层。您可以通过更改以下内容轻松更改此网络以使用多层:
LSTM_function = LSTMP_component_with_self_stabilization(
embedding_function.output, LSTM_dim, cell_dim)[0]
至:
num_layers = 2 # for example
encoder_output = embedding_function.output
for i in range(0, num_layers):
encoder_output = LSTMP_component_with_self_stabilization(encoder_output.output, LSTM_dim, cell_dim)
但是,您最好使用新的图层库。那么你可以简单地这样做:
encoder_output = Stabilizer()(input_sequence)
for i in range(0, num_layers):
encoder_output = Recurrence(LSTM(hidden_dim)) (encoder_output.output)
然后,要获得您放入密集输出层的最终输出,您可以先执行以下操作:
final_output = sequence.last(encoder_output)
然后
z = Dense(vocab_dim) (final_output)
here 你可以找到一个简单的方法,只需添加附加层,如:
Sequential([
Recurrence(LSTM(hidden_dim), go_backwards=False),
Recurrence(LSTM(hidden_dim), go_backwards=False),
Dense(label_dim, activation=sigmoid)
])
训练它、测试它并应用它...
CNTK 发布了一个 hands-on tutorial 具有端到端配方的语言理解:
This hands-on lab shows how to implement a recurrent network to process text, for the Air Travel Information Services (ATIS) task of slot tagging (tag individual words to their respective classes, where the classes are provided as labels in the training data set). We will start with a straight-forward embedding of the words followed by a recurrent LSTM. This will then be extended to include neighboring words and run bidirectionally. Lastly, we will turn this system into an intent classifier.
我正在为序列 classification 实施 LSTM 神经网络。我想设计一个具有以下参数的网络:
- 输入:一系列
n
单热向量。 - 网络拓扑结构:二层LSTM网络。
- 输出:给定序列属于class(二进制-class化)的概率。我只想考虑第二个 LSTM 层的最后输出。
我需要在 CNTK 中实现它,但我很挣扎,因为它的文档写得不是很好。有人可以帮我吗?
我对 CNTK 不熟悉。但是既然这个问题这么久都没有得到解答,我也许可以提出一些建议来帮助您实施? 我不确定您对这些架构有多少经验;但在转向 CNTK(似乎社区不太活跃)之前,我建议查看其他流行的存储库(如 Theano、tensor-flow 等)
例如,这里给出了 theano 中的一个类似任务:kyunghyuncho tutorials。只需查找 "def lstm_layer" 的定义。 可以在 Karpathy's very popular tutorials
中找到火炬示例希望对您有所帮助..
sequence classification example 正好符合您的要求。
唯一的区别是它只使用一个 LSTM 层。您可以通过更改以下内容轻松更改此网络以使用多层:
LSTM_function = LSTMP_component_with_self_stabilization(
embedding_function.output, LSTM_dim, cell_dim)[0]
至:
num_layers = 2 # for example
encoder_output = embedding_function.output
for i in range(0, num_layers):
encoder_output = LSTMP_component_with_self_stabilization(encoder_output.output, LSTM_dim, cell_dim)
但是,您最好使用新的图层库。那么你可以简单地这样做:
encoder_output = Stabilizer()(input_sequence)
for i in range(0, num_layers):
encoder_output = Recurrence(LSTM(hidden_dim)) (encoder_output.output)
然后,要获得您放入密集输出层的最终输出,您可以先执行以下操作:
final_output = sequence.last(encoder_output)
然后
z = Dense(vocab_dim) (final_output)
here 你可以找到一个简单的方法,只需添加附加层,如:
Sequential([
Recurrence(LSTM(hidden_dim), go_backwards=False),
Recurrence(LSTM(hidden_dim), go_backwards=False),
Dense(label_dim, activation=sigmoid)
])
训练它、测试它并应用它...
CNTK 发布了一个 hands-on tutorial 具有端到端配方的语言理解:
This hands-on lab shows how to implement a recurrent network to process text, for the Air Travel Information Services (ATIS) task of slot tagging (tag individual words to their respective classes, where the classes are provided as labels in the training data set). We will start with a straight-forward embedding of the words followed by a recurrent LSTM. This will then be extended to include neighboring words and run bidirectionally. Lastly, we will turn this system into an intent classifier.