shibing624 / text2vec

text2vec, text to vector. 文本向量表征工具,把文本转化为向量矩阵,实现了Word2Vec、RankBM25、Sentence-BERT、CoSENT等文本表征、文本相似度计算模型,开箱即用。
https://pypi.org/project/text2vec/
Apache License 2.0
4.46k stars 396 forks source link

模型离线使用 #116

Closed Huanyongji closed 1 year ago

Huanyongji commented 1 year ago

Describe the Question

如题,下载的模型如何在不联网的情况下使用呢?我现在已经把模型下载到本地,但是加载模型的时候要进行联网操作,机器又没法联网,请问这块该怎么解决呢?谢谢

shibing624 commented 1 year ago

指定模型路径为下载后的绝对路径。

yousenwang commented 1 year ago
from torch.hub import _get_torch_home

_get_torch_home()

'/root/.cache/torch'


from langchain.embeddings import HuggingFaceInstructEmbeddings

instructor_embeddings = HuggingFaceInstructEmbeddings(model_name="/root/.cache/torch/sentence_transformers/GanymedeNil_text2vec-large-chinese",
                                                      # local_files_only=True,
                                                      model_kwargs={"device": "cuda"})

Sources: https://api.python.langchain.com/en/latest/_modules/langchain/embeddings/huggingface.html#HuggingFaceInstructEmbeddings https://github.com/UKPLab/sentence-transformers/blob/master/sentence_transformers/SentenceTransformer.py