Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

可否提供Retrieval QA问答的prompt #26

Closed
jieniu opened this issue Jul 7, 2023 · 2 comments
Closed

可否提供Retrieval QA问答的prompt #26

jieniu opened this issue Jul 7, 2023 · 2 comments
Assignees

Comments

@jieniu
Copy link

jieniu commented Jul 7, 2023

感谢开源!

我想做一组Retrieval QA的测试,请问用什么prompt比较合适,我试了几个prompt都不太好,比如下面这个internLM-7b-chat会用英文来回答,而直接使用chat接口回答都很简短。

    prompt_template = f"""User: 已知信息:
{context}

根据上述已知信息,专业的回答用户的问题。如果无法从中得到答案,请说 “抱歉,根据已知信息无法回答该问题”,不允许在答案中添加编造成分,答案请使用中文。

问题:{question}

Assistant:"""
@Leymore
Copy link

Leymore commented Jul 10, 2023

Hope this would work for you:

context = """意大利大道(Boulevard des Italiens)是巴黎东西走向连贯的四条“grands boulevards”之一,自西向东包括马德莱娜大道、卡布辛大道(Boulevard des Capucines)、意大利大道和蒙马特大道。它得名于法国革命前不久的1783年建于此处的意大利剧院(现在的巴黎喜剧院)。此前使用过的名称有boulevard Neuf、boulevard du Dépôt、boulevard de la Chaussée d'Antin、boulevard Cerutti(法国革命期间)、根特大道(boulevard de Gand,1815 - 1828年)。1795年后,许多流亡者在督政府时期从国外返回法国,聚集于此,使它获得“小科布伦茨”的绰号。第二次波旁复辟时称为根特大道(boulevard de Gand),以纪念路易十八在百日王朝时流亡到根特。在整个19世纪,这条大道是一巴黎精英们的聚会场所(这一角色一直持续到第一次世界大战),当时也是巴黎咖啡馆和杜昂咖啡馆(Tortoni,布宜诺斯艾利斯的那座也得名于巴黎的这座)的时代。奥斯曼大道在1920年代完成后,这些建筑消失了,被代之以其他建筑物,特别是财政方面的-法国巴黎银行总部,约瑟夫·马拉斯特设计。"""
questions = [
    "意大利大道属于哪个国家?",
    "“小科布伦茨”这一绰号有什么由来?",
    "意大利大道上现在有多少家咖啡店?",
]

from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("internlm/internlm-chat-7b", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("internlm/internlm-chat-7b", trust_remote_code=True).cuda()
model = model.eval()

prompt_template = """假设你是一个智能助理,你希望能够回答用户的问题,用户的问题可能是任意的,但是你只能使用以下信息来回答用户的问题:
{context}

你的回答应该是一个完整的句子,你需要首先正面回答用户的问题,同时提供尽可能充分的细节,你需要表现地足够热情、友善。如果无法从中得到答案,请说 “抱歉,根据已知信息无法回答该问题”,不允许在答案中添加编造成分,答案请使用中文。

以下是用户的问题:请问{question}"""

for question in questions:
    prompt = prompt_template.format(context=context, question=question)
    response, history = model.chat(tokenizer, prompt, history=[])
    print(question + '\n' + response)
意大利大道属于哪个国家?
意大利大道是巴黎东西走向连贯的四条“grands boulevards”之一,位于法国。
“小科布伦茨”这一绰号有什么由来?
1795年后,许多流亡者在督政府时期从国外返回法国,聚集于此,使它获得“小科布伦茨”的绰号。
意大利大道上现在有多少家咖啡店?
抱歉,根据已知信息无法回答该问题

@tonysy
Copy link
Collaborator

tonysy commented Jul 10, 2023

Feel free to re-open this issue if you have more questions, also more useful prompts are welcomed.

@tonysy tonysy closed this as completed Jul 10, 2023
li126com pushed a commit to li126com/InternLM that referenced this issue Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants