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

Update BERT.py #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions 5-2.BERT/BERT.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ def forward(self, input_ids, segment_ids, masked_pos):
optimizer = optim.Adam(model.parameters(), lr=0.001)

batch = make_batch()
input_ids, segment_ids, masked_tokens, masked_pos, isNext = map(torch.LongTensor, zip(*batch))
if torch.cuda.is_available():
input_ids, segment_ids, masked_tokens, masked_pos, isNext = map(torch.cuda.LongTensor, zip(*batch))
else:
input_ids, segment_ids, masked_tokens, masked_pos, isNext = map(torch.LongTensor, zip(*batch))
Comment on lines +212 to +215

Choose a reason for hiding this comment

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

The code you modified is incorrect


for epoch in range(100):
optimizer.zero_grad()
Expand All @@ -224,7 +227,10 @@ def forward(self, input_ids, segment_ids, masked_pos):
optimizer.step()

# Predict mask tokens ans isNext
input_ids, segment_ids, masked_tokens, masked_pos, isNext = map(torch.LongTensor, zip(batch[0]))
if torch.cuda.is_available():
input_ids, segment_ids, masked_tokens, masked_pos, isNext = map(torch.cuda.LongTensor, zip(batch[0]))
else:
input_ids, segment_ids, masked_tokens, masked_pos, isNext = map(torch.LongTensor, zip(batch[0]))
Comment on lines +230 to +233

Choose a reason for hiding this comment

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

The code you modified is incorrect

print(text)
print([number_dict[w.item()] for w in input_ids[0] if number_dict[w.item()] != '[PAD]'])

Expand Down