Python 中的 NLP 特征工程
Rounak Banik
Data Scientist
"The bear is a majestic animal""Please bear with me""Jane is an amazing guitarist."
Jane → 专有名词is → 动词an → 限定词amazing → 形容词guitarist → 名词import spacy
# Load the en_core_web_sm model
nlp = spacy.load('en_core_web_sm')
# Initiliaze string
string = "Jane is an amazing guitarist"
# Create a Doc object
doc = nlp(string)
...
...
# Generate list of tokens and pos tags
pos = [(token.text, token.pos_) for token in doc]
print(pos)
[('Jane', 'PROPN'),
('is', 'VERB'),
('an', 'DET'),
('amazing', 'ADJ'),
('guitarist', 'NOUN')]
PROPN → 专有名词DET → 限定词
Python 中的 NLP 特征工程