您的位置:首页 > 科技 > 能源 > 创客贴平面设计在线官网_随州seo_百度云app_网站推广的基本方法有

创客贴平面设计在线官网_随州seo_百度云app_网站推广的基本方法有

2024/10/5 17:23:08 来源:https://blog.csdn.net/weixin_40293999/article/details/142495227  浏览:    关键词:创客贴平面设计在线官网_随州seo_百度云app_网站推广的基本方法有
创客贴平面设计在线官网_随州seo_百度云app_网站推广的基本方法有

在这里插入图片描述
在这里插入图片描述

# Initialize the LSTM layer
lstm = nn.LSTM(input_size, hidden_size, num_layers=2, bidirectional=True)# Pass the input data through the LSTM
# Note: the input needs to be of shape (sequence_length, batch_size, input_size)
output, (hidden, cell) = lstm(input_data)

这里意在说明 num_layer 和 bidirectional 对 output 和 hidden的影响。
output是最后一层所有hidden的collection, 但因为有双向LSTM。
所以最后一层的从输出,是output的最后一个单元的前向,和第一个单元的后向:
在这里插入图片描述

import torch
import torch.nn as nn# Define input parameters
input_size = 1        # Number of input features
hidden_size = 2       # Number of LSTM units (hidden state size)
sequence_length = 5   # Length of the input sequences
batch_size = 1        # Number of sequences in a batch# Create a sample input (sequence of shape [batch_size, sequence_length, input_size])
input_data = torch.tensor([[[1.0]],[[2.0]],[[3.0]],[[4.0]],[[5.0]]])  # Shape (5, 1, 1)# Initialize the LSTM layer
lstm = nn.LSTM(input_size, hidden_size, num_layers=2, bidirectional=True)# Pass the input data through the LSTM
# Note: the input needs to be of shape (sequence_length, batch_size, input_size)
output, (hidden, cell) = lstm(input_data)# Print results
print("LSTM Output (all time steps):")
print(output)print("\nFinal Hidden State (forward + backward):")
print(hidden)# The hidden state has two layers for bidirectional: 
# hidden[0] for the forward direction, hidden[1] for the backward direction.
# We can compare the output with the hidden states.
#  单独看方向因素已经搞定了
#  单独看层的因素
#  看层和方向的组合

可以拿这一段代码来实验出来!,有了方向的参数真的好麻烦啊!!!!
在这里插入图片描述
这也大概解释了,这里。但是可以看出来,它控制的还不够仔细应该是 outputs[-1]的前半段拼接outputs[0]的后半段!

seq2seq类型

在这里插入图片描述
这个地方就很乱,有的输入是有bos和eos,输出时有bos和eos,
但这个图的输入就只有eos, 输出倒是bos和eos都有,

损失函数加入ignore_index,对把pad的忽略掉其损失。
还有一点需要确认的时,encoder部分的输入是一下子放进去一个seq,然后当然神经元计算的时候,肯定一个个串行喽,但是decoder的部分,就是一个个输入的,先输入【bos】,在输入【lls】,然后这里就有个问题,是输入上面那个lls还是下面那个呢,这就是teacher_force那个参数的作用。

seq2seq的示例

输入: the door was locked from the inside . <eos>
标签:<unk> <unk><unk> 了 。 <eos>
翻译:电话 被 <unk><unk> 了 。 <eos>输入: as long as you keep quiet , you can stay here . <eos>
标签:只要 你 保持 安靜   ,   你 可以 留在 這裡 。 <eos>
翻译:你 <unk><unk> 一點 , 你 <eos>输入: tom let us know he needs to do that . <eos>
标签:汤姆 让 我们 知道 他 需要 做 。 <eos>
翻译:汤姆 不想 告诉 我们 他 需要 做 。 <eos>输入: let us know when you'll arrive . <eos>
标签:讓 我們 知道 你 什麼 時候 會 到 。 <eos>
翻译:我們 知道 我們 的 时候 就 就 。 <eos>输入: who did you speak with ? <eos>
标签:你 和 谁 说话 呢 ? <eos>
翻译:你 认为 你 的 的 呢 ? <eos>输入: i was amazed at his courage . <eos>
标签:我 對 他 的 勇氣 感到 驚訝 。 <eos>
翻译:他 的 <unk> , 我 很 <unk><eos>输入: they made him do the work again . <eos>
标签:他們 要 他 再 做 一次 這個 工作 。 <eos>
翻译:他们 坚持 他 他 他 说 的 。 <eos>输入: he has great confidence in himself . <eos>
标签:他 对 自己 很 有 自信 。 <eos>
翻译:他 有 <unk><unk><eos>输入: i know tom can stop me from doing that . <eos>
标签:我 知道 汤姆 不能 阻止 我 做 那件事 。 <eos>
翻译:我 知道 汤姆 为什么 会 信任 我 做 。 <eos>输入: this hotel does not serve lunch . <eos>
标签:這家 旅館 不 提供 午餐 。 <eos>
翻译:這個 <unk> <unk> <unk><eos>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com