05 Inferring
本节主要介绍inferring(文本推理)任务,可以视为对输入文本的理解和分析任务,包含文本分类、理解情感等。
1) 简单的分类任务
给定一段关于灯的评论
lamp_review = """
Needed a nice lamp for my bedroom, and this one had \
additional storage and not too high of a price point. \
Got it fast. The string to our lamp broke during the \
transit and the company happily sent over a new one. \
Came within a few days as well. It was easy to put \
together. I had a missing part, so I contacted their \
support and they very quickly got me the missing piece! \
Lumina seems to me to be a great company that cares \
about their customers and products!!
"""
response = get_completion(prompt)
print(response)
现在我们要模型给出该段评论的情感,我们可以使用下述prompt输入模型。
`prompt = f"""
What is the sentiment of the following product review,
which is delimited with triple backticks?
Review text: '''{
lamp_review}'''
"""
模型会得到"The sentiment of the product review is positive"。如果我们只想得到一个情感分类,方便后续处理,我们可以直接将希望得到的分类标签规定在prompt中:
`prompt =