How do you implement named entity recognition for domain-specific applications?
Named Entity Recognition (NER) identifies and classifies named entities (people, organizations, locations, dates, custom types) in text. Standard NER: pre-trained models (spaCy, Hugging Face token classification) recognize common entity types out of the box. Domain-specific NER requires custom training for specialized entities (drug names, legal terms, financial instruments, product codes). Training approach: annotate domain text with entity labels (use Prodigy, Label Studio, or Doccano for annotation), split into train/validation/test sets (80/10/10), fine-tune a pre-trained model (BERT, RoBERTa, or domain-specific variant like BioBERT for medical, FinBERT for finance), and evaluate using entity-level F1 score. Annotation guidelines: define clear entity boundaries and types, handle nested entities (organization within a location), address ambiguous cases consistently, and maintain inter-annotator agreement above 0.8 Cohen's kappa. Data requirements: typically 2000-5000 annotated sentences for good performance, with at least 200 examples per entity type. Augmentation: generate synthetic training data by replacing entities with same-type alternatives, use LLM-generated examples, and apply text perturbation techniques. Production: implement as a pipeline component (spaCy for fast inference, Hugging Face for maximum accuracy), post-process with rules (regex patterns for structured entities like dates and IDs), and implement confidence thresholds for human review. Advanced: use few-shot NER with large language models (provide examples in the prompt for zero-shot or few-shot entity extraction), and implement active learning to efficiently expand training data.