CodeNER: Code Prompting for Named Entity Recognition

arXiv cs.CL / 3/27/2026

💬 OpinionIdeas & Deep AnalysisModels & Research

Key Points

  • CodeNER introduces a “code-based prompting” approach for named entity recognition (NER) that embeds code and provides explicit BIO schema labeling instructions to guide LLMs beyond plain text context.
  • The method is designed to better capture NER’s detailed labeling requirements while leveraging LLM abilities to handle long-range structure, analogous to programming-language scopes.
  • Experiments on ten benchmarks across multiple languages (English, Arabic, Finnish, Danish, and German) show code-based prompting outperforms conventional text-based prompting.
  • The paper reports additional gains when code-based prompting is combined with chain-of-thought prompting, further improving NER performance.

Abstract

Recent studies have explored various approaches for treating candidate named entity spans as both source and target sequences in named entity recognition (NER) by leveraging large language models (LLMs). Although previous approaches have successfully generated candidate named entity spans with suitable labels, they rely solely on input context information when using LLMs, particularly, ChatGPT. However, NER inherently requires capturing detailed labeling requirements with input context information. To address this issue, we propose a novel method that leverages code-based prompting to improve the capabilities of LLMs in understanding and performing NER. By embedding code within prompts, we provide detailed BIO schema instructions for labeling, thereby exploiting the ability of LLMs to comprehend long-range scopes in programming languages. Experimental results demonstrate that the proposed code-based prompting method outperforms conventional text-based prompting on ten benchmarks across English, Arabic, Finnish, Danish, and German datasets, indicating the effectiveness of explicitly structuring NER instructions. We also verify that combining the proposed code-based prompting method with the chain-of-thought prompting further improves performance.