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

使用avg pooling生成句子嵌入时,是否应该加入attention mask做平均 #13

Open
zchuz opened this issue Apr 7, 2022 · 1 comment

Comments

@zchuz
Copy link

zchuz commented Apr 7, 2022

if pooling == 'first_last_avg':
    output_hidden_state = (hidden_states[-1] + hidden_states[1]).mean(dim=1)
if pooling == 'first_last_avg':
    hidden = (hidden_states[-1] + hidden_states[1]) / 2
    output_hidden_state = (hidden * att_mask.unsqueeze(-1)).sum(1) / att_mask.sum(-1).unsqueeze(-1)
@ysngki
Copy link

ysngki commented Jan 1, 2023

由all_utils.py的sent_to_vec可知,数据是一句一句单独地进行tokenization,没有对齐的需要,所以是没有padding token的。
不过这么做计算很慢,如果要改成整个batch一起tokenization然后编码的话,还是要用attention mask来过滤padding的。亲测前后结果差距很大。

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