我对huggingface的distillBERT工作很感兴趣,通过查看他们的代码(https://github.com/huggingface/transformers/blob/master/examples/distillation/train.py),我发现如果使用roBERTa作为学生模型,他们会冻结位置嵌入,我想知道这是为了什么?
def freeze_pos_embeddings(student, args):
if args.student_type == "roberta":
student.roberta.embeddings.position_embeddings.weight.requires_grad = False
elif args.student_type == "gpt2":
student.transformer.wpe.weight.requires_grad = False我理解冻结token_type_embeddings的原因,因为roBERTa从来不使用段嵌入,但是为什么是位置嵌入呢?
非常感谢你的帮助!
发布于 2020-03-23 16:05:47
在大多数(甚至所有)常用的Transformers中,位置嵌入不是经过训练的,而是使用分析描述的函数( Attention is all you need论文第6页上的未编号方程)定义的:

为了节省Transformer package中的计算时间,它们被预先计算到512的长度,并存储为用作缓存的变量,该缓存在训练期间不应改变。
不训练位置嵌入的原因是,后面位置的嵌入将训练不足,但通过巧妙地解析定义的位置嵌入,网络可以学习方程背后的规律性,并更容易对更长的序列进行推广。
https://stackoverflow.com/questions/60772384
复制相似问题