首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用抱脸移相器GPT-2进行分类任务

用抱脸移相器GPT-2进行分类任务
EN

Stack Overflow用户
提问于 2019-07-29 06:16:27
回答 1查看 833关注 0票数 1

我想使用GPT-2来建立一个文本分类器模型.我不太确定在通过GPT-2提取特征之后,我应该添加什么头。为了以身作则我有一个序列。

代码语言:javascript
运行
复制
import pytorch_transformers as pt 
import torch
text=test.iloc[1,1]
text
'If a fire wanted fanning, it could readily be fanned with a newspaper, and as the government grew weaker, I have no doubt that leather and iron acquired durability in proportion, for, in a very short time, there was not a pair of bellows in all Rotterdam that ever stood in need of a stitch or required the assistance of a hammer.'
len(text)

74
tokenizer = pt.GPT2Tokenizer.from_pretrained('gpt2')
model = pt.GPT2Model.from_pretrained('gpt2')
zz = tokenizer.tokenize(text)
z1=torch.tensor([tokenizer.convert_tokens_to_ids(zz)])
z1
tensor([[ 1532,   257,  2046,  2227,  4336,   768,    11,   340,   714, 14704,
           307,   277,  3577,   351,   257,  7533,    11,   290,   355,   262,
          1230,  6348, 17642,    11,   314,   423,   645,  4719,   326, 11620,
           290,  6953,  9477, 26578,   287,  9823,    11,   329,    11,   287,
           257,   845,  1790,   640,    11,   612,   373,   407,   257,  5166,
           286,  8966,  1666,   287,   477, 18481,   353, 11043,   326,  1683,
          6204,   287,   761,   286,   257, 24695,   393,  2672,   262,  6829,
           286,   257, 15554,    13]])
output,hidden=model(z1)
ouput.shape
torch.Size([1, 74, 768])

GPT2的输出为nxmx768,其中n是批大小,m是序列中的令牌数(例如,我可以将其压缩/截断到128个),所以我不能像论文所说的那样在tail.And上搜索到的tail.And中添加一个完全连接的层,很少修改GPT-2分类任务。我不知道什么是正确的。我应该在完全连接的层之前做平/最大池/平均池吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-07 04:51:25

“所以,我不能像论文所说的那样,在尾部添加一个完全连接的层。”--,这是对你的问题的回答。

通常,像伯特和罗伯塔这样的变压器具有双向自我关注,并且它们有CLS令牌,我们可以在这里输入类词。由于GPT-2是左-右,所以需要为嵌入序列提供最后的令牌。

你能把链接放到报纸上吗。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57248098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档