Advertisement
Python253

nlp_named_entity_spacy

Mar 8th, 2024 (edited)
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: nlp_named_entity_spacy.py
  4. # Author: Jeoi Reqi
  5.  
  6. """
  7. This script performs Named Entity Recognition (NER) using SpaCy.
  8.  
  9. Requirements:
  10. - Python 3
  11. - SpaCy library
  12. - 'en_core_web_md' SpaCy model
  13.  
  14. Usage:
  15. - Run the script, and it will identify named entities in the provided text.
  16.  
  17. Example:
  18. python named_entity_spacy.py
  19. Output: Named Entities: [('Natural Language Processing', 'ORG')]
  20. """
  21.  
  22. import spacy
  23.  
  24. # Load the 'en_core_web_md' SpaCy model
  25. nlp = spacy.load("en_core_web_md")
  26.  
  27. # Sample text
  28. text = "Natural Language Processing is a fascinating field. It involves the use of computers to understand and process human language."
  29.  
  30. # Process the text using SpaCy
  31. doc = nlp(text)
  32.  
  33. # Named Entity Recognition using SpaCy
  34. entities = [(ent.text, ent.label_) for ent in doc.ents]
  35. print("Named Entities:", entities)
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement