Rephrasing Profanity in Chinese Text

This paper proposes a system that can detect and rephrase profanity in Chinese text. Rather than just masking detected profanity, we want to revise the input sentence by using inoffensive words while keeping their original meanings. 29 of such rephrasing rules were invented after observing sentences on real-word social websites. The overall accuracy of the proposed system is 85.56%


Introduction
Profanity, or offensive language, is often seen in social media, especially when users can write things anonymously. In nowadays, many social media or chatrooms have policies to detect and mask offensive words in order to reduce web abuse.
Most of the English profanity processing systems maintain a list of offensive words and their substitutions. A simple match-and-replace method can handle most of the cases (Razavi et al., 2010;Vandersmissen, 2012;Xiang et al., 2012;Bretschneider et al., 2014).
However, detecting profanity in Chinese is more complicated than in English. A Chinese character appearing in an offensive word may also appear in a mild word. For example, although the character "幹" means "fxxk" in some context, it also has meanings of "do", "work", and "stem", as its appearances in the words "幹活" (do works) or "枝 幹" (tree branches and stems). Simple detection and masking will filter out inoffensive words. Moreover, our system tries to offer an alternative way to express what a writer wants to say, rather than just applies masking and leave the offensive words there. There are two reasons that we want to rephrase the offensive expressions instead of masking them: 1. Sometimes in Chinese, the masking will make the sentence incomprehensible.
2. Hopefully, it will gradually make the writer to put words more politely.
To our best knowledge, there is no much research work in NLP discussing about detecting and rephrasing profanity in Chinese text. As a preliminary study, we only focused on the most frequent types of offensive words in Traditional Chinese, as well as some Mandarin transliterations in the Southern Min dialect (referred to as Taiwanese hereafter).
We have to apologize that this paper contains a lot of offensive words, both in Chinese and English. We will rewrite these words in the following ways to make them less offensive: a) for a single Chinese character, it will be replaced by an uppercase English letter, such as "F 你"; b) for a multi-character Chinese word, underlines are inserted between characters, such as 賤_人; c) for a phrase, plus signs are inserted between words, such as 你+奶奶 +的; d) for an English word, some letter will be replaced by 'x', such as "fxxk". We hope the readers can feel less offended with these revisions.
Another challenge in English is to detect abusive languages in articles, including racist, sexual-oriented harassment, bullying, and hateful speech (Ross et al., 2016;Waseem, 2016;Waseem and Hovy, 2016;Wulczyn, et al., 2017). It will be our future work in Chinese.
This paper is organized as follows. Section 2 defines the categories of offensive expressions studied in this paper and explains how to build the experimental dataset. Section 3 describes the rephrasing rules. Section 4 delivers the evaluation and error analysis. Section 5 concludes the paper.

Profanity Data Collection
In order to observe all variations of Chinese profanity in real world, we built a data collection from social media. Offensive expressions were annotated and their milder paraphrases were also created by humans. The procedure is described briefly in the section.

Real-World Profanity Data Collection
Two popular social media, Twitter and PTT (a famous BBS in Taiwan), were chosen as the source websites to collect offensive expressions.
Twitter 1 provides a search tool to find tweets containing submitted keywords. A search example is illustrated in Figure 1. Because Twitter only returns a small set of results for one query, we only collected the top 30 results for study.
PTT 2 , on the other hand, does not provide any tool to search posts. We used Google to do the searching by adding the option "site:ptt.cc", which restricts the source website of the search results. We then retrieved the full texts of the posts by visiting the URLs in the search results. At most top 300 results for each query were collected.
Queries were Chinese characters or words commonly used in Chinese profanity. We expanded the query terms with their synonyms in Tongyici Cilin (同義詞詞林, a thesaurus of Chinese synonyms) or well-known substitutions with similar pronunciation. These query terms belong to the following four categories.
1. Terms related to "sexual intercourse" 2. Terms related to sexual organs or substances 1 https://twitter.com/ 3. Terms synonymous to "bxtch" 4. Terms in the pattern of "one's relative's", a special pattern of profanity in Chinese In case that tweets or posts written in Simplified Chinese were collected, we converted them into Traditional Chinese by three mapping dictionaries developed by Wikipedia with the longest-matching strategy.
We found that not all the search results from PTT were suitable for our research. Some users expressed their anger against some persons, teams or TV programs by changing their names into indelicate characters. These are not common cases thus should be filtered out. In order not to spend too much human effort on filtering, posts from the Gossip Board and the sex-related boards were discarded. The source board of a post can be determined from its URL.
There are totally 9,557 sentences in the test set.

