乱码怎么处理

#9
by cell22 - opened

查询词元

def ciyuan():
tokenizer = AutoTokenizer.from_pretrained("./DeepSeek-R1-Distill-Qwen-7B")

# 示例词元 ID 列表
input_ids_list = [107, 99260]

# 示例词元 ID 张量
input_ids_tensor = torch.tensor([107])

# 检查词元 ID 是否在词表中
for input_id in input_ids_list:
    if input_id not in tokenizer.get_vocab().values():
        print(f"词元 ID {input_id} 不在词表中。")

# 解码操作
decoded_text_from_list = tokenizer.decode(input_ids_list, skip_special_tokens=True)
decoded_text_from_tensor = tokenizer.decode(input_ids_tensor, skip_special_tokens=True)

print(f"从列表解码得到的文本: {decoded_text_from_list}")
print(f"从张量解码得到的文本: {decoded_text_from_tensor}")

结果
从列表解码得到的文本: �较
从张量解码得到的文本: �

Sign up or log in to comment