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

新网备案成功了怎么做网站公司网页制作教程

新网备案成功了怎么做网站,公司网页制作教程,如何用织梦cms做网站,网站开发和手机开发哪个好1--概述 1. 自回归 TransFormer 规定Token只能看到自身及前面的Token,因此需生成一个符合规定的Attention Mask;(代码提供了两种方式自回归Attention Mask的定义方式); 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: condition'''input_x = self.cross_attn(input_x, condition, condition, attn_mask=attn_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), diagonal=1) # 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.tj-hxxt.cn/news/78948.html

相关文章:

  • 网站备案为什么这么慢现在怎么做网络推广
  • 网站备案 抽查广州市运营推广公司
  • 网站维护教程资源优化网站排名
  • 买服务器的网站市场推广策略 包括哪些
  • 订单网站怎么做百度登录
  • 开发网站需要什么条件熊猫seo实战培训
  • 英语做课后作业的网站品牌宣传推广策划方案
  • 成都房屋设计公司哪家好爱站网seo工具
  • 公会网站建设seo联盟
  • 招聘 网站开发seo描述是什么意思
  • 网站建设 网页设计 的文章百度最新秒收录方法2022
  • 网站报价模板微信小程序开发流程
  • 如何在百度上做公司网站南昌seo管理
  • linux wordpress建站教程seo优化资源
  • 长春最专业的网站建设百度人工客服
  • html5网站自适应seo推广培训学费
  • 做网站的软件项目进度计划广东广州疫情最新情况
  • 做地方网站赚钱吗郑州百度seo排名公司
  • 大连开发区凯旋国际厦门seo排名收费
  • 网站模板怎样在本地测试培训心得体会1000字
  • 邵东做网站百度公司电话是多少
  • 沧州网站优化公司网上竞价平台
  • 昆山市建设工程交易中心网站电商网站卷烟订货流程
  • 网站制作加谷歌推广站长之家是干什么的
  • 如何用frontpage做网站社群营销成功案例
  • 网站后台登录地址seo 最新
  • 做拍卖的网站有哪些优化网站关键词排名软件
  • 做浏览单的网站百度实名认证
  • 静态网页扩展名东莞seo优化排名
  • 绵阳网站建设培训学校长沙优化排名推广