当前位置: 首页 > news >正文

诸暨做网站游艇网站建设方案

诸暨做网站,游艇网站建设方案,青海政企网站建设,建设电影网站需要什么1--概述 1. 自回归 TransFormer 规定Token只能看到自身及前面的Token#xff0c;因此需生成一个符合规定的Attention Mask#xff1b;#xff08;代码提供了两种方式自回归Attention Mask的定义方式#xff09;#xff1b; 2. 使用Cross Attention实现条件模态和输入模态之…1--概述 1. 自回归 TransFormer 规定Token只能看到自身及前面的Token因此需生成一个符合规定的Attention Mask代码提供了两种方式自回归Attention Mask的定义方式         2. 使用Cross Attention实现条件模态和输入模态之间的模态融合输入模态作为Query条件模态作为Key和Value 2--代码 import torch import torch.nn as nnclass CrossAttention(nn.Module):def __init__(self, embed_dim: int, num_heads: int):super().__init__()self.cross_attn nn.MultiheadAttention(embed_dim, num_heads)def forward(self, input_x: torch.Tensor, condition: torch.Tensor, attn_mask: torch.Tensor None):query: input_xkey: conditionval: conditioninput_x self.cross_attn(input_x, condition, condition, attn_maskattn_mask)[0]return input_xclass Cond_Autoregressive_layer(nn.Module):def __init__(self, input_dim: int, condtion_dim: int, embed_dim: int, num_heads: int):super(Cond_Autoregressive_layer, self).__init__()self.linear1 nn.Linear(input_dim, embed_dim)self.linear2 nn.Linear(condtion_dim, embed_dim)self.cond_multihead_attn CrossAttention(embed_dim embed_dim, num_heads num_heads)def forward(self, input_x: torch.Tensor, conditon: torch.Tensor, attention_mask1: torch.Tensor, attention_mask2: torch.Tensor):# q, k, v, attention mask, here we set key and value are both condtion y1 self.cond_multihead_attn(self.linear1(input_x), self.linear2(conditon), attn_mask attention_mask1)y2 self.cond_multihead_attn(self.linear1(input_x), self.linear2(conditon), attn_mask attention_mask2)return y1, y2if __name__ __main__:# set sequence len, embedding dim, multi attention headseq_length 10input_dim 32condtion_dim 128embed_dim 64num_heads 8# init input sequence and condtioninput_x torch.randn(seq_length, 1, input_dim)condtion torch.randn(seq_length, 1, condtion_dim)# create two attention mask (actually they have the same function)attention_mask1 torch.triu((torch.ones((seq_length, seq_length)) 1), diagonal1) # bool typeattention_mask2 attention_mask1.float() # True-1 False-0attention_mask2 attention_mask2.masked_fill(attention_mask2 1, float(-inf)) # Convert ones to -inf# init modelAG_layer Cond_Autoregressive_layer(input_dim, condtion_dim, embed_dim, num_heads)# forwardy1, y2 AG_layer(input_x, condtion, attention_mask1, attention_mask2)# here we demonstrate the attention_mask1 and attention_mask2 have the same functionassert(y1[0].equal(y2[0]))
http://www.pierceye.com/news/873475/

相关文章:

  • 织梦网站环境搭建电子邮件怎么注册
  • 企业营销类专业网站app设计尺寸规范
  • 奈曼旗建设局网站建设旅游门户网站
  • 网站设计一般会遇到哪些问题wordpress文章关闭缩略图
  • 优质东莞网站制作公司thinkphp网站源码下载
  • 公司网站做一下多少钱最吉利旺财的公司名字
  • 网站建设维护及使用管理办法营销策划的步骤
  • 优秀网站设计案例在家开个人工作室违法吗
  • 腾讯云建设网站wordpress仿知乎社区
  • 《网站开发技术》模板linchong.wordpress
  • 找做企业网站论文旅游网站建设
  • 类似情侣空间的网站开发seo外推软件
  • 网站建设策划方案怎么写工业品网络营销
  • 上海本地网站建设微信网站怎么建设
  • 江苏华江建设集团网站wordpress开发找工作
  • 家政服务网站源码自己做网站好还是让别人做
  • 手机网站用什么系统做网站在什么地方发帖子呢
  • 虚拟电脑可以做网站吗中国建设行业信息网站
  • 网站设计建设合同公司网页设计实例教程
  • 仿起点小说网站开发网站图片优化工具
  • 在线做logo的网站泉州做网站哪家好
  • 知名企业网站人才招聘情况如何网络系统集成
  • 做灯带的网站重庆有哪些好玩的地方
  • 小孩子做手工做游戏的网站百度账号设置
  • 大庆做网站公司巩义网站建设方案报价
  • 该网站受海外服务器保护品牌营销型网站建设公司
  • 免费做一建或二建题目的网站郑州企业建站系统模板
  • 想自己建个网站徐州做网站软件
  • 蓝色系网站设计企业应对承包商的施工方案尤其是
  • 旅游网站 源码 织梦导购网站开发