Entity swapping is a rule-based or model-driven technique for synthetic data generation where specific spans of text corresponding to named entities—such as persons, organizations, locations, or dates—are identified and substituted with alternative entities of the same category. This process, often powered by named entity recognition (NER) systems and entity libraries, creates semantically coherent variations of original sentences. The primary goal is to expand training datasets for NLP models, particularly for tasks like relation extraction, coreference resolution, and intent classification, by introducing greater lexical diversity without altering the underlying syntactic structure or logical meaning of the statement.
Glossary
Entity Swapping

What is Entity Swapping?
Entity swapping is a data augmentation technique in natural language processing where named entities within a text are systematically replaced with other entities of the same semantic type to generate new, plausible training examples.
This technique directly addresses data scarcity and privacy concerns by allowing the creation of large, privacy-preserving datasets where real, sensitive identifiers are removed. For example, in the sentence "Elon Musk founded SpaceX in Hawthorne," a swap might produce "Sundar Pichai founded Google in Mountain View." Effective implementation requires maintaining semantic plausibility and contextual consistency; swapping "London" for "Microsoft" would break coherence. It is a foundational method within synthetic data for NLP, often used in conjunction with other augmentation strategies like paraphrasing and backtranslation to build robust, generalizable language models, especially in domain-specific or low-resource settings.
Key Characteristics of Entity Swapping
Entity swapping is a data augmentation technique where named entities (e.g., persons, locations) in a text are replaced with other entities of the same type to generate new, semantically plausible examples. This method is fundamental for creating robust training data for NLP tasks like named entity recognition and relation extraction.
Core Mechanism
The process involves two key steps: Named Entity Recognition (NER) to identify and classify entities in a source text, followed by a replacement operation using a curated list of entities of the same semantic type. For example, the sentence 'Elon Musk founded SpaceX in Hawthorne.' could be transformed to 'Jeff Bezos founded Blue Origin in Kent.' by swapping PERSON and LOCATION entities. This preserves the original syntactic structure while altering the factual content.
Primary Use Cases
Entity swapping is primarily deployed to:
- Augment training data for NER models, increasing the diversity of entity mentions a model sees without manual annotation.
- Improve model robustness and generalization by preventing overfitting to specific named entities present in a limited original dataset.
- Generate privacy-preserving synthetic data by obfuscating real-world identifiers (e.g., patient names, company names) in sensitive documents while maintaining linguistic and structural fidelity for downstream NLP tasks.
Entity Type Consistency
The technique's validity hinges on strict semantic type preservation. Swaps must occur within coherent categories defined by an ontology, such as:
- PER (Person): Elon Musk → Satya Nadella
- LOC (Location): Paris → Tokyo
- ORG (Organization): Google → Pfizer
- MISC (Miscellaneous): Python → Java Failure to maintain type consistency (e.g., swapping a PERSON for a LOCATION) produces nonsensical, low-quality data that can harm model performance.
Contextual Plausibility
Advanced entity swapping systems must evaluate contextual plausibility. A naive swap may create semantically anomalous or factually incoherent sentences. For instance, swapping 'Paris' for 'Sahara' in 'She enjoyed the rainy weather in Paris.' creates a contradiction. Mitigation strategies include:
- Using knowledge graphs to ensure swapped entities share relevant properties (e.g., both are capital cities).
- Implementing co-reference resolution to consistently swap all mentions of an entity within a document.
- Applying linguistic constraints to handle grammatical agreement (e.g., ensuring proper article usage: 'a CEO' vs. 'an FBI agent').
Relation to Other Techniques
Entity swapping is a specialized form of data augmentation and is often combined with other NLP synthesis methods:
- Paraphrasing: Swapping entities within a paraphrased sentence for even greater diversity.
- Template Filling: Using entity-swapped lists to populate predefined sentence templates at scale.
- Backtranslation: Applying entity swaps to the back-translated text to augment non-English data. It is distinct from text perturbation (e.g., synonym replacement) as it operates on a discrete, structured level of named entities rather than individual words.
Validation and Quality Metrics
Assessing the quality of entity-swapped data is critical. Key validation metrics include:
- Semantic Acceptability: Human or model-based scoring of whether the swapped sentence remains coherent and plausible.
- Entity Type Accuracy: Verification that all swaps correctly maintain the original NER tag.
- Utility for Downstream Tasks: The ultimate test is the performance improvement (or non-degradation) of an NER or relation extraction model trained on the augmented dataset versus the original. Poorly validated swaps can introduce noise and degrade model performance rather than improve it.
How Entity Swapping Works: A Technical Mechanism
Entity swapping is a data augmentation technique where named entities (e.g., persons, locations) in a text are replaced with other entities of the same type to generate new, semantically plausible examples.
The mechanism begins with named entity recognition (NER) to identify and classify spans of text into predefined categories like PERSON, ORGANIZATION, or LOCATION. A replacement entity pool—curated from knowledge bases or generated synthetically—provides candidate substitutes of the same semantic type. The core operation is a deterministic or probabilistic substitution function that swaps the original entity mention for a new one, ensuring grammatical agreement (e.g., verb conjugation, article usage) is preserved through simple post-processing rules.
This technique directly expands dataset diversity for sequence labeling tasks like NER and relation extraction, where models must learn to generalize the abstract entity type rather than memorize specific names. It is a foundational component of privacy-preserving synthesis, as swapping personal identifiers with fictitious ones can anonymize sensitive documents. When integrated into a data augmentation pipeline, entity swapping is often combined with other techniques like paraphrasing or text perturbation to create robust, multi-faceted training examples for language models.
Common Use Cases and Applications
Entity swapping is a versatile synthetic data technique primarily used to enhance model robustness and protect privacy. Its applications span from improving core NLP tasks to enabling secure data sharing.
Named Entity Recognition (NER) Augmentation
Entity swapping is a cornerstone technique for augmenting training data for Named Entity Recognition (NER) models. By systematically replacing entities within annotated sentences, it creates new, valid training examples that teach the model to focus on contextual patterns and entity boundaries rather than memorizing specific names.
- Improves Generalization: Models learn that "[PERSON] works at [ORGANIZATION] in [LOCATION]" is a valid pattern, regardless of the specific entities.
- Creates Edge Cases: Swapping in rare or novel entity names helps the model handle out-of-vocabulary terms.
- Preserves Annotation: The original syntactic structure and entity type labels (PER, ORG, LOC) remain intact, providing high-quality supervisory signals.
Relation Extraction & Knowledge Graph Population
This technique is critical for generating training data for Relation Extraction (RE) models, which identify semantic relationships (e.g., works_for, located_in) between entities in text. Swapping entity pairs within known relationship contexts creates diverse examples without altering the underlying relational logic.
- Scales Training Data: From a single fact "Elon Musk founded SpaceX," swapping generates "Jeff Bezos founded Blue Origin" and "Larry Page founded Google."
- Tests Logical Consistency: Ensures the model learns the predicate
foundedconnects aPERSONto anORGANIZATION, not just specific famous pairs. - Populates Knowledge Graphs: Generated entity-relation-entity triples can be used to synthetically expand or validate knowledge graphs, especially in domains with sparse real data.
Privacy-Preserving Data Sharing
Entity swapping is a direct method for de-identifying sensitive text data, such as medical records, legal documents, or financial reports, enabling safer sharing for research or development. Real personal identifiers (names, addresses, IDs) are replaced with plausible but fictional counterparts.
- Preserves Utility: The grammatical structure, statistical relationships, and clinical or legal concepts remain, keeping the data useful for model training.
- Mitigates Re-identification Risk: Unlike simple masking (e.g., [NAME]), swapped entities maintain linguistic realism without leaking private information.
- Complements Differential Privacy: Can be used in conjunction with formal privacy frameworks to create layered data protection.
Bias Mitigation & Fairness Auditing
By controllably swapping demographic indicators (e.g., names, pronouns, locations associated with specific groups), practitioners can audit and reduce model bias. This creates counterfactual examples to test for spurious correlations.
- Detects Spurious Correlations: If a sentiment model changes its prediction when "Jamal" is swapped for "Connor" in an otherwise identical review, it indicates name-based bias.
- Creates Balanced Datasets: Can oversample underrepresented entity combinations in training data to improve fairness.
- Enables Stress Testing: Systematic swapping of gender, ethnicity, or nationality markers reveals a model's sensitivity to protected attributes.
Question Answering & Machine Reading Comprehension
For Question Answering (QA) systems, entity swapping is used to generate new (context, question, answer) triplets. The context passage is modified by swapping entities, and the question and answer are updated correspondingly, ensuring perfect alignment.
- Expands Training Corpora: Crucial for domain-specific QA (e.g., biomedical, legal) where real Q&A pairs are scarce.
- Tests Robust Understanding: Ensures models learn to answer "Who is the CEO?" based on textual evidence, not prior knowledge about a specific company.
- Creates Adversarial Evaluation Sets: Can be used to construct test sets where only the entity has changed, testing if a model relies on memorization versus true comprehension.
Dialogue System Training
In training task-oriented dialogue systems (e.g., for booking or customer service), entity swapping diversifies the dialogue state tracking and natural language generation data. User utterances and system responses are modified by swapping slot values (e.g., restaurant names, dates, product IDs).
- Generalizes to New Entities: A restaurant booking bot trained with swapped data can handle reservations for a new restaurant not in its original training set.
- Maintains Dialogue Coherence: The conversation flow and intent remain logical despite entity changes.
- Accelerates Bot Deployment: Reduces the need to collect thousands of real dialogues for every new product or service entity in a catalog.
Entity Swapping vs. Other NLP Augmentation Techniques
A feature-by-feature comparison of entity swapping against other common text augmentation methods, highlighting their distinct mechanisms, use cases, and trade-offs for synthetic data generation.
| Feature / Metric | Entity Swapping | Backtranslation | Paraphrasing | Text Perturbation |
|---|---|---|---|---|
Core Mechanism | Replaces named entities (e.g., persons, locations) with same-type alternatives. | Translates text to another language and back to the original. | Rewrites text to convey the same meaning with different phrasing. | Applies small, stochastic edits (e.g., synonym swap, character deletion). |
Semantic Preservation | ||||
Syntactic Preservation | ||||
Entity-Level Diversity | ||||
Requires External Model/API | ||||
Typical Latency per Sample | < 1 ms | 200-500 ms | 50-200 ms | < 10 ms |
Primary Use Case | Augmenting NER, relation extraction, and de-identification. | Improving translation robustness and general language understanding. | Training models for semantic similarity and question answering. | Improving robustness to typos and minor input variations. |
Risk of Semantic Drift | Low (controlled by entity type) | Medium | Low-Medium | High |
Common Implementation | Rule-based with knowledge base lookup. | Sequence-to-sequence model or third-party API. | Large language model or paraphrasing model. | Lightweight rule-based or statistical library. |
Frequently Asked Questions
Entity swapping is a core technique in synthetic data generation for natural language processing. This FAQ addresses common technical questions about its implementation, applications, and relationship to other augmentation methods.
Entity swapping is a data augmentation technique where named entities (e.g., persons, organizations, locations, dates) within a text are systematically replaced with other entities of the same semantic type to generate new, semantically plausible training examples. The process typically involves three core steps: first, a named entity recognition (NER) model identifies and classifies entities in the source text; second, a replacement entity is sampled from a predefined list or knowledge base for each entity type; and third, the original entities are substituted, ensuring grammatical agreement (e.g., adjusting pronouns or verb conjugation) where necessary. For example, the sentence "Elon Musk founded SpaceX in Hawthorne." could be transformed into "Sundar Pichai founded Google in Mountain View." by swapping the PERSON and ORGANIZATION entities and their corresponding LOCATION. This technique artificially expands dataset diversity, particularly for tasks like relation extraction and question answering, where model performance depends on understanding relationships between entities rather than memorizing specific names.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Entity swapping is one of several core techniques for generating artificial text data. These related methods are essential for building robust, privacy-preserving, and well-understood natural language processing systems.
Data Augmentation
Data augmentation is a foundational set of techniques for artificially expanding a training dataset by creating modified versions of existing data points. In NLP, this includes methods like entity swapping, paraphrasing, and backtranslation.
- Primary Goal: Improve model generalization and robustness by exposing it to a wider distribution of linguistic variations.
- Core Principle: Apply label-preserving transformations to create new, valid training examples.
- Example: For a sentiment classifier, augmenting "The movie was great" to "The film was excellent" provides a semantically equivalent training point.
Paraphrasing
Paraphrasing is the process of generating alternative phrasings of a given text while preserving its original meaning. It is a critical data augmentation technique for teaching models semantic equivalence.
- Techniques: Range from rule-based synonym replacement to advanced neural generation using sequence-to-sequence models.
- Utility: Creates diverse training data for tasks like question answering, textual entailment, and semantic search.
- Contrast with Entity Swapping: While entity swapping changes specific named entities, paraphrasing alters the broader syntactic structure and word choice of a sentence.
Template Filling
Template filling is a rule-based text generation technique where a predefined sentence structure (a template) is populated with specific values or entities from a knowledge base.
- Mechanism: Uses slot-value pairs to instantiate templates like
[PERSON] works at [ORGANIZATION] in [LOCATION]. - Use Case: Rapidly generates large volumes of structured, domain-specific text for training named entity recognition (NER) and relation extraction models.
- Relation to Entity Swapping: Can be seen as a more controlled, schema-driven precursor. Entity swapping often operates on already-extracted entities within free-form text.
Controlled Generation
Controlled generation refers to techniques that allow a language model to produce text conforming to specific, predefined attributes, such as topic, sentiment, style, or—critically—specific entities.
- Methods: Includes conditional training, prompt engineering, guided decoding, and plug-and-play language models.
- Application: Directly enables the creation of synthetic data with desired properties, such as dialogues with a specific persona or documents about a target domain.
- Precision: Entity swapping is a form of fine-grained controlled generation where the control attribute is the semantic type (e.g., PERSON, LOCATION) of the tokens to be generated.
Synthetic Fine-Tuning (SFT)
Synthetic Fine-Tuning (SFT) is the process of adapting a pre-trained language model using a dataset of artificially generated examples. This is often the downstream application of techniques like entity swapping.
- Workflow: 1. Use entity swapping, paraphrasing, etc., to create a task-specific synthetic dataset. 2. Fine-tune a base model (e.g., GPT, LLaMA) on this dataset via supervised learning.
- Advantage: Allows for domain specialization or task adaptation without the cost and privacy concerns of collecting large real-world datasets.
- Validation: The utility of SFT depends entirely on the quality and fidelity of the underlying synthetic data generation process.
Privacy-Preserving Synthesis
Privacy-preserving synthesis encompasses techniques for generating data that protects individual privacy, making it a key driver for using methods like entity swapping in regulated industries.
- Core Techniques:
- Differential Privacy: Adds mathematical noise to data or training processes to guarantee privacy.
- k-Anonymity: Ensures each individual in a dataset is indistinguishable from at least k-1 others.
- Synthetic Generation: Creating entirely new, statistically similar records that contain no real personal data.
- Role of Entity Swapping: Directly removes or obfuscates Personally Identifiable Information (PII) by replacing real names, addresses, and IDs with fictional equivalents, breaking the link to original individuals.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us