Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RobertaPromptForSequenceClassification 代码实现问题 #47

Open
nongfang55 opened this issue Feb 12, 2023 · 3 comments
Open

RobertaPromptForSequenceClassification 代码实现问题 #47

nongfang55 opened this issue Feb 12, 2023 · 3 comments

Comments

@nongfang55
Copy link

RobertaPromptForSequenceClassification 中的实现原理,大致是单独把RobertaModel 中的 RobertaEmbeddings 拿出来。然后tokenize 过的输入通过 RobertaEmbeddings 获得输入embedding,再拼上 prompt 的 embedding 过 RobertaEncoder。

不过单独拎出来的输入embedding,之前经过RobertaEmbedding时候,已经经过了word、pos、type的embedding相加和LN、drop的过程。而以inputs_embeds为参数输入 RobertaModel 之后,似乎会再次经过上述的操作。

是不是我理解的不对?不然按照我的理解,这么实现好像是有问题的?

@Xiao9905
Copy link
Member

@nongfang55 你好,P-tuning v2中的prompt embeddings是通过past_key_value方式传入每一层进行计算的。具体可以看这一行代码,并非是要通过RobertaEmbedding。

@nongfang55
Copy link
Author

@Xiao9905 感谢回复, P-tuning v2(RobertaPrefixForSequenceClassification)的实现确实如你所说,没有问题。

我所疑问的点是用于对比的P-tuning v1的代码 (RobertaPromptForSequenceClassification), 这里

@Xiao9905
Copy link
Member

@nongfang55 你好,

是的。这里的实现有一些问题,应该使用self.roberta.embeddings.word_embeddings来获取inputs_embeddings。感谢指出,我们会更新这部分的代码。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants