Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7984159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:10:47+00:00 2026-06-04T11:10:47+00:00

I have multiple texts and I would like to create profiles of them based

  • 0

I have multiple texts and I would like to create profiles of them based on their usage of various parts of speech, like nouns and verbs. Basially, I need to count how many times each part of speech is used.

I have tagged the text but am not sure how to go further:

tokens = nltk.word_tokenize(text.lower())
text = nltk.Text(tokens)
tags = nltk.pos_tag(text)

How can I save the counts for each part of speech into a variable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:10:49+00:00Added an answer on June 4, 2026 at 11:10 am

    The pos_tag method gives you back a list of (token, tag) pairs:

    tagged = [('the', 'DT'), ('dog', 'NN'), ('sees', 'VB'), ('the', 'DT'), ('cat', 'NN')] 
    

    If you are using Python 2.7 or later, then you can do it simply with:

    >>> from collections import Counter
    >>> counts = Counter(tag for word,tag in tagged)
    >>> counts
    Counter({'DT': 2, 'NN': 2, 'VB': 1})
    

    To normalize the counts (giving you the proportion of each) do:

    >>> total = sum(counts.values())
    >>> dict((word, float(count)/total) for word,count in counts.items())
    {'DT': 0.4, 'VB': 0.2, 'NN': 0.4}
    

    Note that in older versions of Python, you’ll have to implement Counter yourself:

    >>> from collections import defaultdict
    >>> counts = defaultdict(int)
    >>> for word, tag in tagged:
    ...  counts[tag] += 1
    
    >>> counts
    defaultdict(<type 'int'>, {'DT': 2, 'VB': 1, 'NN': 2})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge text file that I would like to split into multiple
I would like to create a UIView has multiple UITextFields validates each one as
I have an application that has multiple panels; I would like to have the
I would like to create the ability for a user to have opened more
I have a java SAX parser which I would like to call multiple times
Say that I have a UIView which I would like to re-use in multiple
I have multiple text files with logged data like this: 6/23/09 17:00 0.443 6/23/09
I have form with multiple input type=radio with text next to them. I want
I have text documents like the following which contain single and multiple variables: title::
I would like to have a special sub-node that could be attached to other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.