whisper_merge.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model can implement some string logic given a fuzzy description."
  3. TAGS = ['code', 'python']
  4. question = """
  5. Given a parse function like
  6. def parse_transcript(content):
  7. transcript_segments = []
  8. pattern = r'\[(\d{2}:\d{2}:\d{2}\.\d{3}) --> (\d{2}:\d{2}:\d{2}\.\d{3})\] (.*)'
  9. matches = re.findall(pattern, content)
  10. for start_time, end_time, text in matches:
  11. start_seconds = timedelta(hours=int(start_time[:2]), minutes=int(start_time[3:5]), seconds=int(start_time[6:8]), milliseconds=int(start_time[9:])).total_seconds()
  12. end_seconds = timedelta(hours=int(end_time[:2]), minutes=int(end_time[3:5]), seconds=int(end_time[6:8]), milliseconds=int(end_time[9:])).total_seconds()
  13. transcript_segments.append((start_seconds, end_seconds, text))
  14. return transcript_segments
  15. for data like
  16. [00:00:14.240 --> 00:00:14.420] the
  17. [00:00:14.420 --> 00:00:14.860] robust
  18. [00:00:14.860 --> 00:00:15.020] ness
  19. [00:00:15.020 --> 00:00:15.140] of
  20. [00:00:15.140 --> 00:00:15.500] neural
  21. [00:00:15.500 --> 00:00:15.870] networks
  22. [00:00:15.870 --> 00:00:16.200] .
  23. [00:00:16.200 --> 00:00:16.410] And
  24. [00:00:16.410 --> 00:00:16.700] this
  25. [00:00:16.700 --> 00:00:16.840] is
  26. [00:00:16.840 --> 00:00:17.200] joint
  27. write a merge() function that (1) calls parse and (2) merges words into sentences that end in period. Start with the first word and end with the period. Return a list of strings.
  28. """
  29. test_case, answer = make_python_test([("""merge("[00:00:14.240 --> 00:00:14.420] the\\n[00:00:14.420 --> 00:00:14.860] robust\\n[00:00:14.860 --> 00:00:15.020] ness\\n[00:00:15.020 --> 00:00:15.140] of\\n[00:00:15.140 --> 00:00:15.500] neural\\n[00:00:15.500 --> 00:00:15.870] networks\\n[00:00:15.870 --> 00:00:16.200] .\\n[00:00:16.200 --> 00:00:16.410] And\\n[00:00:16.410 --> 00:00:16.700] this\\n[00:00:16.700 --> 00:00:16.840] is\\n[00:00:16.840 --> 00:00:17.200] joint\\n")""", "[' the robustness of neural networks.', ' And this is joint']")], header="""
  30. def parse_transcript(content):
  31. transcript_segments = []
  32. pattern = r'\[(\d{2}:\d{2}:\d{2}\.\d{3}) --> (\d{2}:\d{2}:\d{2}\.\d{3})\] (.*)'
  33. matches = re.findall(pattern, content)
  34. for start_time, end_time, text in matches:
  35. start_seconds = timedelta(hours=int(start_time[:2]), minutes=int(start_time[3:5]), seconds=int(start_time[6:8]), milliseconds=int(start_time[9:])).total_seconds()
  36. end_seconds = timedelta(hours=int(end_time[:2]), minutes=int(end_time[3:5]), seconds=int(end_time[6:8]), milliseconds=int(end_time[9:])).total_seconds()
  37. transcript_segments.append((start_seconds, end_seconds, text))
  38. return transcript_segments
  39. """)
  40. TestWhisperMerge = question >> LLMRun() >> ExtractCode() >> PythonRun(test_case) >> SubstringEvaluator(answer)
  41. if __name__ == "__main__":
  42. print(run_test(TestWhisperMerge))