Building a Delicate Text Detection System for Content Safety

grammarly · Tech · 2024 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.4 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: AI content safety and delicate-text detection

Grammarly needed a way to detect emotionally charged or potentially triggering text that existing toxicity detectors miss, because harmful user or model interactions are broader than profanity or explicit abuse.

Constraints:

Architecture

Grammarly created DeTexD as both a training dataset and benchmark. The team sourced candidate text through domain specification and delicate-keyword matching, annotated it with expert linguists using a two-step process, fine-tuned a RoBERTa-based classifier, and evaluated it against existing toxicity-oriented methods on the DeTexD Benchmark.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  candidate-text-sources[Candidate text sources] --> keyword-dictionary[Keyword dictionary]
  candidate-text-sources --> annotation-process[Annotation process]
  keyword-dictionary --> annotation-process
  annotation-process --> detexd-training-dataset[DeTexD Training dataset]
  annotation-process --> detexd-benchmark-dataset[DeTexD Benchmark dataset]
  detexd-training-dataset --> roberta-based-classifier[RoBERTa-based classifier]
  roberta-based-classifier --> detexd-benchmark-dataset
  external-toxicity-methods[External toxicity methods] --> detexd-benchmark-dataset
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Candidate text sources News sites, sensitive-topic forums, and controversial forums used to source potential delicate text. Keyword dictionary, Annotation process
Keyword dictionary Delicate-keyword list with severity ratings used to refine and extract candidate texts. Candidate text sources, Annotation process
Annotation process Expert-linguist labeling workflow for delicacy and risk level with majority-vote final labels. DeTexD Training dataset, DeTexD Benchmark dataset
DeTexD Training dataset 40,000-sample labeled dataset used to train the baseline classifier. RoBERTa-based classifier
RoBERTa-based classifier Fine-tuned baseline model for delicate-text classification. DeTexD Training dataset, DeTexD Benchmark dataset
DeTexD Benchmark dataset 1,023-paragraph labeled benchmark used to compare the baseline with toxicity-detection methods. RoBERTa-based classifier, External toxicity methods
External toxicity methods Existing hate-speech, offensive-language, Perspective API, and moderation baselines evaluated against DeTexD. DeTexD Benchmark dataset

Data flow

Candidate text came from targeted domains and delicate-keyword matching. Expert linguists labeled whether each text was delicate and rated risk. The labeled DeTexD Training dataset was used to fine-tune a RoBERTa-based classifier, and the DeTexD Benchmark measured how well that model and other toxicity detectors captured delicate text.

3 supporting quotes
“Domain specification: We specifically targeted news websites, forums discussing sensitive topics, and generally controversial forums.”article, stated
“To mitigate this, we provided annotators with detailed examples and instructions, which can be found in our paper. We also used a two-step annotation process: annotators first identified whether texts were delicate or not, and then rated the risk level of delicate texts.”article, stated
“We also used a two-step annotation process: annotators first identified whether texts were delicate or not, and then rated the risk level of delicate texts.”article, stated

Why this architecture

Grammarly treated delicate text as a separate detection problem instead of stretching toxicity classifiers to cover it. A dedicated dataset, expert annotation, and task-specific classifier were necessary because broad toxicity definitions either missed sensitive coverage or misclassified offensive-but-not-delicate examples.

3 supporting quotes
“Our theory was that delicate text detection and toxic text detection are two distinct tasks. To test this, we evaluated our model on several canonical toxic text datasets.”article, stated
“On the other hand, our model tends to classify texts dealing with topics like race, violence, and sexuality as delicate, even though these texts may not be labeled as toxic. Ultimately, “toxic” and “delicate” are very different concepts.”article, stated
“However, none of the toxic language detection methods that we studied perform very well at detecting delicate text.”article, stated

Models used: RoBERTa-based classifier · Google Perspective API · OpenAI moderation API

Scale

Alternatives considered (roads not taken)

Reuse toxic-text detection as the safety boundary

Rejected because: Delicate text can be non-toxic but still harmful, and toxicity detectors missed important coverage.

“we’ve seen a gap when it comes to the broader category of delicate text, which may not be characterized as toxic but still presents a risk.”article, stated

Rely on Google Perspective API or OpenAI moderation API

Rejected because: The reported benchmark scores were much lower than the DeTexD baseline for this task.

“Google’s Perspective API 77.2% 29.2% 42.3% OpenAPI content filter 55.0% 64.0% 58.9%”article, stated

