Langchain使用Huggingface进行嵌入,无法通过访问令牌。

huangapple go评论251阅读模式
英文:

langchain emedding with huggingface can't pass the access token

问题

我正在使用llama_index和langchain创建文档索引。
对于嵌入,我想使用<https://huggingface.co/bert-base-multilingual-cased>。
使用以下代码创建嵌入没有问题:

  1. from langchain.embeddings.huggingface import HuggingFaceEmbeddings
  2. from llama_index import LangchainEmbedding, ServiceContext
  3. embed_model = LangchainEmbedding(
  4. HuggingFaceEmbeddings(model_name="bert-base-multilingual-cased")
  5. )
  6. service_context = ServiceContext.from_defaults(embed_model=embed_model)

我的问题是,我不知道如何在请求模型时使用我的HF访问令牌。我想使用访问令牌是因为1)HF文档建议使用它,2)我可能会使用HF Pro计划以获得更高的API速率限制。

英文:

I am creating an index of documents with llama_index and langchain.
For the embedding I want to use <https://huggingface.co/bert-base-multilingual-cased>.
I had no problem creating the embedding using the following code:

  1. from langchain.embeddings.huggingface import HuggingFaceEmbeddings
  2. from llama_index import LangchainEmbedding, ServiceContext
  3. embed_model = LangchainEmbedding(
  4. HuggingFaceEmbeddings(model_name=&quot;bert-base-multilingual-cased&quot;)
  5. )
  6. service_context = ServiceContext.from_defaults(embed_model=embed_model)

my problem is that I don't understand how to use my HF access token when requesting the model. I want to use the access token because 1) it is suggested by the HF documentation and 2) I will probably use the HF Pro Plan in order to have an higher api rate limit.

答案1

得分: 0

我认为你不能在langchain.embeddings.HuggingfaceEmbeddings中使用授权令牌,但如果你需要使用授权令牌,你可以使用Hugging Face Hub。

  1. from langchain.embeddings import HuggingFaceHubEmbeddings
  2. embeddings = HuggingFaceHubEmbeddings(repo_id='path/to/repo',
  3. huggingfacehub_api_token='API_TOKEN')
英文:

I think you can't use authorization tokens in langchain.embeddings.HuggingfaceEmbeddings but you can surely use hugging face hub if you need to use the authorization tokens.

  1. from langchain.embeddings import HuggingFaceHubEmbeddings
  2. embeddings = HuggingFaceHubEmbeddings(repo_id=&#39;path/to/repo&#39;,
  3. huggingfacehub_api_token=&#39;API_TOKEN&#39;)

huangapple
  • 本文由 发表于 2023年8月9日 00:29:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76861517.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定