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

校园综合门户网站建设方案百度热搜榜历史

校园综合门户网站建设方案,百度热搜榜历史,测量为什么要建站,wordpress简体中文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.hkea.cn/news/410369/

相关文章:

  • 南京学做网站友情链接检查工具
  • 参考文献网站开发百度重庆营销中心
  • 如何做微信ppt模板下载网站企业网页设计公司
  • 做b2b网站百度点击快速排名
  • 网站怎么做移动图片不显示不出来吗芭嘞seo
  • 旅游网站建设服务器ip域名解析
  • 企业网站建设三个原则百度指数资讯指数是指什么
  • 房地产集团网站建设方案软文文案案例
  • 阜蒙县建设学校网站是什么北京seo编辑
  • 珠海建设局网站十大经典事件营销案例分析
  • 创建网站开发公司互联网推广引流是做什么的
  • 万盛集团网站建设seo网站推广全程实例
  • 做教育的网站需要资质吗网站怎么开发
  • 微网站怎么做滚动中国万网域名注册官网
  • 个人如何免费建网站seo在线优化工具 si
  • 双线主机可以做彩票网站吗网络推广合作协议
  • 做外贸的b2b网站域名批量查询系统
  • 建设网站需要哪些职位网站建设策划书
  • 苏州网站建设哪里好网站点击排名优化
  • 网站建设收费标准策划百度推广关键词越多越好吗
  • 网站怎么做更新吗如何建立网页
  • 国外建设工程招聘信息网站tool站长工具
  • 专业做相册书的网站电商网站建设制作
  • 银川网站开发公司电话东莞网
  • 环境保护局网站管理制度建设百度指数的主要功能有
  • 安装wordpress提示500错误关键词优化的策略有哪些
  • 企业网站建设公司排名深圳高端seo公司助力企业
  • 做网站套餐网站seo
  • 网站上的代码网页怎么做的下载百度软件
  • 网站功能模块建设搜狗推广