Tokenization and NLP 道练习题
38 道题 · 0 已解决
在语言模型处理文本之前,tokenizer 会将其切分为若干片段,并将每个片段映射为一个 id。tokenizer 的选择会影响成本、速度,以及模型处理印地语、泰米尔语或克什米尔语等语言的能力。这类似于在教人识字前决定如何将单词拆分为音节。这些题目涵盖了现代 tokenizer 和经典 NLP 基础知识。你将练习将文本预切分为单词、数字和符号;提取 character n-grams;使用 byte fallback 对文本进行编码;解码 SentencePiece 片段;执行 BPE tokenizer 的一次 merge 步骤并使用 ranked merges 对单词进行编码;使用 WordPiece greedy longest match 进行分词;将 tokens 映射回字符偏移量;使用 unigram model 和 Viterbi 寻找最佳分词方案;使用 TF-IDF 对单词评分;计算 Levenshtein edit distance;训练 bigram language model 并测量 perplexity;以及使用 Kneser-Ney smoothing 对 bigrams 进行评分。建议从关于 pre-tokenization、n-grams 和 TF-IDF 的 Easy 题目开始。然后练习 BPE、WordPiece 和 edit distance,最后完成 unigram segmentation 和平滑语言模型。Tokenizer 的 bug 会导致模型行为异常,面试官也经常会问 BPE 的工作原理。
简单 15
- Score words by TF-IDF
- Encode text with a byte fallback so no character is ever unknown
- Normalize text by lowercasing, stripping accents and collapsing spaces
- Count word n-grams and return the k most frequent with stable ties
- Build a bag-of-words count matrix over a fixed vocabulary
- Turn WordPiece tokens back into text by merging ## pieces
- Pre-tokenize text into words, numbers and symbols
- Extract character n-grams with boundary markers
- Decode SentencePiece pieces back to text
- Build next-token training pairs with a sliding window and stride
- Measure tokenizer compression and fertility on a text sample
- Join word tokens back into readable text
- Encode a list of strings into one string and decode it back
- Evaluate an expression with plus and times, no parentheses
- Check brackets and report the first error position
中等 17
- Do one merge step of a BPE tokenizer
- Compute Levenshtein edit distance
- Tokenize words with WordPiece greedy longest match
- Build a vocabulary with special tokens, a minimum frequency and UNK
- Rank documents for a query with smoothed TF-IDF and cosine similarity
- Clean text with stopword removal and a rule-based suffix stemmer
- Truncate a sentence pair to a token budget with the longest-first strategy
- Encode a word with ranked BPE merges
- Map tokens back to character offsets
- Split text so special tokens stay whole
- Map raw bytes to printable characters for byte-level BPE
- Evaluate an arithmetic expression with precedence, parentheses and unary minusPro
- Fully justify words into lines of a fixed widthPro
- Repair LLM-generated SQL and formulas: remove the fewest bracketsPro
- Expand a compressed string with counts and nested groupsPro
- Find the longest common substring of two textsPro
- Longest stretch of a string with no repeated characterPro
困难 6
- Train a bigram language model and measure perplexityPro
- Find the most likely segmentation with a unigram model and ViterbiPro
- Encode a batch with CLS and SEP, truncation, padding side and an attention maskPro
- Recover the edit operations behind a Levenshtein distance by backtrackingPro
- Find collocations by ranking bigrams with pointwise mutual informationPro
- Score bigrams with interpolated Kneser-NeyPro