ERNIE icon indicating copy to clipboard operation
ERNIE copied to clipboard

ERINE-doc调用

Open xiankangW-gi opened this issue 11 months ago • 1 comments

在使用demo时: import numpy as np import paddle from paddlenlp.transformers import ErnieDocModel from paddlenlp.transformers import ErnieDocTokenizer

def get_related_pos(insts, seq_len, memory_len=128): beg = seq_len + seq_len + memory_len r_position = [list(range(beg - 1, seq_len - 1, -1)) +
list(range(0, seq_len)) for i in range(len(insts))] return np.array(r_position).astype('int64').reshape([len(insts), beg, 1])

tokenizer = ErnieDocTokenizer.from_pretrained('ernie-doc-base-zh') model = ErnieDocModel.from_pretrained('ernie-doc-base-zh')

inputs = tokenizer("长文本") inputs = {k:paddle.to_tensor([v + [0] * (128-len(v))]).unsqueeze(-1) for (k, v) in inputs.items()}

memories = [paddle.zeros([1, 128, 768], dtype="float32") for _ in range(12)] position_ids = paddle.to_tensor(get_related_pos(inputs['input_ids'], 128, 128)) attn_mask = paddle.ones([1, 128, 1])

inputs['memories'] = memories inputs['position_ids'] = position_ids inputs['attn_mask'] = attn_mask

outputs = model(**inputs)

encoder_output = outputs[0] pooled_output = outputs[1] new_mem = outputs[2] 请问ERINE-doc不是号称可以处理长文本吗 为什么在当输出文本超过512tokens时 依然出现:Token indices sequence length is longer than the specified maximum sequence length for this model (566 > 512). Running this sequence through the model will result in indexing errors

xiankangW-gi avatar Dec 14 '24 15:12 xiankangW-gi

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Feel free to reopen it. Thank you for your contributions.

stale[bot] avatar Apr 26 '25 03:04 stale[bot]