جواب «Few-Shot Builder» چالش 3 از جلسهی 62
سؤال
تابع few_shot(examples, question) را کامل کن: برای هر جفت (review, label) دو خط Review: ... و Label: ... بسازد، آخر کار سؤال جدید را با Label: خالی اضافه کند و همه را با خط جدید ("\n") به هم بچسباند. خروجی باید این ۸ خط باشد:Review: The new level is amazing!Label: positiveReview: It keeps crashing on my phone.Label: negativeReview: Graphics are okay, music is great.Label: positiveReview: Too many ads, I deleted it.Label:
راهنما
lines.append("Review: " + review) و lines.append("Label: " + label). بعد از حلقه همین کار را برای question بکن، با "Label:" تنها.
یک جواب درست
def few_shot(examples, question):
lines = []
for review, label in examples:
lines.append("Review: " + review)
lines.append("Label: " + label)
lines.append("Review: " + question)
lines.append("Label:")
return "\n".join(lines)
examples = [
("The new level is amazing!", "positive"),
("It keeps crashing on my phone.", "negative"),
("Graphics are okay, music is great.", "positive"),
]
print(few_shot(examples, "Too many ads, I deleted it."))
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن