如何强制falcon 40B以JSON格式打印?

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

我一直在尝试使用 Falcon 40B 从输入文本中提取开始时间和结束时间。这是我的提示,

Identify the following items from the given text which states random shipping details: 
 start_time 
 end_time
The input text is delimited with triple backticks.
Convert your response to 24 hour clock format and Format your response as a JSON object
with "start_time" and "end_time" as the keys. That is, {"start_time" :"","end_time":""}.
If the information isn't present or incomplete information is present, 
set start time as 08:00 and end time as 16:00 as the values.

input text: ```start time is 04 am and end time is 5 pm```

我得到的输出是:“开始时间是 04:00,结束时间是 17:00。”

我尝试过https://huggingface.co/spaces/tiiuae/falcon-chat。尽管我提到了 JSON 格式,但它以自然语言提供输出。而且,每次刷新页面时输出都会发生变化。那么如何让 Falcon 40B 以 JSON 格式打印输出呢?

artificial-intelligence huggingface-transformers prompt llm falcon
1个回答
0
投票

您可以使用Guidance库。

来自其自述文件的“保证有效语法 JSON 示例”部分

大型语言模型非常擅长生成有用的输出,但它们并不擅长保证这些输出遵循特定的格式。当我们想要使用语言模型的输出作为另一个系统的输入时,这可能会导致问题。例如,如果我们想使用语言模型生成 JSON 对象,我们需要确保输出是有效的 JSON。在指导下,我们既可以加快推理速度,又可以确保生成的 JSON 始终有效。

而且,根据他们的自述文件,它提供了“与 Hugging Face 模型的轻松集成”。

© www.soinside.com 2019 - 2024. All rights reserved.