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

[BERT] support 2D attention mask #1226

Merged
merged 1 commit into from
Oct 25, 2021
Merged

[BERT] support 2D attention mask #1226

merged 1 commit into from
Oct 25, 2021

Conversation

JunnYu
Copy link
Member

@JunnYu JunnYu commented Oct 25, 2021

PR types

Bug fixes

PR changes

Models

Description

support 2D attention mask

@JunnYu
Copy link
Member Author

JunnYu commented Oct 25, 2021

BERT当前不支持2D的attention mask。

import paddle
from paddlenlp.transformers import BertModel,BertTokenizer

path = "bert-base-chinese"
model = BertModel.from_pretrained(path)
tokenizer = BertTokenizer.from_pretrained(path)
model.eval()

text = "欢迎使用paddlenlp!"
inputs = {
    kpaddle.tile(paddle.to_tensor(
        vdtype="int64").unsqueeze(0),[2,1])
    for kv in tokenizer(text,return_attention_mask=True).items()
}

with paddle.no_grad():
    hidden_states = model(**inputs)[0]

print(hidden_states.shape)

Copy link
Contributor

@yingyibiao yingyibiao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yingyibiao yingyibiao merged commit 089f8ae into PaddlePaddle:develop Oct 25, 2021
@JunnYu JunnYu deleted the bert_support_2D_attention_mask branch October 25, 2021 10:20
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

Successfully merging this pull request may close these issues.

None yet

2 participants