Technical Implementation and Practice of Rhetorical Device Recognition in Text
This article explores the engineering approach to text rhetorical analysis, transforming literary perception into structured, computable, and verifiable labels. It details a five-layer analysis framework, core computable rhetorical patterns, corpus annotation standards, a three-tier technical architecture, cloud engineering practices, and evaluation methodologies. By leveraging rules, statistics, and models, this guide provides a systematic path to building scalable and controllable rhetorical recognition systems.
1. Problem Background: Why Rhetorical Analysis Needs Engineering
The vividness of a text often stems not from the sheer amount of information, but from structural arrangement: juxtaposing two vastly different quantities, sequentially listing nouns without verbs, or creating rhythm through parallelism. In traditional language education, these phenomena are identified through manual reading. However, when dealing with massive volumes of text (content moderation, public opinion summarization, writing assistance, educational assessment), manual methods fall short in consistency, throughput, and cost.
The goal of engineering is not to “judge whether an article is good,” but to transform rhetorical phenomena into annotatable, computable, and regression-verifiable structured tags. This is the core thesis of this article: rhetorical analysis is a multi-level information extraction and classification task, rather than an end-to-end “scoring” problem.
2. Task Decomposition: A Five-Layer Analysis Framework
Explicitly layering the analysis granularity is the first step in controlling complexity. A unidirectional dependency is maintained between layers, where upper layers only consume the output of lower layers.
- Character Layer: Character types (numbers, units, punctuation), variant character and full/half-width normalization, and the literal morphology of quantitative expressions.
- Word Layer: Part-of-speech tagging, quantitative phrases (numeral + measure word/unit), noun phrase boundaries, and named entities.
- Sentence Layer: Determination of rhetorical devices such as parallelism, contrast, noun sequencing, and rhetorical questions, as well as sentence length and rhythm statistics.
- Paragraph Layer: Inter-sentence relations (coordination, transition, progression), rhetorical density distribution, and topic progression.
- Discourse Layer: Style vectors, rhetorical preference profiles, and paragraph function division (introduction, development, transition, conclusion).
The benefit of layering is that the character and word layers can be entirely resolved using rules and dictionaries, which are stable and have zero training costs. Statistical methods and models are introduced only above the sentence layer, allowing errors to be attributed layer by layer.
3. Computable Core Patterns
3.1 Quantitative Contrast (Juxtaposition of Vastly Different Magnitudes)
There are three key criteria for determination: two or more quantitative phrases exist in the sentence; their units can be normalized to the same dimension; and the ratio exceeds a threshold. The normalization table needs to cover common dimensions such as mass, length, time, and currency, and must retain the “literal original value” because the rhetorical effect depends on the literal difference rather than the converted result.
# Pseudocode to express the judgment logicUNIT_TABLE = { "microgram": ("mass", 1e-6), "gram": ("mass", 1e-3),"ton": ("mass", 1e3), "meter": ("length", 1.0) }def extract_quantities(sentence):return [ (raw, dim, value * factor)for (raw, value, unit) in scan_quantity(sentence)for (dim, factor) in [UNIT_TABLE.get(unit, (None, None))]if dim is not None ]def detect_contrast(sentence, ratio_threshold=1e6):qs = extract_quantities(sentence)for a, b in combinations(qs, 2):if a.dim != b.dim or a.value <= 0:continueratio = max(a.value, b.value) / min(a.value, b.value)if ratio >= ratio_threshold:yield { "left": a.raw, "right": b.raw,"dimension": a.dim, "ratio": ratio }
The threshold should not be fixed to a single value. It is recommended to bucket configurations by dimension and make the threshold a hot-updatable configuration item, facilitating differentiated adjustments for different business scenarios (e.g., educational annotation vs. content recommendation).
3.2 Noun Sequencing (Noun Arrangement, Verb Absence)
The formal characteristic of noun sequencing is a “noun phrase sequence + extremely low verb density.” This can be computed into three metrics: the proportion of noun phrases, the ratio of verbs to nouns, and the number of conjunctions in the sequence. A valid determination is made only when all three metrics exceed their thresholds simultaneously; looking solely at the part-of-speech ratio can easily misjudge a normal list as a rhetorical sequence.
def detect_noun_cluster(tokens, min_len=3):nps = group_noun_phrases(tokens) # Word-layer outputif len(nps) < min_len: return Noneverb_ratio = count_verbs(tokens) / max(len(nps), 1)conj_count = count_conjunctions(tokens)if verb_ratio <= 0.34 and conj_count == 0:return { "phrases": [p.text for p in nps],"verb_ratio": verb_ratio }
3.3 Parallelism and Contrast
Parallelism requires structural symmetry. First, perform syntactic dependency or part-of-speech sequence abstraction (replacing content words with placeholders), then calculate the edit distance between the two placeholder sequences. Contrast relies on an antonym table and the sign of the semantic similarity difference. For both, it is recommended to retain a “confidence score” rather than a hard label, allowing downstream tasks to consume it based on business-specific thresholds.
4. Corpus and Annotation Standards
Rules can cover high-frequency patterns, but the long tail must rely on data. The annotation specification must lock down three things in advance:
- Closed Label System: The enumeration of rhetorical tags is fixed, and annotators are forbidden from creating their own tags. Ambiguous samples go to an arbitration queue.
- Clear Boundary Rules: A sentence can contain multiple rhetorical devices, utilizing multi-labels rather than mutually exclusive single choices. Cross-sentence rhetorical devices are annotated at the paragraph layer.
- Consistency Metrics: The overlap rate of two-person annotations serves as the admission threshold. If a tag definition falls below the threshold, it must be rewritten rather than forced through training.
Regarding data scale, a “small amount of fine-labeled + large amount of weak-labeled” approach is recommended. Weak labels can be produced by the rule engine for pre-training or distillation; fine labels are only used for validation and hard case sets to prevent linear inflation of annotation costs.
5. Three-Tier Technical Architecture
- Rule Layer: Dictionaries, regular expressions, dimension normalization tables. Characterized by zero latency, explainability, and hot updates, responsible for the character and word layers.
- Statistical Layer: Part-of-speech sequence features, n-grams, sentence length and punctuation rhythm, rhetorical density. Outputs structured feature vectors.
- Model Layer: Multi-label fine-tuning on a general pre-trained language model. The input is a sentence or paragraph, and the output is a rhetorical tag and confidence score. The model only handles semantic rhetoric that the rule layer cannot cover.
The three layers are serial and retain their respective outputs, enabling error attribution: for a bad case, first determine whether it is a missing dictionary entry, insufficient features, or a model misjudgment, then decide which layer to fix.
6. Cloud Engineering Implementation
- Access and Buffering: Text flows into a queue service to shave peak loads, ensuring that batch retrospective analysis does not impact the online pipeline.
- Storage: The original text and structured tags are stored separately. The original text goes into object storage, while tags go into relational or search storage, supporting reverse sample lookup by tag.
- Compute: The rule and statistical layers are deployed in containers, while the model layer is supported by an inference service, with grayscale deployment based on dimension configurations and model versions.
- Observability: The logging service collects the latency and confidence distribution of each layer. Monitoring and alerting cover tag distribution drift, sudden drops in rule hit rates, and inference latency percentile breaches.
- Closed Loop: Online low-confidence samples automatically flow back into the hard case set, forming an iterative loop of “supplementing dictionaries for rules and supplementing semantics for models.”
If using Baidu AI Cloud, the above capabilities can be implemented by combining general product categories such as object storage, message queues, container platforms, logging services, and monitoring and alerting, allowing a similar architecture to be completed without being bound to specific interfaces.
7. Evaluation and Common Pitfalls
Evaluation must be layered: the character and word layers look at precision and recall; the sentence layer looks at the macro-average F1 of multi-labels; the discourse layer looks at the correlation between style profiles and manual scores. Additionally, a “pure rule baseline” should be retained. Any model must significantly outperform the baseline before going live to have value.
There are four high-frequency pitfalls: first, an incomplete dimension normalization table leading to missed contrast recalls; second, misjudging normal noun listings as noun sequencing; third, annotation label drift causing inflated metrics; fourth, hardcoding thresholds in the code, which fails when scenarios change. The mitigation methods are to complete dimensions and unit variants, introduce the dual constraints of verb density and conjunction count, freeze annotation version numbers, and fully configurate thresholds.
8. Conclusion
The key to landing rhetorical analysis is translating “literary perception” into “layered computable features”: the character and word layers use rules and dictionaries to ensure stability, layers above the sentence use statistics and models to supplement semantics, and the full chain maintains controllability through configurable thresholds and layered evaluation. Proceeding along this path yields interpretable intermediate results and allows for a smooth upgrade of model capabilities after data accumulation, avoiding one-shot rewrites.
