1 安装依赖包
pip install sentence_transformers
pip install langchain_huggingface
2 代码
from langchain_huggingface.embeddings import HuggingFaceEmbeddings
def use_m3e_embedding():
# 定义向量模型路径
EMBEDDING_MODEL = "moka-ai/m3e-base"
# 第三步:初始化 hugginFace 的 embeddings 对象
embeddings = HuggingFaceEmbeddings(model_name=EMBEDDING_MODEL)
print(embeddings)
3 出现以下错误
RuntimeError: Failed to import transformers.trainer because of the following error (look up to see its traceback): cannot import name 'is_npu_available' from 'accelerate.utils'
(X:\LearningSoftware\Anaconda\install\envs\myllm\lib\site-packages\accelerate\utils\__init__.py)
出错原因:transformers和accelerate包出现了冲突
解决方案
pip uninstall accelerate
pip install accelerate
就可以正常加载本地Embedding模型了
4192

被折叠的 条评论
为什么被折叠?



