How Large Language Models Handle Chinese: Tokenization, Embeddings, and Engineering Practices

    This article explains why large language models are language-agnostic at their core and why Chinese often underperforms in practice. It covers how Token IDs and shared embedding spaces work, the limitations of BPE and SentencePiece for Chinese, and practical fixes such as vocabulary expansion, structured prompts, hybrid retrieval for RAG, Token budget management, and multilingual content moderation.

    1. Introduction: Returning to the Technical Fundamentals

    A common misconception in discussions of AI is that a large language model’s (LLM) “stance” or “capability” is enforced by blocking specific languages. From the underlying mathematics to the engineering implementation, this view misrepresents how LLMs actually work. Modern LLMs process every language through the same mathematical logic rather than hard linguistic boundaries. This article examines the technical nature of multilingual support across three dimensions: tokenization, vector space mapping, and engineering practice, and discusses how developers can improve results in Chinese-language scenarios.

    2. Underlying Logic: Why LLMs Are Indifferent to Language Switching

    2.1 Token IDs: A Unified Measure Across Languages

    An LLM is fundamentally a probability-based next-token prediction engine. To the model, the English word “apple”, the Japanese kanji “林檎”, and the Chinese characters “苹果” carry no linguistic meaning. They are mapped to integer vectors in a high-dimensional space, known as Token IDs.

    During pretraining, the tokenizer builds a large vocabulary that decomposes human language into discrete numeric sequences. When text enters the model, the tokenizer slices it into a sequence of Token IDs. The Transformer architecture performs matrix operations on these numbers only, computing attention weights and outputting the next most likely Token ID.

    Key technical points:

    • Semantic irrelevance: In the model’s computation graph, the difference between Token ID 1234 and Token ID 5678 is merely the cosine similarity between different row vectors in the embedding table. The model does not “know” which ID corresponds to English and which to Chinese; it only captures co-occurrence probabilities.
    • Shared embedding space: Modern multilingual models typically use a shared embedding layer. This means the vector for “狗” lies very close to the vector for “dog” in geometric space, because they frequently appear in similar contexts across the training corpus.

    2.2 A Mathematical View of the Logic

    Suppose the model processes Chinese text with an input sequence $X = [x1, x_2, …, x_n]$, where each $x_i$ is a Token ID. The objective is to maximize the conditional probability $P(x_t | x{<t})$. This process does not depend on a language tag $L$. Unless language embeddings are deliberately introduced in a restricted model, such as a dedicated translation model, the loss function of a general-purpose LLM is neutral with respect to language.

    Consequently, “banning” a language is technically equivalent to “breaking vocabulary integrity”. Masking a range of Token IDs would fracture the autoregressive generation logic, the output probability distribution would no longer be smooth, and the model would suffer catastrophic forgetting. This is why mainstream foundation models continue to support full Token ID output.

    3. Core Challenge: Tokenization Bottlenecks in Chinese

    If the model itself does not reject Chinese, why do developers often find Chinese results worse than English? The cause lies in the statistical properties of the tokenizer when the vocabulary was built.

    3.1 The Chinese Bottleneck of BPE and SentencePiece

    Most mainstream LLMs use BPE (Byte-Pair Encoding) or a variant. Because early training corpora were overwhelmingly English (often more than 90%), Chinese characters tend to be split at a coarse granularity in the vocabulary.

    • The byte-level BPE compromise: To handle out-of-vocabulary (OOV) words, many models adopt byte-level BPE. A complex Chinese character (such as “龘”) may be split into multiple byte tokens. This directly inflates token length for Chinese text and increases inference cost.
    • Loss of semantic completeness: When a Chinese word is over-segmented, the model struggles to capture the complete semantic unit.

    Engineering countermeasures:
    If your application depends heavily on Chinese, there are two mainstream optimization paths:

    1. Tokenizer extension and fine-tuning: Add common Chinese word combinations to the pretrained model’s embedding layer, then fine-tune only the new embeddings.
      1. # Pseudocode: extending the vocabulary
      2. new_tokens = ["人工智能", "机器学习", "深度学习", "大语言模型"]
      3. tokenizer.add_tokens(new_tokens)
      4. model.resize_token_embeddings(len(tokenizer))
    2. Choose a Chinese-optimized vocabulary: Prefer model architectures with a reasonable proportion of Chinese tokens in the vocabulary, trained with SentencePiece, to reduce average sequence length.

    4. Engineering Practice: Building High-Performance Chinese AI Applications

    Once the underlying logic is clear, developers need application-level optimizations for Chinese characteristics to ensure accurate and safe output.

    4.1 Structured Prompt Design for Chinese

    Chinese logical connectives often carry multiple meanings, which can easily trigger model hallucinations. Use a strictly structured prompt of “instruction + context + constraints”.

    Poor example (vague): “Summarize the key points of this article.”

    Good example (structured):

    1. Role: Senior technical editor.
    2. Task: Extract 3 core points about "database index optimization" from the text below.
    3. Constraints: Output in Chinese, no more than 30 characters per point, stay objective and neutral.
    4. Input: <insert text here>

    4.2 Chinese Vectorization in Semantic Retrieval (RAG)

    In a knowledge-base question answering system, retrieval quality determines generation quality. Chinese retrieval faces segmentation ambiguity, such as how to split “南京市长江大桥”.

    • Hybrid retrieval strategy: Combine keyword-based inverted indexing (such as BM25) with vector-based semantic retrieval. BM25 excels at proper nouns and exact matching, while embedding vector models excel at capturing semantic similarity.
    • Embedding model selection: Ensure the embedding model is aligned with the generation model in semantic space. If the generation model is Chinese-optimized, the retrieval model should also be a vector model trained on Chinese corpora, avoiding a semantic gap.

    4.3 Segmentation Granularity and Token Budget Management

    Because of Chinese token consumption characteristics, cost estimation for API calls requires a precise local test set.

    Optimization code example:

    1. import tiktoken # Example of a general-purpose tokenizer library
    2. # In real projects, use the tokenization logic of the target model
    3. def calculate_tokens(text, encoding_name="cl100k_base"):
    4. enc = tiktoken.get_encoding(encoding_name)
    5. return len(enc.encode(text))
    6. chinese_text = "人工智能技术的发展日新月异,大语言模型正在重塑软件工程。"
    7. tokens = calculate_tokens(chinese_text)
    8. print(f"Token count: {tokens}")

    Developers should monitor the input/output token ratio. If Chinese text consumes an abnormally high number of tokens, the text usually contains many rare Chinese characters or unknown entities. Preprocessing or replacement via regular expressions is recommended.

    5. Content Safety: Governance in Multilingual Environments

    Supporting multiple languages does not mean lacking control. In global deployments, developers need cross-language content filtering.

    • Multilingual toxic classifiers: Simple keyword filtering is limited against Chinese variant forms (such as pinyin abbreviations or “Martian text”). Use a moderation API annotated across multiple languages, or a fine-tuned classification model for a second check.
    • Cultural context adaptation: Chinese-specific idioms, metaphors, and euphemisms can cause misjudgment. Add a context-based review step in the business logic instead of relying only on keyword matching.
    • Guardrails: Place interception layers before model input and after output. The input layer prevents prompt injection (such as “ignore previous instructions”), and the output layer prevents harmful content generation.

    6. Conclusion: Technical Neutrality and Engineering Judgment

    Returning to the initial point: an LLM is a mathematical engineering system that operates on token probability distributions and is inherently language-agnostic. So-called “blocking” is meaningless in the face of tokenizer statistics and only adds engineering complexity.

    For developers, the focus should not be on the model’s “stance” but on data engineering, tokenization optimization, and scenario adaptation. With a properly extended vocabulary, an optimized prompt structure, and hybrid retrieval, Chinese can become a strength of AI applications. Technology itself is neutral; the real barrier is a developer’s deep understanding of the underlying mechanisms and the ability to implement them in engineering.