Named Entity Recognition (NER) with GenAI

Named Entity Recognition (NER) with GenAI
Source: https://cloud.google.com/natural-language - Rebeka Kiss

Named Entity Recognition (NER) is a key technique in natural language processing that involves identifying and classifying specific entities in a text, such as people, organisations, locations or dates. The following prompt offers a structured and nuanced approach to testing NER capabilities using a rich biographical narrative.

The prompt instructs the model to extract all named entities from a continuous text focusing on Barack and Michelle Obama, assigning each instance to a predefined category drawn from an explicit taxonomy—including Person, Organisation, Geo-Political Entity, Law, among others. The prompt instructs the model to extract all named entities from a continuous text focusing on Barack and Michelle Obama, assigning each instance to a predefined category drawn from an explicit taxonomy—including Person, Organisation, Geo-Political Entity, Law, among others. It explicitly requires the model to list entities in the order of their appearance and to include each occurrence, even if repeated. This approach emphasizes contextual sensitivity as well as consistency in classification. The expected output is clearly defined: a numbered list, with each item containing the identified entity and its corresponding category.

Prompt

Identify all named entities in the following input text. For each entity, indicate its category from the following list:


  • Organisation: Companies, agencies, institutions, and other formally named groups (e.g. Google, United Nations).
  • Product: Physical objects such as devices, vehicles, foods, and other tangible items, excluding services (e.g. iPhone, Toyota Corolla).
  • Law: Named legal documents or pieces of legislation (e.g. Civil Rights Act, GDPR).
  • Work of Art: Titles of creative works, including books, films, songs, paintings, and similar artistic outputs (e.g. Hamlet, The Starry Night).
  • Person: Named individuals, both real and fictional (e.g. Barack Obama, Sherlock Holmes).
  • Location: Geographical places that do not have political or administrative status, such as mountain ranges, oceans, or landmarks (e.g. Sahara Desert, Pacific Ocean).
  • Geo-Political Entity: Locations with political or administrative boundaries and governance, such as countries, cities, and states (e.g. France, New York, California).
  • Ordinal Number: Words indicating position or rank in a sequence (e.g. first, second, 3rd).
  • Event: Named historical, social, political, or sporting events (e.g. World War II, Olympic Games).
  • Cardinal Number: Numerals expressing quantity that do not fall under other categories (e.g. 100, five million, two).
  • Nationality, Religious or Political Group: Named groups based on nationality, religion, or political affiliation (e.g. Hungarian, Buddhist, Democrats).
  • Date: Specific or relative calendar references, including full dates, months, years, or time periods (e.g. 4 July 1998, last year).

Go through the text in order, and create a numbered list of all named entities as they appear. Each entity should be listed every time it occurs, even if it has appeared earlier in the text. Please only include entities that belong to one of the categories listed above. Do not include any entity that does not fall into one of the categories listed above.


Present your output as a numbered list, with each item containing: Entity – Category


"""[Barack Obama, the 44th President of the United States, served two terms in office from 2009 to 2017. Born on August 4, 1961, in Honolulu, Hawaii, Obama was the first African American to hold the highest office in the country. His presidency was marked by significant achievements in both domestic and foreign policy. Barack Obama’s wife, Michelle Obama, was an influential First Lady who championed numerous initiatives related to health, education, and veterans' affairs. Michelle Obama, originally Michelle LaVaughn Robinson, was born on January 17, 1964, in Chicago, Illinois. She met Barack Obama while working at a law firm in Chicago, and the two married in 1992.
Together, Barack and Michelle Obama have two daughters, Malia Obama and Sasha Obama. Malia Ann Obama was born on July 4, 1998, while Natasha Marian Obama, known as Sasha, was born on June 10, 2001. The Obama family resided in the White House for eight years, making their mark as a close-knit and public-minded first family.
During his presidency, Barack Obama’s administration focused on major issues such as healthcare reform, the economic recovery from the Great Recession, and the killing of Osama bin Laden. One of his landmark achievements was the Affordable Care Act, often referred to as "Obamacare," which aimed to provide affordable healthcare to millions of uninsured Americans. Key figures in Obama’s cabinet included Hillary Clinton, who served as Secretary of State from 2009 to 2013, and Joe Biden, the Vice President of the United States during both terms.
In foreign affairs, Barack Obama's administration sought to improve relations with other nations and promote diplomacy. For instance, Secretary of State Hillary Clinton played a pivotal role in initiating the U.S. pivot to Asia, focusing on enhancing diplomatic ties and economic engagement with countries in the Asia-Pacific region. Another notable member of Obama's administration was John Kerry, who succeeded Hillary Clinton as Secretary of State in 2013. Under Kerry’s leadership, the Obama administration was instrumental in negotiating the Iran nuclear deal, officially known as the Joint Comprehensive Plan of Action (JCPOA), aimed at preventing Iran from developing nuclear weapons.
In addition to his political achievements, Barack Obama was also known for his inspirational speeches, such as his address on race relations in America, often referred to as the "A More Perfect Union" speech, delivered in 2008. He frequently spoke about themes of hope, change, and unity, which resonated with many Americans.
Barack Obama’s legacy also includes his administration’s efforts to combat climate change. His administration actively participated in the Paris Agreement, a landmark international treaty adopted in 2015, which brought together nations to tackle global warming and reduce greenhouse gas emissions. Barack Obama's Environmental Protection Agency (EPA) worked on implementing regulations to limit carbon emissions from power plants, which were significant steps in the fight against climate change.
Michelle Obama also played a crucial role in promoting healthy lifestyles and educational opportunities for children and young adults. Her "Let’s Move!" initiative aimed to combat childhood obesity by encouraging healthier food choices and increased physical activity. Michelle also launched the "Reach Higher" initiative, which inspired students to pursue higher education and training beyond high school.
After leaving office, Barack Obama and Michelle Obama continued their public service through the Obama Foundation, established to inspire and empower the next generation of leaders. The couple also signed a deal with Netflix to produce content, including documentaries and series that align with their values and vision for the future.
In summary, Barack Obama, along with his wife Michelle Obama, left a lasting impact on American society through their leadership, advocacy, and commitment to service. Their legacy is characterized by efforts to improve healthcare, address climate change, promote education, and inspire hope and unity among the American people.]"""

