Closed yyuan312 closed 6 months ago
看了下模型结构是XLMRoberta,已经支持了,能给个环境我验一下不
好的,下午我也搞个环境发给你哈,十分感谢
---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年03月08日 11:38 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [mindspore-lab/mindnlp] bce-embedding-base_v1 模型迁移到910B上 (Issue #897) |
看了下模型结构是XLMRoberta,已经支持了,能给个环境我验一下不
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
好的,下午我也搞个环境发给你哈,十分感谢
---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年03月08日 11:38 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [mindspore-lab/mindnlp] bce-embedding-base_v1 模型迁移到910B上 (Issue #897) |
看了下模型结构是XLMRoberta,已经支持了,能给个环境我验一下不
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
加下QQ群吧: 742130668
import mindspore from mindspore import Tensor from mindnlp.transformers import AutoModel, XLMRobertaTokenizer from mindnlp.transformers import *
model = AutoModel.from_pretrained('/home/ma-user/work/bce-embedding-base_v1') tokenizer = XLMRobertaTokenizer.from_pretrained('/home/ma-user/work/bce-embedding-base_v1')
def predict_with_model(text): label_map = {0: "消极", 1: "中性", 2: "积极"}
# 对文本进行tokenize
text_tokenized = tokenizer(text, padding=True, truncation=True, max_length=64, return_tensors='np')
# 转换为mindspore tensor
input_ids = Tensor(text_tokenized['input_ids'])
attention_mask = Tensor(text_tokenized['attention_mask'])
# 模型推理
logits = model(input_ids, attention_mask)
# 获取预测结果
predict_label = logits[0].asnumpy().argmax()
return label_map[predict_label]
infer_text = "家人们咱就是说一整个无语住了 绝绝子叠buff" predicted_label = predict_with_model(infer_text) print(f"输入文本: '{infer_text}',预测情感: '{predicted_label}'") 这个推理代码 ,到最后 报错:
predicted_label = predict_with_model(infer_text) \
Traceback (most recent call last): File "
", line 1, in File " ", line 8, in predict_with_model KeyError: 14412
你这个代码有问题,这个模型输出是词向量,我测了一下模型完全支持,把你最终想要实现的效果对应的pytorch代码发一下
郑州智算项目 要把https://huggingface.co/maidalun1020/bce-embedding-base_v1 模型迁移到npu上 , bce-embedding-base_v1的介绍在https://github.com/netease-youdao/BCEmbedding/blob/master/README_zh.md