为什么LLMChain的答案被砍掉了?

问题描述 投票:0回答:1

我想使用 Huggingface API 和 Gemma 模型构建一个问答应用程序,但模型提供的答案被切断了。我在 Google Colab 和 Kaggle 笔记本上尝试过,但它总是被切断。这可能是什么原因?

这是我的代码;

from dotenv import load_dotenv
from langchain_community.llms import HuggingFaceHub
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate

//Loaded api key
load_dotenv()
//Models name
hub_llm = HuggingFaceHub(repo_id="google/gemma-1.1-7b-it")

prompt = PromptTemplate(
    input_variables=["text-generation"],
    template="Text generation :{text-generation}"
    )

hub_chain = LLMChain(prompt=prompt,llm =hub_llm,verbose=True)
print(hub_chain.run("How does the brain work ? "))

输出看起来像这样:enter image description here

还在kaggle/colab笔记本中尝试过:enter image description here

我该怎么办?

python nlp huggingface-transformers langchain nlp-question-answering
1个回答
0
投票

我通过更改此代码解决了问题;

hub_llm = HuggingFaceHub(repo_id="google/gemma-1.1-7b-it") 
to
hub_llm = HuggingFaceHub(repo_id="google/gemma-1.1-7b-it", model_kwargs={'temperature':0.8, 'max_new_tokens':2000})
© www.soinside.com 2019 - 2024. All rights reserved.