Data Annotation
The main purpose of our system is to rephrase profanity into another meaningful text. It is important to find suitable substitutions so that the rephrased text is fluent and has the same (or similar) meaning of the original text. Therefore, we built a develop set as gold standard for observation. Two annotators (college students) were asked to browse the posts collected from Twitter or PTT, extract the sentences containing profanity, and provide possible paraphrases. Besides, if they saw a sentence containing obscene keywords but was not offensive, they would tag the sentence as "no need to change".
Moreover, if two annotators had different opinions on the same sentence, the authors would discuss and make decisions. Most of the disagreements were about the determination of indelicate text. Some found a text offensive while the other could tolerate it.

Detection and Rephrasing Rules
The main purpose of this paper is to develop a system which can detect and rephrase profanity in a given input. This system can be integrated with social media. After a user writes down some words, our system can provide a more decent way to express the same thing before the message is submitted. An example is shown in Figure 2 when integrating with Facebook.  After observing the real-world indelicate texts and their paraphrases, we invented 29 sets of detection patterns and rephrasing rules. Detection patterns consist of surface strings, word sets, and preconditions to apply the rules. Appendix A lists all the detection patterns and rephrasing rules. The following subsections explain the definitions and the challenges of the five major categories.

Phrases with F-words
The direct Chinese translation of "fxxk" is "幹" (masked by F hereafter in this paper). Appendix A also lists 3 other synonymous characters. Such characters have several usages. 1. It can be used as a verb as a swear word as in the phrase "F 你老師" ("fxxk your teacher"). The writer only wants to express his or her anger, so it can be replaced by "darn" or "oh no" (Rule #1). Note that the object of such a verb is often a relative or a close person to the hearer (such as mother or teacher). 2. A single word can form an exclamatory sentence "F!" ("Fxxk!"). It has the same meaning as the first case (Rule #2). 3. It can be used as an adjective as in the phrase "覺得很 F" ("feeling really fxxked"). Most of the time there will be an adverb preceding it. It can be replaced by an adjective synonymous to "angry" (Rule #3). 4. It can be used as a sentence opener as in the sentence "F 昨天忘了買鞋" ("Fxxk I forgot to buy shoes yesterday"). Replacing it with "oh no" is OK (Rule #4). 5. It may appear in an inoffensive word such as "幹活" (do works) or "操作" (operate). A list of formal words containing these offensive characters is maintained. Words in this list will remain unchanged in the input text (Rule #27).

Phrases Containing Relatives
The original phrase in this category is "他+媽+的" ("to his mother" / "his mother's"). Due to the explosion of social media, many similar phrases have been invented. They are all in the pattern of Pronoun + RL + 的, where Pronoun is a 2nd-or 3rdperson singular pronoun and RL is a relative title such as "奶奶" (grandma) or "妹妹" (sister). Note that "的" is a particle and carries no content information. Such a phrase can also be used as a possessive form in a formal text, such as "他奶奶的拿手菜" ("his grandmother's specialty dish"). But when it is used alone, it becomes offensive (Rule #29).

Words Synonymous to "Bxtch"
Words in this category are used to scold somebody, so they can be replaced by phrases like "bad person" (Rules #5 ~ #7) which is less offensive.

Phrases with the Word "Semen"
The word "semen" has more than one translation in Chinese. Its formal term is "精液" and its obscene term is "洨" (siao2, Mandarin transliteration of Taiwanese dialect; masked by X hereafter).
Because the obscene term comes from Taiwanese, a lot of Taiwanese profanities are written down in many different ways of Mandarin transliterations, as shown in Appendix A. Their meanings are explained as follows. 1. The Taiwanese word "hau-siau5" means "exaggerating" or "trash talking". Its second character has no corresponding Chinese character therefore is usually written as X in text (Rules #12 and #13). 2. The Taiwanese phrase "jia7 siau5" means "eat shxt" and its second character is indeed X. We suggest a milder term to expression the same feeling (Rule #14). 3. The Taiwanese phrase "siaN2 siau5" means "what the hxll" and its second character is indeed X. We suggest a milder term to express the same feeling (Rule #15). Note that "三小" (san-siao3, three + little, what the hxll) is one of the expressions in this category. However, the string may also appear in a common phrase such as "三小時" (three hours). It is rephrased only when it follows a verb (Rule #11). 4. The Taiwanese word "lu5-siau5" means "annoying". Its second character has no corresponding Chinese character therefore is usually written as X in text (Rule #17). 5. If the term really means "semen", it should be replaced with its formal term (Rule #16). 6. The character X can also be used to replace any character with a sound similar to "siao3" when haters write person names or show names. It is not easy to recover the correct characters in the names. The proposed rule is a baseline rule (Rule #18).

Phrases Containing Sex Organs
Sex organs often have several names in Chinese. Their obscene terms 屄 (female genital, masked as B hereafter), 屌 (male genital, masked as D hereafter), and the Taiwanese word "lam7-pha" (scrotum, masked as LP hereafter) have developed different meanings in the Internet as listed here. 1. The word "牛 B" and the character D itself mean "awesome" in some context (Rules #19 and #23). 2. The word "傻 B" means "fool" (Rule #20). 3. The character D can be an adverb meaning "greatly" as in the phrase "D 打" (to defeat greatly) (Rule #24). 4. The character D can also be a verb meaning "to pay attention" as in the phrase "D 你" (to pay attention to you) (Rule #25).

Evaluation
As a preliminary experiment, we evaluated our system in a small test set constructed by the following steps. For each of the 29 rephrasing rules, we randomly selected at most 100 sentences containing corresponding keywords to do the evaluation. Note that some groups were infrequent so we only had less than 100 sentences. There are totally 2,389 sentences in the test set. Each rephrased (or detected but remain unchanged) part was assessed by two assessors in terms of both correct and fluent. The evaluation metric is the ratio of the correctness of the processing by the rephrasing rules. Note that if two or more parts in a sentence were detected, they were assessed separately.
The evaluation result is shown in Table 1, where Acc denotes accuracy. We can see that 15 of 29 groups of rules achieved accuracy above 90% and only 4 groups did not achieved accuracy better than 70%. The overall accuracy was 85.56%. The main error types are discussed as follows.

Out-of-vocabulary problem
Although we have tried to collect as many variants as possible, there are still newly invented ways to transliterate Taiwanese profanity. For example, "F 0 糧" has similar sound to "F 您_娘" (fxxk your mother) but does not appear in our dictionary. It is the major error of Rules #4 and #7.

Similar sound substitution
Haters usually like to disparage the targets whom they are criticizing by replacing characters in the names with profane characters B, D, or X. It is not easy to recover the original names and becomes the major errors of Rules #18, #22, and #26.

Proper names containing obscene words
There is a hamburger restaurant in Taiwan whose name is "牛逼洋行". The term "牛逼" inside its name should not be changed by Rule #19. The accuracy of Rule #19 becomes 94% if our system can recognize this name. 4. Sentence segmentation Some writers are too lazy to use punctuation marks to separate sentences. Words in different sentences are incorrectly adjoined and matched with wrong rephrasing rules. For example, "你 D" should be rephrased into "你厲害" (you are awesome). But "你 D 你 D 你 D…" matches Rule #25 and is incorrectly rephrased as "你理你理你…" (you notice you notice you…).

Conclusion
This paper proposes a system to deal with profanity in Chinese text. The system does not only detect profanity, but also provide rephrased text which is less offensive. Nearly ten thousand sentences containing Chinese profanity were collected from real-world social websites. After human annotation, 29 groups of detection and rephrasing rules were invented. The overall accuracy of our system was 85.56% when evaluating on a test set of 2,389 sentences. Now we have handled five main types of Chinese profanity. We need to look for a larger dataset in order to expand our rephrasing rules and find more types of profanities in the future.
Moreover, the proposed rephrasing rules were hand-crafted. We should try to discover more rules by machine learning.