我有一个像下面的对话框.我想实现一个预测系统动作的LSTM模型.系统动作被描述为位向量.并且用户输入被计算为字嵌入,其也是位向量.
t1: user: "Do you know an apple?", system: "no"(action=2)
t2: user: "xxxxxx", system: "yyyy" (action=0)
t3: user: "aaaaaa", system: "bbbb" (action=5)
Run Code Online (Sandbox Code Playgroud)
所以我想要实现的是"多对多(2)"模型.当我的模型收到用户输入时,它必须输出系统操作.
但我无法理解LSTM后的return_sequences选项和TimeDistributed图层.要实现"多对多(2)",需要return_sequences==True添加TimeDistributedLSTM后?如果你能更多地描述它们,我感激不尽.
return_sequences:布尔值.是返回输出序列中的最后一个输出,还是返回完整序列.
TimeDistributed:此包装器允许将图层应用于输入的每个时间片.
我想我能理解这个return_sequence选项.但我还不确定TimeDistributed.如果我添加一个TimeDistributedLSTM之后,模型是否与下面的"我的多对多(2)"相同?所以我认为Dense图层适用于每个输出.

我正在使用vscode进行python开发.我有时使用调试运行模式,即使没有断点,vscode总是在第一行停止.我附上了这种现象的截图.这有点烦人,我想跳过这个.有没有办法跳过这个?
我的环境
我有一个单词列表,如下所示.我想拆分列表..Python 3中是否有更好或更有用的代码?
a = ['this', 'is', 'a', 'cat', '.', 'hello', '.', 'she', 'is', 'nice', '.']
result = []
tmp = []
for elm in a:
if elm is not '.':
tmp.append(elm)
else:
result.append(tmp)
tmp = []
print(result)
# result: [['this', 'is', 'a', 'cat'], ['hello'], ['she', 'is', 'nice']]
Run Code Online (Sandbox Code Playgroud)
添加测试用例以正确处理它.
a = ['this', 'is', 'a', 'cat', '.', 'hello', '.', 'she', 'is', 'nice', '.']
b = ['this', 'is', 'a', 'cat', '.', 'hello', '.', 'she', 'is', 'nice', '.', 'yes']
c = …Run Code Online (Sandbox Code Playgroud) 我想比较我的代码处理时间和不使用gpu.我的keras后端是Tensorflow.所以它会自动使用GPU.我用一个keras/examples/mnist_mlp.py比较模型.
我检查了下面的处理时间.那么,我如何禁用我的GPU?应该~/.keras/keras.json修改?
$ time python mnist_mlp.py
Test loss: 0.109761892007
Test accuracy: 0.9832
python mnist_mlp.py 38.22s user 3.18s system 162% cpu 25.543 total
Run Code Online (Sandbox Code Playgroud) 我有以下字符串列表。然后,我想按每个元素中的数字对其进行排序。sorted失败,因为它无法处理诸如 between10和之类的顺序3。我可以想象如果我使用re,我可以做到。但这并不有趣。你们有好的实现想法吗?我想这个代码的python 3.x。
names = [
'Test-1.model',
'Test-4.model',
'Test-6.model',
'Test-8.model',
'Test-10.model',
'Test-20.model'
]
number_sorted = get_number_sorted(names)
print(number_sorted)
'Test-20.model'
'Test-10.model'
'Test-8.model'
'Test-6.model'
'Test-4.model'
'Test-1.model'
Run Code Online (Sandbox Code Playgroud) 我想使用Ctrl-semicolon作为tmux的前缀.但我的conf不起作用.
unbind-key C-b
set-option -g prefix C-\;
Run Code Online (Sandbox Code Playgroud)
我发现了一篇类似的文章.但它不是前缀. tmux绑定分号
顺便说一下,你最喜欢的前缀键是什么?:D你有推荐钥匙吗?
我不确定 numpy 中 (N,) 和 (N,1) 之间的区别。假设两者都是一些特征,它们具有相同的N维,并且都有一个样本。有什么不同?
a = np.ones((10,))
print(a.shape) #(10,)
b = np.ones((10,1))
print(b.shape) #(10,1)
Run Code Online (Sandbox Code Playgroud) 我有顺序数据,我宣布了一个LSTM模型,y用xKeras 预测.所以,如果我打电话model.predict(x1)和model.predict(x2),它是正确的调用model.reset_states两者之间predict()明确?是否model.reset_states清楚输入的历史,而不是权重,对吧?
# data1
x1 = [2,4,2,1,4]
y1 = [1,2,3,2,1]
# dat2
x2 = [5,3,2,4,5]
y2 = [5,3,2,3,2]
Run Code Online (Sandbox Code Playgroud)
在我的实际代码中,我使用model.evaluate().在evaluate()中,是否为每个数据样本隐式调用reset_states?
model.evaluate(dataX, dataY)
Run Code Online (Sandbox Code Playgroud) 我想实现字符级嵌入.
这是通常的单词嵌入.
单词嵌入
Input: [ [‘who’, ‘is’, ‘this’] ]
-> [ [3, 8, 2] ] # (batch_size, sentence_len)
-> // Embedding(Input)
# (batch_size, seq_len, embedding_dim)
Run Code Online (Sandbox Code Playgroud)
这就是我想要做的.
字符嵌入
Input: [ [ [‘w’, ‘h’, ‘o’, 0], [‘i’, ‘s’, 0, 0], [‘t’, ‘h’, ‘i’, ‘s’] ] ]
-> [ [ [2, 3, 9, 0], [ 11, 4, 0, 0], [21, 10, 8, 9] ] ] # (batch_size, sentence_len, word_len)
-> // Embedding(Input) # (batch_size, sentence_len, word_len, embedding_dim)
-> // sum each character embeddings …Run Code Online (Sandbox Code Playgroud) 我正在阅读以下论文。它对变量使用 EMA 衰减。
用于机器理解的双向注意力流
在训练过程中,模型所有权重的移动平均值保持为 0.999 的指数衰减率。
他们使用TensorFlow,我找到了EMA的相关代码。
https://github.com/allenai/bi-att-flow/blob/master/basic/model.py#L229
在 PyTorch 中,如何将 EMA 应用于变量?