ABSTRACT Protecting sensitive data is important in healthcare to ensure privacy and follow rules like the General Data Protection Regulation (GDPR) and Health Insurance Portability and Accountability Act (HIPAA). However, existing studies struggle to handle unstructured data, miss sensitive information like compound entities, and reduce the usefulness of data during the anonymization process. This study aims to create a better model that can identify and anonymize sensitive data accurately and handle complex data. This work proposes an innovative method for preserving sensitive data in healthcare, incorporating natural language processing (NLP)‐based entity recognition and dual‐layered encryption‐based anonymization. The data is preprocessed with SpaCy for tokenization, lemmatization, and regex‐based pattern recognition to preserve formats like dates and IDs while identifying entities such as dates, diseases, and locations. Biomedical Clinical Bidirectional Encoder Representations from Transformers (BioClinicalBERT) and SpaCy are fine‐tuned with healthcare data, using subword‐level tokenization. Hyperparameter tuning optimizes performance by adjusting learning rate, batch size, and epochs. BioClinicalBERT, SpaCy, SciSpaCy, and regex patterns are then combined to detect sensitive information, which is anonymized using dynamic masking and encryption for comprehensive privacy protection. Our model performed well, with a macro‐average F1 score of 0.82, a micro‐average F1 score of 0.94, and high precision in recognizing sensitive entities like ID, religion, and marital status. This research also anonymizes unstructured data effectively. This outperforms existing methods by accurately detecting complex compound entities often missed by rule‐based systems. Moreover, compared to previous anonymization method, our dual‐layered anonymization process preserves data utility for research purposes. This research enhances patient data privacy in healthcare environments, ensuring compliance with GDPR and HIPAA regulations. It enables safer, more effective utilization of medical data for clinical research.
Setu et al. (Sun,) studied this question.