Advertisement
Python253

nlp_speech_tags_spacy

Mar 8th, 2024 (edited)
586
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_speech_tags_spacy.py
  4. # Author: Jeoi Reqi
  5.  
  6. """
  7. This script performs part-of-speech tagging on a given text using SpaCy.
  8.  
  9. Requirements:
  10. - Python 3
  11. - SpaCy library with the English model
  12.  
  13. Usage:
  14. - Run the script, and it will print the part-of-speech tags of the provided text.
  15.  
  16. Example:
  17. python speech_tags_spacy.py
  18. Output: Part-of-Speech Tags: [insert tags here]
  19. """
  20.  
  21. import spacy
  22.  
  23. # Sample text
  24. text = "Natural Language Processing is a fascinating field. It involves the use of computers to understand and process human language."
  25.  
  26. # Load the SpaCy model
  27. nlp = spacy.load("en_core_web_sm")
  28.  
  29. # Process the text using SpaCy to get the 'doc' object
  30. doc = nlp(text)
  31.  
  32. # Access part-of-speech tags from the 'doc' object
  33. pos_tags = [(token.text, token.pos_) for token in doc]
  34. print("Part-of-Speech Tags:", pos_tags)
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement