Rich Semantic Knowledge Enhanced Large Language Models for Few-shot Chinese Spell Checking (2024)

Abstract: Chinese Spell Checking (CSC) is a widely used technology, which plays a vital role in speech to text (STT) and optical character recognition (OCR). Most of the existing CSC approaches relying on BERT architecture achieve excellent performance. However, limited by the scale of the foundation model, BERT-based method does not work well in few-shot scenarios, showing certain limitations in practical applications. In this paper, we explore using an incontext learning method named RS-LLM (Rich Semantic based LLMs) to introduce large language models (LLMs) as the foundation model. Besides, we study the impact of introducing various Chinese rich semantic information in our framework. We found that by introducing a small number of specific Chinese rich semantic structures, LLMs achieve better performance than most of the BERT-based model on few-shot CSC task. Furthermore, we conduct experiments on multiple datasets, and the experimental results verified the superiority of our proposed framework.

heading: 1 Introduction
text: Spell checking (SC) aims to utilize intelligent methods to automatically identify and correct errors in text. This technology facilitates nature language processing applications to correct the errors from different text input systems, such as speech to text (STT) and optical character recognition (OCR). In recent years, SC has attracted tremendous attention from the research community (Chodorow et al., 2007; Malmi et al., 2019; Mallinson et al., 2020). Chinese spell checking (CSC) specifically refers to SC for Chinese text. Compared with the relatively complete SC technology, CSC still cannot be perfectly applied to various practical scenarios, and there are still many problems that need to be solved (Zhang et al., 2023).
∗Corresponding author.
As an ideogram, the usage and structure of Chinese are very different from English, which leads to different challenges for CSC and SC. First of all, the pronunciation of Chinese varies greatly, and it is difficult to easily infer the glyphs from the pronunciation. When listening to a piece of Chinese speech, if you do not understand the context, the text result obtained based on the speech is likely to contain a large number of homophones. In addition, the glyph structure of Chinese is more diverse, resulting in more types of errors. Therefore, CSC task mainly needs to handle two types of error texts. One is a text based on the STT system, which contains a large number of homophonic errors. The other is text generated by OCR-based systems that mainly contains glyph errors. To address these two types of spelling errors, most of the existing studies use models based on BERT architecture, then introducing the external glyph-phonetic features (Ji et al., 2021; Xu et al., 2021; Ji et al., 2021).
In practical Internet applications, the catchwords from hot topics vary rapidly and unlabeled incorrect sentences emerge constantly, resulting in few-shot scene for CSC. However, existing BERTbased models are difficult to be conduct in few-shot scene because of the limited scale of the foundation model. Large language models (LLMs) show remarkable ability on semantic analyzing, positioning them to become an optimal foundation model for CSC. This paper focus on CSC in few-shot scene. We build a Chinese rich semantic corpus (See details in Section 4.1). Besides, we choose LLMs as foundation and integrate Chinese rich semantic knowledge by in-context learning. Furthermore, we conduct experiments on several datasets. The contributions of this study are summarized as follows:
• We propose an in-context learning based method to introduce LLMs to CSC task, which improves the performance of few-shot
7372
scenarios. • We propose the paradigm of prompt template
designing for CSC. • We conduct experiment to compare different
Chinese Rich Semantic structures. And we find the best structures for LLMs based CSC tasks.

heading: 2 Related Work
text: Due to the lack of parallel corpus training data, early CSC methods mainly rely on linguistic knowledge to manually design rule-based methods (Mangu and Brill, 1997; Jiang et al., 2012). Subsequently, machine learning models become the main paradigm for CSC tasks (Chen et al., 2013; Yu and Li, 2014). Machine learning typically employs language models, such as n-grams, to detect error locations. Then uses confusion sets and character similarities to correct potential misspelled characters and candidate correct characters, and finally scores replace sentences through the language model to determine the best correction solution (Liu et al., 2013; Xie et al., 2015).
The field of CSC advances significantly with the development of deep learning, particularly through pre-trained models like BERT (Devlin et al., 2019). Pre-trained models such as BERT are known for their context awareness and transfer learning capabilities. Most current CSC models with better performance use BERT as the baseline model. Hong et al. (2019) innovates by modeling CSC as a BERT token classification task, utilizing the ConfidenceCharacter Similarity Decoder (CSD). Zhang et al. (2020) enhances this approach by combining error identification and correction losses with a soft mask strategy. Addressing the prevalent issue of phonetic and glyph similarities in spelling errors, the integration of these features with semantic information is now a primary research focus. Liu et al. (2021) suggests incorporating confusion sets into pre-training with a GRU network to better mimic real errors and model character sound-shape similarities. Xu et al. (2021) proposes a multi-modal approach to capture semantic, phonetic, and graphical information and the use of adaptive gating modules to merge semantic, phonetic, and glyph features in CSC. Ji et al. (2021) introduces SpellBERT, which integrates radical features into character representation using a graph convolution network. The SCOPE model (Li et al., 2022) further develops this field by adding pronunciation prediction tasks in training, forging
a deeper connection between semantics and phonetics, and employing iterative reasoning strategies to bolster CSC model performance.
Recently, the development and advancement of LLMs have brought natural language processing to the next stage. Li et al. (2023b) analyzes the correction ability of the OpenAI1’s existing LLMs and finds that they still fall short of the CSC capabilities of previous fine-tuned models.

heading: 3 Preliminary

heading: 3.1 Chinese Rich Semantics
text: Chinese is the carrier of the inheritance and development of Chinese civilization. As a hieroglyphic script that has lasted for thousands of years, Chinese characters have rich semantic structures, including traditional characters, glyphs, phonetic, tones and other features. Chinese contains a large number of phonograms, whose pronunciation and meaning are contained in radicals. For example, "海 (sea)", "河 (river)" and "湖 (lake)" all have the radical "氵", related to water (Sun et al., 2021). For another example, "株 (zhū)", "诛 (zhū)" and "珠 (zhū)" all have the same phonetic tone "朱 (zhū)", so the pronunciation of these characters is similar. In essence, radicals can be regarded as a kind of classification label information. This classification information serves as traditional context. The additional supplement of semantic features has important semantic value. In addition to the features at the glyph level, Chinese also has features such as morpheme diversity, ambiguity, and structural diversity.

heading: 3.2 Task Definition
text: Formulate definition of CSC: CSC focuses on identifying and rectifying spelling errors in a given text sequence. Essentially, it involves processing a sequence of characters X = {x1, x2, ..., xn} and producing a corrected sequence Y = {y1, y2, ..., yn}, where n is the number of word. Here, X denotes the initial text with potential errors, and Y signifies the amended, correct text. The two sequences X and Y have the same length. Few-shot Learning on CSC: Few-shot learning refers to provide a model named L with K pairs of contexts and corresponding required answers as examples, and then a context that requires model L to reason. The goal of model L is to generate
1https://openai.com/

heading: I am really sorry to trouble you. I hope you have a good time
text: an appropriate answer for the last context. During inference, model L is guided by K context-answer pairs without any updates to its parameters (Brown et al., 2020).
In few-shot learning for CSC task, we set K to 3. Then we have a few-shot learning prompt P , which contains three sentences pairs:
P = {p1, p2, p3} (1)
where pi contains an incorrect sentence and its corresponding correct sentence.
Then the sentence X that need to be spell checked:
X = {x1, x2, . . . , xn} (2)
where xi denotes a word of sentence X . n is the length of sentence X .
For model L, the inputs are P and X , and the output is the correct sentence Y corresponding to the sentence X .
Y = L(P,X) (3)
Y = {y1, y2, . . . , yn} (4) where yi denotes a word of sentence Y and n is the length of sentence Y .

heading: 3.3 Difficulties of LLMs based CSC Tasks
text: The versatility of LLMs gives them significant text polishing capabilities. Since there are no specific restrictions on input prompts, LLMs tend to perform freely in CSC tasks. However, free play of
LLMs may result in LLMs outputting sentences that are completely grammatically correct. However, the sentences output by LLMs are different from the standards established by existing CSC datasets and evaluation indicators. Therefore, these existing traditional datasets are used without specific restrictions on input prompts. It becomes challenging to objectively and realistically evaluate the spell checking performance of LLMs. An example of using LLMs (ChatGPT) to perform a CSC task without setting specific restrictions on input prompts is shown in Fig.1. From Fig.1, it can be observed that two main problems are prone to occur in LLMs when performing CSC tasks, one is the length of the input sentence and the output sentence are inconsistent. For instance, the sentence "I am really bald (我真胡秃)", which should be corrected to "I am really confused (我真糊涂)". However, LLMs correct this sentence to "I am really sorry (我真的抱歉)". Another problem is that LLMs easily rewrite the input sentences semantically. For example, "I hope you have a good time dancing without (希望你们好好的跳无)", in which "dancing without (跳无)" should be corrected to "dancing (跳舞)". Instead, LLMs correct this sentence to "I hope you have a good New Year (希望你们好好的过年)".

heading: 4 Method

heading: 4.1 Chinese Rich Semantic Corpus
text: Chinese, a logo-graphic language, inherently possesses a rich semantic depth in its character glyph,
potentially enhancing the expressiveness of LLMs. Our work focuses on the GB2312 simplified Chinese coding table, a standard set by China’s State Administration of Standards on May 1, 19812. This table consists of 6,763 Chinese characters, divided into 3,755 primary and 3,008 secondary characters. It contains the most commonly used Chinese characters. In order to obtain the detailed information of this coding table, we collected various basic attributes of each Chinese word, such as its phonetic, radical, phonetic notation, strokes, outside strokes (the strokes except the radical), stroke order, structure, Unicode, Wubi code, Cangjie code, Zheng code, Four-corner code, as well as glyph images from different historical periods. Despite the large amount of data collected, we note issues with the quality and completeness of the data. To address these issues, we manually annotate the collected information to ensure a more accurate and comprehensive dataset. We give the attributes of the word 海 (sea) in the dataset as shown in Fig.3. In order to understand and better utilize these properties, we classify these features into the following three categories:
2https://openstd.samr.gov.cn/bzgk/gb
• Phonetic Features：Phonetic uses Latin letters to represent the pronunciation of Chinese characters. Phonetic notation is a phonetic system that uses symbols to represent the speech of Chinese characters. Zheng Code is a Chinese character input method that assigns codes based on the initials of the phonetic pronunciation. • Glyph Features：Radical is a category according to the type and side of the Chinese characters, and all the Chinese characters are bound to be classified in a certain radical. Strokes refers to the number of lines needed to write Chinese character. Outside strokes mean the number of lines needed to write Chinese character except the radical. Structure refers to the internal organization of Chinese characters, including the arrangement of radicals, strokes, and components. • Input Coding Features：Stroke Order indicates the sequence in which strokes are written when forming a Chinese character. Proper stroke order is important for correct character writing. Cangjie code assigns codes to characters based on their shapes and compo-
nents. Unicode is an international standard for character encoding that assigns unique codes to characters from various writing systems, including Chinese characters. Wubi code assigns codes based on the five basic strokes. Four-Corner code is a Chinese character input method that assigns codes based on the shapes of the four corners of a character.
We publish the information we collect at dropbox. 3

heading: 4.2 In Context Learning for CSC

heading: 4.2.1 Motivation
text: A variety of studies (Xie et al., 2022; Dai et al., 2023; Bansal et al., 2023) have revealed that LLMs exhibit exceptional in-context learning capabilities (Dong et al., 2023). In-context learning can quickly improve the task-specific performance of LLMs by providing a limited set of task-related examples, which can quickly adapt to most LLMs without the need for separate training for each LLM. As mentioned in Section 3.3, when LLMs perform CSC tasks without specific task constraints on input prompts, the answers generated by LLMs are very likely to be inconsistent with the existing evaluation indicators of CSC tasks. Therefore, in order to accurately and objectively explore the performance ability of LLMs on CSC tasks, we design the taskspecific prompts as shown in Fig.2.

heading: 4.2.2 Prompt Design
text: First of all, we give the identity and task description in the prompt. According to Li et al. (2023a), we know that Role Attribution (“You are an excellent Chinese Spell Checking model") can effectively stimulate LLMs’ comprehension. The task description requires the LLMs to only correct spelling mis-
3https://www.dropbox.com/scl/fo/ 0r1jw4l1ex3w0lyojsfpf/AGVMdlOFpwDqoOFrxqWXJko? rlkey=18wke1vmhj6muwufvu3aazji2&st=vgh1drbi&dl=0
takes, thus limiting the LLMs’ semantic rephrasing of the input sentence. Since the evaluation of CSC task requires the input sentence and the output sentence to be same length, the LLMs are required not to add any other explanations and descriptions of output, so as to ensure the length remains unchanged.
Then, we give three pairs of input sentences and their corrected sentences as examples, carefully selected from the corresponding training set of the dataset we use. From Liu et al. (2010), Chinese text errors are primarily caused by characters that are visually and phonetically similar. These three sentence pairs contain a set of phonetic errors, a set of glyph errors, and a set of correct sentences that do not need to be corrected.
Next, we add specific task requirements to the input sentences of three pairs of sentences, which is different from the foremost task description. The foremost task description requires LLMs to correct the spelling errors of the input sentences. We concretize the task here, asking LLMs to find spelling errors in sentences and replace wrong word with correct one. This allows LLMs to have a clearer comprehension of CSC task. We append the length of the input sentence to the end to indicate the LLMs that we limit the length of the output sentence in the first prompt. We also include the phonetic and radical information of each Chinese character in the input sentence, drawn from Chinese Rich Semantic Corpus outlined in Section 4.1. It is hoped that by adding this information to the prompt, the LLMs can strengthen their understanding of the input sentence. Therefore, LLMs can better correct phonetic and visual errors that may occur in the sentences. These are in the form of four pairs of historical dialogues that form a few-shot prompt input to LLMs, hoping to stimulate the in-context learning capabilities of LLMs at once.
Considering the length limit of LLMs on the length of the input (including historical dialogue), and the deterioration of the semantic understanding of LLMs with long input lengths. For each sentence to be corrected in the test set, we clear the historical memory of the LLMs and add our few-shot prompt.

heading: 4.3 Introspection Mechanism
text: A significant challenge with using LLMs for spell checking is that LLMs tend to over-modify and arbitrarily change sentence lengths. In order to avoid the impact of this change on the evaluation indicators, we use a Introspection mechanism.
Specifically, after LLMs generate the correction sentence, we send this answer and the original input sentence to LLMs again. LLMs are required to introspect two questions: 1) Whether the lengths of the two sentences are consistent. 2) Whether the added rich semantic information is effectively used in this error correction process. Only when the answers to both questions are "yes" will the answer be output as the final error correction result. Otherwise, the current conversation will be added to the historical conversation and provided as context to the model. In the conversation, it indicates that the sentence length in this answer does not match the input sentence length or the semantic information is not used, and then sends a reply request to LLMs again. In the introspection mechanism of this experiment, we set the maximum number of loops to 5. If the answer cannot be obtained after five requests to LLMs, it is judged that LLMs cannot correct the sentence and uses original input sentence without introspection as the answer. And consider that the model’s ability to understand long context will deteriorate. We only add the latest round of dialogue in each loop within the context of the original design.

heading: 5 Experiments

heading: 5.1 Datasets and Evaluation Metrics
text: Datasets: To evaluate the effectiveness of our proposed method, we choose two widely used datasets. The first, SIGHAN15 (Tseng et al., 2015), consists of handwritten samples from learners of Chinese as a Second Language (CSL). These samples provide a rich source of real-world language usage by non-native speakers, offering insights into common errors and patterns in learning Chinese. The second dataset (Lv et al., 2023) is specialized and segmented into three distinct domains to provide a more comprehensive understanding of language use in specific contexts. For the LAW domain, data is sourced from the stems and choices of multiple-choice questions in judicial examinations, reflecting the formal and technical language of the legal field. The MED domain encompasses data from question-and-answer pairs drawn from online medical consultations, showcasing the specific terminology and communication style in healthcare. The ODW (Official Document Writing) domain includes data from various official documents such as news, policies, and state reports on national conditions, representing formal and structured writing
styles. The statistics of the test data from these four datasets we used are shown in Table 1.
Evaluation Metrics: By following the existing work (Xu et al., 2021; Lv et al., 2023), we evaluate the performance on two metrics: detection and correction. For detection, a sentence is considered correct if it successfully identifies all spelling errors. For correction, the model not only identifies but also rectifies all erroneous characters by replacing them with the correct ones. We provide accuracy, precision, recall, and F1-scores for both metrics.

heading: 5.2 Baselines
text: We choose two widely used LLMs as foundational models. gpt-3.5-turbo4: One of a series of LLMs provided by OpenAI, which can be accessed through the API. The gpt-3.5-turbo serves as the underlying module for ChatGPT and is trained on GPT-3 using Reinforcement Learning from Human Feedback (RLHF). ChatGLM2-6B5: An open-source bilingual (Chinese-English) chat model. ChatGLM2-6B employs a GLM-based (Du et al., 2022) hybrid objective function and has been pre-trained on 1.4 trillion bilingual tokens and human preference alignment training. We choose several advanced CSC models as baselines: BERT (Devlin et al., 2019): BERT encodes the input sentence to get semantic information, followed by using a classifier to select the correct character from the vocabulary. ChineseBERT (Sun et al., 2021): ChineseBERT encodes the input sentence to get semantic,
4https://platform.openai.com/docs/api 5https://huggingface.co/THUDM/chatglm2-6b
phonetic, and graphical information, then use a classifier to select the correct character from the vocabulary. ReaLiSe (Xu et al., 2021): This CSC model captures semantic, phonetic, and graphical information of input characters using multimodality for prediction. Scope (Li et al., 2022): This CSC model introduces an auxiliary task of Chinese pronunciation prediction (CPP) to improve CSC task.

heading: 5.3 Implementation Details
text: For all methods, the settings of hyper-parameters follow the optimal parameters in the open source code corresponding to the model. In order to achieve few-shot scenarios, all contrast experiments randomly selected 10 samples of data from the training set, trained for 1000 epochs, and then selected the best performance. The LLMs experiment uses the same few-shot prompt designed for CSC task as RS-LLMs, but does not add semantic information. All experiments were conducted on a RTX-4090 with 24G memory.

heading: 5.4 Experimental Results
text: Table 3 shows the evaluation results of our RSLLMs comparing to other models on the test sets of SIGHAN15, LAW, MED, and ODW. It is observed that our RS-LLM consistently outperforms all baselines on all datasets in all metrics. Especially compared with LLM, LLM uses the same few-shot prompt as RS-LLM but does not add semantic information when performing CSC tasks. The experimental results of this period verify the effectiveness and superiority of our semantic information on LLM for CSC task.
From time to time experiments, we found that the experimental results are not completely consistent because the performance of online APIs varies.
Therefore, we use ± in the results to explain the error band of the experiment.
As shown in Table 3, our spell-checking approach, RS-LLM on ChatGLM2-6B, achieves a notable 8.0% improvement in error detection and an 9.8% increase in correction on SIGHAN 15 using Rich Semantic, compared to the standard LLM. Impressively, RS-LLM on gpt-3.5-turbo registers a 9.9% boost in F1-score for detection and a 12.3% leap in correction. In the LAW dataset, RS-LLM on ChatGLM2-6B beats ChatGLM2-6B by 5.8% in detection and 6.6% in correction, while RS-LLM on gpt-3.5-turbo outperforms gpt-3.5-turbo by 16.9% and 14.6%, respectively. The trend continues in the MED dataset, where RS-LLM on ChatGLM2-6B surpasses ChatGLM2-6B by 13.1% in detection and 9.3% in correction, and RS-LLM on gpt-3.5turbo exceeds gpt-3.5-turbo by 15.3% and 13.7%. On the ODW dataset, our method also shows significant gains, with RS-LLM on ChatGLM2-6B leading ChatGLM2-6B by 6.9% in detection and 5.6% in correction, and RS-LLM on gpt-3.5-turbo outdoing gpt-3.5-turbo by 14.1% and 12.7%.

heading: 5.5 Analyses and Discussions
text: In order to verify the effectiveness of the prompt sentence, we count the number of sentences whose length remained the same with and without a specific prompt, and the experimental results are shown in Table 2. It is obvious that LLM performs better than most of the BERT-based CSC models at both the detection and correction levels. The ability of the BERT-based CSC model to detect and correct erroneous characters is overly dependent on the training data of CSC, especially the ability to correct erroneous characters. The LLMs based approach shows better generalization in the few-shot scenario. However, we find that LLM’s performance on the CSC task heavily depends on the foundation model. When the scale of parameters of the foundation model is larger, the model performs better on the CSC task. Although the performance of RS-LLM cannot currently outperform Scope, we believe that with the continuous update of the base model performance, the RS-LLM method will continue to improve and show a better improvement trend.

heading: 5.5.1 Impact of Different In-context Learning Approaches
text: Fig.4 and Fig.5 show the evaluation results of different in-context learning approaches. From Fig.4
and Fig.5, we discover that the performance of CSC task on LLMs improves as the number of examples increasing, both in terms of detection and correction. Additionally, it’s clear that RS-LLM is more effective than most BERT-based models in terms of zero-shot, one-shot, and few-shot scene. Such experimental results reflect the effectiveness of our in-context learning strategy designed for CSC task. The specific experimental results are shown in Table 5 in Appendix A.

heading: 5.5.2 Impact of Different Chinese Rich
text: Semantic Information
In order to further study the impact of semantic information on LLMs when performing CSC tasks. We design to use phonetic information, radical in-
formation, structural information and strokes information. Each of these four types of information is added to our zero-shot prompt, one-shot prompt, and few-shot prompt. To explore the impact of these four prompts on the test set of SIGHAN15, LAW, MED, and ODW. The specific experimental results are Table 4 in Appendix A.
The experimental results show that individual phonetic, radical, structural, and stroke information leads to improvements in CSC task across all datasets. Notably, the phonetic and radical information contribute the most significant enhancements, followed by structural information. While strokes information does show some improvement, it’s relatively puny compared to the others.

heading: 6 Conclusion and Future Work
text: In this paper, we introduce an in-context learning method named RS-LLM for CSC task, one of whose core components is using Chinese Rich Semantics in LLMs for CSC task. RS-LLM utilizes adding a small number of specific Chinese rich semantic information into a specific few-shot prompt set for CSC task, aiming to allow LLMs to have a fuller understanding of the semantics when doing CSC task. Experimental results show that this LLMs-independent approach can help existing LLMs better recognize and correct phonetically and visually erroneous characters in CSC tasks. Considering the impact of the similarity of errors in the few-shot prompt and errors in the sentence on LLMs’ understanding of the sentence when LLMs perform CSC task. In the future, we will try to construct dynamic prompt for each sample through semantic similarity retrieval.
Limitations
To verify the effectiveness of RS-LLM, we conducted extensive experiments on two benchmark datasets of different domains and scales. The results indicate that RS-LLM delivers SOTA results in few-shot scenarios. Since most of the errors in the CSC dataset are attributed to visual and phonetical errors, we incorporate phonetic and radical information into the prompt template. However, it is difficult to ensure that the existing manually formu-
lated prompt templates are optimal, and the optimal prompt sentences for CSC require further research. Furthermore, relevant examples have been carefully selected to enable LLMs to identify potential visual and speech errors in a small number of scenarios. No consideration was given to the ability to motivate the LLMs through semantic similarity. We recognize these two limitations and plan to address them in future research efforts.
Ethics Statement
We adhere to and advocate for the principles outlined in the ACL Code of Ethics. The primary focus of this paper is on the task of CSC, with an objective to enhance the performance of LLMs in this task by incorporating semantic knowledge into the template. The datasets utilized in our research are obtained from openly published sources, ensuring they are free from privacy or ethical concerns. In our approach, we consciously avoid introducing or magnifying any social or ethical biases in the model or data. Consequently, we anticipate no direct social or ethical challenges as a result of our research.

heading: Acknowledgments
text: This work was partly supported by China Postdoctoral Science Foundation (No. 2023M731253) and Hubei Provincial Natural Science Foundation (No. 2023AFB487).

heading: A The Detailed Experimental Results
text: In this section, we introduce the specific experimental results of different in-context learning methods under different semantic information.

heading: Future Work
text: In the future, we will try to construct dynamic prompt for each sample through semantic similarity retrieval. Limitations
To verify the effectiveness of RS-LLM, we conducted extensive experiments on two benchmark datasets of different domains and scales. The results indicate that RS-LLM delivers SOTA results in few-shot scenarios. Since most of the errors in the CSC dataset are attributed to visual and phonetical errors, we incorporate phonetic and radical information into the prompt template. However, it is difficult to ensure that the existing manually formu-
lated prompt templates are optimal, and the optimal prompt sentences for CSC require further research. Furthermore, relevant examples have been carefully selected to enable LLMs to identify potential visual and speech errors in a small number of scenarios. No consideration was given to the ability to motivate the LLMs through semantic similarity. We recognize these two limitations and plan to address them in future research efforts