This prompt offers a clear and replicable framework for testing Named Entity Recognition across a range of entity types. It is particularly well suited for evaluating how models handle classification consistency and contextual sensitivity in longer, narrative-style texts. The input text provided can easily be replaced with other domain-specific content, allowing for flexible adaptation to various research or instructional purposes.

Output

The prompt was tested using the GPT-4.5 model, which identified 89 named entities in the input text.

Named Entities – Annotated List

  1. Barack Obama – Person
  2. 44th – Ordinal Number
  3. President – Person
  4. United States – Geo-Political Entity
  5. two – Cardinal Number
  6. 2009 – Date
  7. 2017 – Date
  8. August 4, 1961 – Date
  9. Honolulu – Geo-Political Entity
  10. Hawaii – Geo-Political Entity
  11. Obama – Person
  12. first – Ordinal Number
  13. African American – Nationality, Religious or Political Group
  14. Barack Obama – Person
  15. Michelle Obama – Person
  16. First Lady – Person
  17. Michelle Obama – Person
  18. Michelle LaVaughn Robinson – Person
  19. January 17, 1964 – Date
  20. Chicago – Geo-Political Entity
  21. Illinois – Geo-Political Entity
  22. Barack Obama – Person
  23. Chicago – Geo-Political Entity
  24. 1992 – Date
  25. Barack – Person
  26. Michelle Obama – Person
  27. two – Cardinal Number
  28. Malia Obama – Person
  29. Sasha Obama – Person
  30. Malia Ann Obama – Person
  31. July 4, 1998 – Date
  32. Natasha Marian Obama – Person
  33. Sasha – Person
  34. June 10, 2001 – Date
  35. Obama – Person
  36. White House – Geo-Political Entity
  37. eight – Cardinal Number
  38. Barack Obama – Person
  39. Great Recession – Event
  40. Osama bin Laden – Person
  41. Affordable Care Act – Law
  42. Obamacare – Law
  43. Americans – Nationality, Religious or Political Group
  44. Obama – Person
  45. Hillary Clinton – Person
  46. Secretary of State – Person
  47. 2009 – Date
  48. 2013 – Date
  49. Joe Biden – Person
  50. Vice President – Person
  51. United States – Geo-Political Entity
  52. Barack Obama – Person
  53. Hillary Clinton – Person
  54. U.S. – Geo-Political Entity
  55. Asia – Geo-Political Entity
  56. Asia-Pacific – Geo-Political Entity
  57. Obama – Person
  58. John Kerry – Person
  59. Hillary Clinton – Person
  60. Secretary of State – Person
  61. 2013 – Date
  62. Kerry – Person
  63. Obama – Person
  64. Iran nuclear deal – Event
  65. Joint Comprehensive Plan of Action – Law
  66. JCPOA – Law
  67. Iran – Geo-Political Entity
  68. Barack Obama – Person
  69. America – Geo-Political Entity
  70. A More Perfect Union – Work of Art
  71. 2008 – Date
  72. Americans – Nationality, Religious or Political Group
  73. Barack Obama – Person
  74. Paris Agreement – Law
  75. 2015 – Date
  76. Barack Obama – Person
  77. Environmental Protection Agency – Organisation
  78. EPA – Organisation
  79. Michelle Obama – Person
  80. Let’s Move! – Work of Art
  81. Michelle – Person
  82. Reach Higher – Work of Art
  83. Barack Obama – Person
  84. Michelle Obama – Person
  85. Obama Foundation – Organisation
  86. Netflix – Organisation
  87. Barack Obama – Person
  88. Michelle Obama – Person
  89. American – Nationality, Religious or Political Group

The output reflects the model’s strong ability to follow detailed instructions, including strict adherence to the specified taxonomy and the requirement to list entities in order of appearance, including repetitions. The consistent categorisation and contextual awareness evident in the results indicate that GPT-4.5 performs reliably in complex NER tasks.

The authors used GPT-4.5 [OpenAI (2025), GPT-4.5 (accessed on 22 March 2025), Large language model (LLMs), available at: https://openai.com] to generate the output.