MBPP is a dataset of around 1,000 Python programming problems that are solvable by entry-level programmers. The problems cover topics such as programming fundamentals, standard library functionality, and text processing. Each problem consists of a natural language description, a code solution, and three automated test cases.
The dataset can be used to evaluate the capabilities of code-generation models, such as large language models, to synthesize short Python programs from natural language descriptions. It can also be used to enhance the user experience of code generation tools, such as Codex, by providing accurate and reliable solutions.
Here are some examples of problems from the MBPP dataset, taken from different topics:
def count_vowels(s: str) -> int:
vowels = "aeiouAEIOU"
count = 0
for c in s:
if c in vowels:
count += 1
return count
Test cases:
count_vowels("hello") == 2
count_vowels("AEIOU") == 5
count_vowels("bcdfghjkl") == 0
def second_largest(nums: list) -> int:
largest = max(nums)
second = min(nums)
for n in nums:
if n > second and n < largest:
second = n
return second
second_largest([1, 2, 3, 4, 5]) == 4
second_largest([10, 9, 8, 7, 6]) == 9
second_largest([5, 5, 4, 3, 2]) == 4
def swap_ends(s: str) -> str:
if len(s) < 2:
return s
else:
return s[-1] + s[1:-1] + s[0]
Test cases:
swap_ends("hello") == "oellh"
swap_ends("a") == "a"
swap_ends("ab") == "ba"