Skip to content

Commit 55917af

Browse files
committed
updates
1 parent fcc0be8 commit 55917af

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/MMLLM/庖丁解牛BLIP2.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,11 +552,14 @@ class BertEncoder(nn.Module):
552552
...
553553
##================= Image Captioning ========================##
554554
decoder_input_ids = text_tokens.input_ids.clone()
555+
# 将第一个 token 替换为 BOS(Begin Of Sentence)标记,表示“开始生成句子”
555556
decoder_input_ids[:, 0] = self.tokenizer.bos_token_id
557+
# 将 padding token 替换为 -100,这是 CrossEntropyLoss 默认忽略的标签值
556558
labels = decoder_input_ids.masked_fill(
557559
decoder_input_ids == self.tokenizer.pad_token_id, -100
558560
)
559-
561+
562+
560563
query_atts = torch.ones(query_tokens.size()[:-1], dtype=torch.long).to(
561564
image.device
562565
)

0 commit comments

Comments
 (0)