Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 985 of the free egghead.io lessons, plus get JavaScript content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Tag parts of speech using Natural

2:16 JavaScript lesson by

An important component of many natural language processing projects is being able to identify the grammar of a piece of text. We’ll learn how to do that with Natural’s parts of speech (POS) tagger.

There are many tags, and it's worth looking them up online (search "POS tag symbols") to become familiar with them all.

The setup of the tagger may seem a little strange, but it allows you to replace the lexicon or the rules with a different lexicon or rule set of your choice.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

An important component of many natural language processing projects is being able to identify the grammar of a piece of text. We’ll learn how to do that with Natural’s parts of speech (POS) tagger.

There are many tags, and it's worth looking them up online (search "POS tag symbols") to become familiar with them all.

The setup of the tagger may seem a little strange, but it allows you to replace the lexicon or the rules with a different lexicon or rule set of your choice.

Avatar
David

When I used a test string of:

const testString = `Lys soldered the beautiful jewelry pieces.`.split(' '); //note the punctuation at the end

I got different results, and I'm not 100% sure why... or what the final tagging on 'pieces' means.

/*
* [ [ 'Lys', 'NNP' ], *NN = noun, P = Proper Noun
  [ 'soldered', 'VBN' ], Verb
  [ 'the', 'DT' ], Determiner
  [ 'beautiful', 'JJ' ], Adjective
  [ 'jewelry', 'NN' ], Noun
  [ 'pieces.', 'N' ] ] ??
* */
In reply to egghead.io
Avatar
Hannah

So as you've figured out, the POS tagger doesn't split up punctuation, so you'll generally want to separate or remove punctuation before you use the tagger - otherwise it's trying to tag "pieces." as a word, and is unable to. "N" is the default tag that gets spit out if the tagger can't find an accurate tag. You can set your own default tag, but "N" is common in order to group in the unknowns with an existing group (nouns, which generally start with N).

In reply to David
Avatar
Hannah

Let me know if that answers your question!

In reply to Hannah
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?