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

关于输出每个word的embedding #1

Open
ECNU109 opened this issue Nov 26, 2019 · 1 comment
Open

关于输出每个word的embedding #1

ECNU109 opened this issue Nov 26, 2019 · 1 comment

Comments

@ECNU109
Copy link

ECNU109 commented Nov 26, 2019

作者您好,请问使用您的代码应该如何改写能输出最终fine-tune的模型中的word embedding呢?
另外我注意到您没有进行分词,是一个中文字为单位,如果想使用字的embedding得到一个词汇的embedding,请问有什么比较好的方式么?谢谢!

@yao8839836
Copy link
Owner

@ECNU109

您好,个人认为最简单的方法是将单词用[CLS]和[SEP]包装起来(例如,如[CLS]头痛[SEP])传入预训练的BERT,然后将[CLS]的最后一层embedding作为词汇的embedding。

此外,可以参考bert-as-service的计算方式:

Q: How do you get the fixed representation? Did you do pooling or something?
A: Yes, pooling is required to get a fixed representation of a sentence. In the default strategy REDUCE_MEAN, I take the second-to-last hidden layer of all of the tokens in the sentence and do average pooling.

这里的sentence也可以是词汇。

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

1 participant