Use keyword matching alone

Rejected because: Keyword matching helped source candidates, but final labels required expert annotation and majority vote.

“All annotators were expert linguists with previous experience in similar tasks; the final label was decided by majority vote.”article, stated

Patterns

safety-policy-enforcement (safety)

Grammarly broadened safety detection beyond toxicity by defining and detecting delicate text that could harm users or agents.

“Delicate text may not be explicitly offensive and may contain no vulgar language, but it carries a risk for users or agents”article, stated

data-quality-loop (data)

The benchmark depended on targeted data sourcing, expert instructions, two-step annotation, and majority-vote labels.

“The annotation of datasets containing delicate text presents a unique challenge given its subjective nature.”article, stated

fine-tuning-adaptation (modeling)

Grammarly fine-tuned a RoBERTa-based classifier on the DeTexD Training dataset for the delicate-text task.

“We began by fine-tuning a classification model on the DeTexD Training dataset.”article, stated

eval-driven-development (evaluation)

The DeTexD Benchmark compared the dedicated classifier against canonical toxicity and moderation baselines.

“we hypothesized that approaches to detect hate speech will underperform on the DeTexD Benchmark dataset, compared to our baseline model.”article, stated

Tradeoffs

Build a dedicated delicate-text benchmark

Chose DeTexD as a separate safety dataset and benchmark over using existing toxicity datasets as-is.

Rationale: Existing toxic-text definitions missed or mischaracterized delicate text.

“There is no clear border between delicate text and toxic text, and it’s possible for text to fall into both categories.”article, stated

Use keyword matching for candidate mining but expert annotation for labels

Chose keyword-based sourcing plus human linguistic judgment over fully automated keyword labeling.

Rationale: Keywords can identify candidate topics, but delicacy and risk require subjective expert labeling.

“We developed a dictionary of delicate keywords along with a severity rating for each keyword. We used this dictionary to further refine our dataset”article, stated

Publish artifacts with explicit caution

Chose public benchmark/model availability with due-diligence warnings over frictionless reuse as a drop-in production filter.

Rationale: The benchmark includes sensitive content and needs privacy, security, legal, and compliance review before operational use.

“Due to the nature of the subject matter, the DeTexD Benchmark dataset includes a variety of uncensored sensitive content”article, stated

Gotchas (what bit them)

Toxicity detection is not a sufficient proxy for delicate text.

Root cause: Delicate text includes emotional or triggering topics that may not contain vulgar or explicitly offensive language.

Resolution: Define delicate text separately and build a task-specific benchmark and classifier.

“Delicate text may not be explicitly offensive and may contain no vulgar language, but it carries a risk for users or agents”article, stated

Subjective safety categories are hard to annotate consistently.

Root cause: Delicate text depends on sensitive topics and risk judgments rather than a simple objective label.

Resolution: Use detailed annotation instructions, expert linguists, risk-level labeling, and majority vote.

“To mitigate this, we provided annotators with detailed examples and instructions, which can be found in our paper.”article, stated

Released safety datasets can themselves contain harmful sensitive content.

Root cause: A realistic benchmark includes uncensored examples across hate speech, violence, threats, self-harm, mental health, sexuality, and profanity.

Resolution: Warn users not to use the artifacts without privacy, security, sensitivity, legal, and compliance due diligence.

“we do not recommend using these artifacts without proper due diligence for privacy, security, sensitivity, legal, and compliance measures.”article, stated

Evaluation

Grammarly evaluated the fine-tuned baseline and several toxicity methods on the DeTexD Benchmark using precision, recall, and F1 score.

Metrics: 79.3% F1 for the DeTexD baseline · 42.3% F1 for Google Perspective API · 31.1% F1 for OpenAI moderation API

“We evaluated several methods on precision, recall, and F1 score (a metric that combines precision and recall).”article, stated
“The evaluated methods either miss coverage, specifically on medical and mental health topics, show lower precision on examples that contain offensive keywords”article, stated

Outcomes

The key scale numbers are dataset and benchmark sizes: 40,000 training samples and 1,023 benchmark paragraphs.

“The result was the labeled DeTexD Training dataset of 40,000 samples and the labeled DeTexD Benchmark dataset of 1,023 paragraphs.”article, stated
“We’ve made our annotation guidelines, annotated benchmark dataset, and baseline model publicly available.”article, stated