You are given a vocabulary dictionary mapping strings (tokens) to integer IDs, e.g. {'a': 1, 'b': 2, 'cd': 3, 'UNK': -1}, and an input text string. Part 1 – Code Reading / Bug Finding: A baseline tokenize(text, vocab) is provided. It builds a running key character by character; whenever the…