对于我的用例,我需要使用 model.forward() 而不是 model.generate() 方法,即代替下面的代码
outs = model.model.generate(input_ids=batch['source_ids'],
attention_mask=batch['source_mask'],
output_scores=True,
max_length=model.model_arguments.max_output_seq_length)
preds_cleaned = [model.tokenizer.decode(ids, skip_special_tokens=True, clean_up_tokenization_spaces=True) for ids in outs]
Run Code Online (Sandbox Code Playgroud)
我需要使用
model_outputs = model.model(
input_ids=batch["source_ids"],
attention_mask=batch["source_mask"],
labels=lm_labels.to(device),
decoder_attention_mask=batch['target_mask']
)
logits = model_outputs.logits
softmax_logits = m(logits)
max_logits = torch.max(softmax_logits, dim=2)
Run Code Online (Sandbox Code Playgroud)
解码这些 logits 会给出未处理的文本,该文本存在许多问题,例如末尾重复单词等。我需要做什么才能获得与 model.generate() 相同的结果?