concept spaCy in category nlp

appears as: spaCy
Getting Started with Natural Language Processing

This is an excerpt from Manning's book Getting Started with Natural Language Processing.

[43] In the scheme used by spaCy, prepositions are referred to as “adposition” and use a tag ADP. Words like “Friday” or “Obama” are tagged with PROPN, which stands for “proper nouns” reserved for names of known individuals, places, time references, organizations, events and such. For more information on the tags, see documentation here: https://spacy.io/api/annotation.

Listing 6.8 Code to apply spaCy preprocessing
def preprocess(source):    #A
    source_docs = {}
    index = 0
    for (sent, label) in source:
        text = " ".join(sent)    #B
        source_docs[text] = nlp(text)    #C
        if index>0 and (index%2000)==0:
            print(str(index) + " texts processed")
        index += 1
    print("Dataset processed")    #D
    return source_docs
 
train_docs = preprocess(strat_train_set)
pretest_docs = preprocess(strat_pretest_set)
test_docs = preprocess(test_set)    #E
Figure 7.12 Run spaCy’s pipeline and store the results in source_docs Python dictionaries

Now let’s see how you can incorporate the SentiWordNet information with your sentiment analyzer. As in the Code Listing 8.3, let’s make sure that you are accessing the right type of synsets – that is, let’s extract the synsets for the specific part of speech. Remember that you have previously (i.e., while building your baseline classifier in Chapter 7) processed the reviews with spaCy and saved the results to the linguistic containers in pos_docs and neg_docs. These containers, among other information, contain part-of-speech tags for all words in the reviews. That is, you don’t need to run any further analysis to detect parts of speech, but the particular tags used to denote each part of speech differ between spaCy and NLTK’s interface to SentiWordNet. Here is the summary of the differences:

  • nouns have tags starting with “NN” in spaCy’s notation[89] and are denoted as wn.NOUN in NLTK’s interfaces to WordNet and SentiWordNet;
  • verbs have tags starting with “VB” or “MD” is spaCy and are denoted as wn.VERB in NLTK;
  • adjectives have tags starting with “JJ” in spaCy and are denoted as wn.ADJ in NLTK; and finally
  • adverbs have tags starting with “RB” in spaCy and are denoted as wn.ADV in NLTK.