- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我对基本序列到序列 LSTM 的理解。假设我们正在处理问答设置。
你有两组 LSTM(下面的绿色和蓝色)。每组分别共享权重(即 4 个绿色单元格中的每一个都具有相同的权重,并且与蓝色单元格相似)。第一个是多对一LSTM,总结了问题在最后一个隐藏层/单元内存 .
第二组(蓝色)是多对多 LSTM,其权重与第一组 LSTM 不同。输入只是答案句子,而输出是同一个句子移位了一个。
问题有两个方面:
1.我们是否通过了最后一个隐藏状态仅限 将蓝色 LSTM 作为初始隐藏状态。还是最后一个隐藏状态和单元内存 .
2. 有没有办法在 Keras 或 Tensorflow 中设置初始隐藏状态和单元内存?如果有引用?
(图片取自 suriyadeepan.github.io)
最佳答案
- Are we passing the last hidden state only to the blue LSTMs as the initial hidden state. Or is it last hidden state and cell memory.
h
和单元内存
c
传递给解码器。
basic_rnn_seq2seq()
中找到以下代码:
_, enc_state = rnn.static_rnn(enc_cell, encoder_inputs, dtype=dtype)
return rnn_decoder(decoder_inputs, enc_state, cell)
LSTMCell
,返回
enc_state
来自编码器的将是一个元组
(c, h)
.如您所见,元组直接传递给解码器。
LSTMCell
定义的“状态”也是一个元组
(h, c)
(注意顺序与TF不同)。在
LSTMCell.call()
, 你可以找到:
h_tm1 = states[0]
c_tm1 = states[1]
LSTM
返回的状态层,可以指定
return_state=True
.返回值是一个元组
(o, h, c)
.张量
o
是该层的输出,将等于
h
除非您指定
return_sequences=True
.
- Is there a way to set the initial hiddden state and cell memory in Keras or Tensorflow? If so reference?
LSTMCell
调用它时。例如,在
official RNN tutorial :
lstm = tf.contrib.rnn.BasicLSTMCell(lstm_size)
...
output, state = lstm(current_batch_of_words, state)
initial_state
tf.nn.static_rnn
等函数的参数.如果您使用 seq2seq 模块,请将状态提供给
rnn_decoder
如问题 1 的代码所示。
initial_state
在 LSTM 函数调用中。
out = LSTM(32)(input_tensor, initial_state=(h, c))
Note on specifying the initial state of RNNs
You can specify the initial state of RNN layers symbolically by calling them with the keyword argument
initial_state
. The value ofinitial_state
should be a tensor or list of tensors representing the initial state of the RNN layer.
关于tensorflow - 了解 Seq2Seq 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46355651/
我是 F# 的新手,目前想知道如何将序列的字节序列转换为序列的浮点序列 seq -> seq 所以我有以下字节序列 let colourList = seq[ seq[10uy;20uy;30uy];
我想在一个序列中聚合兼容的元素,即转换 Seq[T]成Seq[Seq[T]]其中每个子序列中的元素彼此兼容,同时保留原始 seq 顺序,例如从 case class X(i: Int, n: Int)
以下函数files返回seq> 。如何让它返回seq相反? type R = { .... } let files = seqOfStrs |> Seq.choose(fun s -> mat
我正在尝试转换如下所示的数据: val inputData = Seq(("STUDY1", "Follow-up", 1), ("STUDY1", "Off Study", 2),
稍微简化一下,我的问题来自字符串列表 input我想用函数解析 parse返回 Either[String,Int] . 然后list.map(parse)返回 Either 的列表s。程序的下一步是
如标题中所述,我不明白为什么这些函数无法编译并要求 Seq。 def f1[V a + b } error: type mismatch; found : Seq[Int] required:
我有一个类型为 Flow[T, Seq[Seq[String]], NotUsed] 的流。 我想以示例流的方式将其展平 ev1: Seq(Seq("a", "b"), Seq("n", "m") e
我对 Scala 比较陌生,但我想我理解它的类型系统和并行集合,但我无法理解这个错误: 我有一个函数 def myFun(a : Seq[MyType], b : OtherType) : Seq[M
在学习 F# 时,我正在做一个小挑战: Enter a string and the program counts the number of vowels in the text. For adde
------------------------- clojure.core/seq ([coll]) Returns a seq on the collection. If the collec
我担心不知道什么时候可以使用 "Seq", "seq"。你能告诉我有哪些不同之处吗? 这是我的代码。为什么不使用“seq”? let s = ResizeArray() s.Add(1.1) s
我试图返回一个带有直到循环的可变序列,但我有一个不可变的序列作为 (0 until nbGenomes) 的返回: def generateRandomGenome(nbGenomes:Int):
将 Seq(Seq) 分配到多个类型化数组而不先将 Seq 分配给标量的正确语法是什么? Seq 是否会以某种方式变平?这失败了: class A { has Int $.r } my A (@ra1
我正在尝试训练 序列到序列 一个简单的正弦波模型。目标是获得Nin数据点和预测 Nout下一个数据点。任务看起来很简单,模型对大频率的预测很好 freq (y = sin(freq * x))。例如,
我正在努力重构一些使用 Seq 的 Node.js 代码,以及文档和 this answer ,我知道我使用 this() 转到下一个 .seq(),但是如何将变量传递给下一个 .seq( )的功能?
我有一个像这样的字符串序列(文件中的行) [20150101] error a details 1 details 2 [20150101] error b details [20150101] er
给定两个序列 a 和 b,声明如下: var a = @[1, 2, 3] b = @[4, 5, 6] a = b 会创建一个新的 seq 将所有内容从 b 复制到 a 还是重用 a?我有特
type Suit = Spades | Clubs | Hearts | Diamonds type Rank = Ace | Two | Three | Four | Five | Six | S
慢慢地掌握列表匹配和尾递归的窍门,我需要一个函数将列表“缝合”在一起,去掉中间值(更容易显示而不是解释): 合并 [[1;2;3];[3;4;5];[5;6;7]]//-> [1;2;3;4;5;6;
为什么这段代码不起作用? type Test() = static member func (a: seq) = 5. let a = [[4.]] Test.func(a) 它给出以下错误: T
我是一名优秀的程序员,十分优秀!