Advertisement
Python253

nlp_part_of_speech_tags_nltk

Mar 8th, 2024 (edited)
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: nlp_part_of_speech_tags_nltk.py
  4. # Author: Jeoi Reqi
  5.  
  6. """
  7. This script performs part-of-speech tagging on a given text using NLTK.
  8.  
  9. Requirements:
  10. - Python 3
  11. - NLTK library
  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_nltk.py
  18. Output: Part-of-Speech Tags: [insert tags here]
  19. """
  20.  
  21. from nltk import pos_tag
  22. from nltk.tokenize import word_tokenize
  23.  
  24. # Sample text
  25. text = "Natural Language Processing is a fascinating field. It involves the use of computers to understand and process human language."
  26.  
  27. # Tokenize the text
  28. words = word_tokenize(text)
  29.  
  30. # Perform part-of-speech tagging
  31. pos_tags = pos_tag(words)
  32. print("Part-of-Speech Tags:", pos_tags)
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement