← 返回 perplexity 的题目列表Optimize Byte Tokenization and Estimate Token Count
类型:online_judge
Multi-Part Interview Task
Part 0: Understand ByteTokenizer Reference Implementation
Open the byte_tokenizer.py file and study the ByteTokenizer class and the slow_tokenize method in the starter code. Write a detailed natural language description that accurately explains how the algorithm operates, so it can be faithfully re-implemented by others.
Part 1: Optimize ByteTokenizer Performance
Develop a faster implementation in the tokenize method that returns identical results as slow_tokenize.
Maintain performance: total test time should be under 10 seconds.
Preprocessing logic may be implemented in the constructor and any helper functions can be added at will.
Part 2: Estimate Token Count
Implement the estimate_token_count method to estimate the number of tokens returned by self.tokenize(text).
Meet accuracy expectations: returns accurate count when sample_size exceeds text length, otherwise estimates should have less than 20% error, and less than 5% when sample_size>10000.
Example
Input
{"text": "This is a simple test text.", "sample_size": 1000}