emoji_movies.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from evaluator import *
  2. DESCRIPTION = "A for-fun test to see if the model can go movie title -> emoji -> movie title."
  3. TAGS = ['fun']
  4. question = """
  5. For each of the following ten movies give at most 5 emoji that would best describe the movie.
  6. Give your answer as a JSON array. So If I asked for
  7. ```["Finding Nemo", "Toy Story"]```
  8. you might might answer
  9. ```json
  10. {"Finding Nemo": ["🐠", "🐟", "🐡", "🐬", "🐳"],
  11. "Toy Story": ["🚀", "⚔️,", "🤖", "👽", "🌌"]}
  12. ```.
  13. Each emoji must be a single utf8 character. ABSOLUTELY NO ZERO WIDTH JOINING. (So, max(len(emoji) for movie in result.values() for emoji in movie) == 1)
  14. Now give me answers for these movies:
  15. ```["The Lion King", "The Nightmare Before Christmas", "The Godfather", "The Matrix", "Casablanca", "Raiders of the Lost Ark", "V for Vendetta", "The Princess Bride", "Back to the Future", "Dune"]```
  16. Give ONLY a JSON output. Nothing else.
  17. """
  18. undo = """
  19. For each of the following ten movies described by 5 emoji, give the movie title that best matches.
  20. Give your answer as a JSON list. So If I asked for
  21. ```[["🐠", "🐟", "🐡", "🐬", "🐳"], ["🚀", "⚔️,", "🤖", "👽", "🌌"]]```
  22. You might answer
  23. ```json
  24. ["Finding Nemo", "Toy Story"]]
  25. ```.
  26. Now give me answers for these movies:
  27. ```<A>```
  28. What are the names of the movie titles?
  29. """
  30. def extract(x):
  31. try:
  32. x = json.loads(x)
  33. except:
  34. print("Failed processing")
  35. return ""
  36. send = list(x.values())
  37. # I'll be nice...
  38. send = [[x for x in y if len(x) <= 2] for y in send]
  39. return str(send).replace("], [", "],\n[")
  40. def count(x):
  41. try:
  42. x = json.loads(x)
  43. count = 0
  44. for correct, guessed in zip(["The Lion King", "The Nightmare Before Christmas", "The Godfather", "The Matrix", "Casablanca", "Raiders of the Lost Ark", "V for Vendetta", "The Princess Bride", "Back to the Future", "Dune"], x):
  45. if correct.lower() == guessed.lower():
  46. count += 1
  47. return count >= 8, "OK"
  48. except:
  49. return False, "Not a JSON list"
  50. TestEmojiMovie = question >> LLMRun() >> ExtractJSON() >> PyFunc(extract) >> LLMRun(undo) >> ExtractJSON() >> PyFunc(count)
  51. if __name__ == "__main__":
  52. print(run_test(TestEmojiMovie))