Step 3: Accuracy and Mistakes چالش 3 از جلسهی 36، متوسط
قدم ۳. حالا آزمون منصفانه روی TEST: برای هر (text, label)، حدس "kind" است اگر score >= 0، وگرنه "unkind". درستها را بشمار و متن اشتباهها را در لیست mistakes بگذار. چاپ کن right: 9 of 10 و بعد هر اشتباه با mistake:. (چاپ سه نظر نمونهی قدم ۲ را برداشتهایم.) به اشتباهها نگاه کن: چرا ابزار گول خورد؟
TRAIN = [
("great game i love it", "kind"), ("so fun and so cool", "kind"), ("nice colors", "kind"),
("amazing work", "kind"), ("i love the music", "kind"), ("this is so cool", "kind"),
("great idea", "kind"), ("fun level and nice music", "kind"), ("thanks for sharing", "kind"),
("cool game well done", "kind"), ("the art is beautiful", "kind"), ("so funny i love it", "kind"),
("well done great job", "kind"), ("nice and fun", "kind"), ("the best game ever", "kind"),
("i like the colors", "kind"), ("beautiful work thanks", "kind"), ("very cool idea", "kind"),
("fun fun fun", "kind"), ("good job", "kind"),
("this is boring", "unkind"), ("so stupid", "unkind"), ("worst game ever", "unkind"),
("ugly colors", "unkind"), ("i hate it", "unkind"), ("boring and slow", "unkind"),
("lame idea", "unkind"), ("this is dumb", "unkind"), ("you are a loser", "unkind"),
("the music is awful", "unkind"), ("so slow and boring", "unkind"), ("terrible game", "unkind"),
("ugly and stupid", "unkind"), ("i hate this game", "unkind"), ("worst idea", "unkind"),
("dumb level", "unkind"), ("boring music", "unkind"), ("awful art", "unkind"),
("this game is lame", "unkind"), ("so bad", "unkind"),
]
TEST = [
("i love the art", "kind"), ("boring level", "unkind"), ("cool music", "kind"),
("this is the worst", "unkind"), ("so nice", "kind"), ("ugly game", "unkind"),
("not bad at all", "kind"), ("you are not funny", "unkind"), ("great work", "kind"),
("slow and lame", "unkind"),
]
weights = {}
for text, label in TRAIN:
for word in text.split():
if word not in weights:
weights[word] = 0
if label == "kind":
weights[word] += 1
else:
weights[word] -= 1
def check(text):
score = 0
bad_words = []
for word in text.split():
w = weights.get(word, 0)
score += w
if w < 0:
bad_words.append(word)
return score, bad_words
راهنما و جواب این چالش · برگشت به درس جلسهی 36: پروژه: ناظر مهربان گالری · چالش بعدی: Step 4: A Person Decides
بیشتر بخوان: تابع در پایتون: آموزش def، پارامتر و return با مثال