Abstract
Automated content moderation systems often fail when faced with "malicious" misspellings—intentional typos designed to bypass filters. This paper presents an unsupervised, lightweight correction algorithm that combines edit-distance candidate generation with context-aware word embeddings. By treating the surrounding context as a linear space, the system identifies the most likely correction for obfuscated tokens. Evaluation on toxicity, spam, and hate speech datasets demonstrates that this approach significantly outperforms standard spell checkers, effectively restoring the performance of downstream safety filters.
Introduction
Automated content moderation is a persistent cat-and-mouse game. While standard spell checkers are designed to catch "innocuous" errors—accidental slips of the thumb—malicious actors use "deceptive" misspellings to thwart automated systems. For example, a profanity filter might catch the word "stupid" but fail to flag "stup*d," even though a human reader understands the intent perfectly.
Standard tools often rely on simple edit distances or n-gram statistics that struggle with the creative, non-random nature of adversarial typos. Furthermore, many existing solutions are domain-specific or require massive amounts of annotated training data. This research addresses the challenge of creating a robust, unsupervised system that utilizes surrounding context to "de-obfuscate" these malicious tokens effectively.
Methodology
The proposed system utilizes a two-stage unsupervised algorithm designed to be lightweight and adaptable to various domains:
- Candidate Enumeration: For any word not found in a "valid" vocabulary, the system generates a list of potential corrections using the Damerau-Levenshtein edit distance. This metric accounts for the four most common types of errors: insertions, deletions, substitutions, and transpositions.
- Correction via Context: To select the best candidate, the system employs word embeddings (specifically word2vec CBOW). It treats the surrounding context as a linear space and evaluates candidates based on two factors:
- Geometric Fit: It calculates the distance between a candidate’s word vector and the "linear span" of the vectors of its neighbors.
- Weighted Windows: Recognizing that words closer to the error are usually more informative (e.g., "stubborn" is a better clue for "stup*d" than a word ten tokens away), the algorithm weights the distance by the inverse of the window size.
Because the model is unsupervised, it can be easily adapted to new domains, such as shifting from Twitter slang to formal email, by simply fine-tuning the embeddings on a small corpus of domain-specific text.
Evaluation and Results
The system was evaluated across three distinct applications: toxicity detection (Perspective API dataset), spam detection (Ling-Spam dataset), and real-world hate speech detection (Twitter posts).
As shown in the results, the proposed system consistently outperformed established baselines like PyEnchant, Ekphrasis, and Google’s search-based spell checker. On the Perspective toxicity dataset, the system achieved 84% accuracy, significantly higher than the 71.3% reached by the next best baseline.
Beyond raw accuracy, the system proved highly effective at restoring the performance of downstream filters. In spam detection, malicious errors originally dropped a Naive Bayes classifier's accuracy from 98% to 72%; applying the proposed correction method restored that accuracy more effectively than off-the-shelf tools. On the Twitter hate speech dataset, the system improved the F1-score for the "racist" category by 3.7 absolute points, proving its utility on messy, human-generated data.
Discussion and Limitations
A key insight of this work is that context serves as the ultimate tie-breaker. A misspelled word like "stupd" could morphologically resemble "stud" or "stupid," but the surrounding words allow the model to make the correct semantic choice. Furthermore, by using embeddings, the system can handle "Internet slang" (like tmr or lol) as valid vocabulary if they appear frequently enough in the training corpus, preventing unnecessary "corrections" into standard English.
However, the system does face limitations. It struggled with certain categories, such as sexism-related tweets, which often contain very short abbreviations (e.g., "kys") or lack enough surrounding context for the embedding model to make an informed choice. Future work may involve incorporating character-level embeddings to better capture the "visual" similarity of obfuscated words, such as the use of '0' for 'o' or '@' for 'a'.
Conclusion
This research provides a lightweight, unsupervised solution to the problem of adversarial typos. By leveraging the geometric properties of word embeddings, the system offers a robust pre-processing step that significantly enhances the reliability of automated content moderation in the face of intentional obfuscation.
Summary updated