bert4torch
bert4torch copied to clipboard
self.random_sample和 self.beam_search返回值tensor未统一转化numpy,导致两函数同时调用报错
提问时请尽可能提供如下信息:
基本信息
- 你使用的操作系统: win0
- 你使用的Python版本: 3.10
- 你使用的Pytorch版本: 2.1
- 你使用的bert4torch版本:
- 你加载的预训练模型:
核心代码
# 请在此处贴上你的核心代码
def generate(self, passage, topk=1, topp=0.95): token_ids, segment_ids = tokenizer.encode(passage, maxlen=max_p_len) a_ids = self.random_sample([token_ids, segment_ids], n=1, topp=topp)[0] # 基于随机采样 token_ids += list(a_ids) segment_ids += [1] * len(a_ids) q_ids = self.beam_search([token_ids, segment_ids], topk=topk)[0] # 基于beam search return (tokenizer.decode(q_ids.cpu().numpy()), tokenizer.decode(a_ids.cpu().numpy()))
输出信息
# 请在此处贴上你的调试输出
Traceback (most recent call last):
File "F:\project\code\python\bert4torch\examples\seq2seq\task_question_answer_generation_by_seq2seq.py", line 191, in
自我尝试
此处请贴上你的自我尝试过程 def generate(self, passage, topk=1, topp=0.95): token_ids, segment_ids = tokenizer.encode(passage, maxlen=max_p_len) a_ids = self.random_sample([token_ids, segment_ids], n=1, topp=topp)[0] # 基于随机采样 # return tokenizer.decode(a_ids.cpu().numpy()) a_ids = a_ids.cpu().numpy() #这里需要转化成numpy token_ids += list(a_ids) segment_ids += [1] * len(a_ids) q_ids = self.beam_search([token_ids, segment_ids], topk=topk)[0] # 基于beam search # return tokenizer.decode(q_ids.cpu().numpy()) return (tokenizer.decode(q_ids.cpu().numpy()), tokenizer.decode(a_ids))#