pytorch - 如何在 BERT 模型上添加 Sequentilal CNN 层?
问题描述
信息
我正在处理二进制分类任务,并使用变压器库中的BERT模型使用下面的自定义模型来完成它:
class BERT(nn.Module):
def __init__(self):
super(BERT, self).__init__()
self.bert = BertModel.from_pretrained(BERT_PATH, return_dict=False)
self.dropout = nn.Dropout(0.2)
self.out = nn.Linear(768, 1)
def forward(self, ids, mask, token_type_ids):
outputs = self.bert(ids, attention_mask=mask,token_type_ids=token_type_ids)
# Use the pooled output
output = self.dropout(outputs[1])
return self.out(output)
我在找什么?
现在我希望CNN
在上面使用BERT
具有以下配置的层来查看我的模型将如何执行:
self.cnn = nn.Sequential(
nn.Conv2d(? ? ?),
nn.ReLU(),
nn.MaxPool2d(? ? ?)
)
遇到的问题。
我已经尝试过,但在设置尺寸方面遇到了错误。您认为我应该在顺序模型中放置什么配置以避免调整尺寸的问题?如果您可以复制粘贴我的代码并为我提供包含正确顺序模型的最终自定义模型,我将不胜感激。
解决方案
推荐阅读
- swift - 如何将 XMLDocument 分解为更小的部分,以便在 Swift 中使用 XPath 进行处理?
- css - 在overflow-x的父元素下定位粘性元素:auto
- python - Python:用 0 替换空值
- java - 用户是否可以在给定时间重复外部方法调用
- sql - 该列是否应该属于主键并且可以为空?
- data-binding - UWP:如果以编程方式填充 NavigationView.MenuItems 结果为空
- sql - 对 R studio 代码进行 WINdow SQL 查询
- node.js - Sequelize 同步复制现有的外键关联
- wordpress - wordpress 网站进入 iframe 登录页面无法正常工作获取 cookie 错误
- node.js - 在 ReactNative 中使用“net”Node.js 模块