Word Segmentation and Tokenization
摘要
This chapter details two distinct approaches to word segmentation and tokenization for Natural Language Processing (NLP). The first method addresses Chinese Word Segmentation (CWS) by treating it as a character-based sequence-labeling task, where each character is tagged based on its position within a word (e.g., beginning, middle, end, or single). It provides a step-by-step guide for implementing this task by fine-tuning a pre-trained BERT model, covering everything from data processing and model construction to training and evaluation. The second method introduces sub-word segmentation using the Byte Pair Encoding (BPE) algorithm, a technique designed to handle out-of-vocabulary (OOV) words and reduce vocabulary size by breaking words into smaller, more frequent sub-word units. This section explains how to build a BPE vocabulary by iteratively merging the most frequent adjacent character pairs and then use that vocabulary to segment new text.