- Python Machine Learning By Example
- Yuxi (Hayden) Liu
- 216字
- 2021-07-02 12:41:40
Stemming and lemmatization
Word stemming is a process of reverting an inflected or derived word to its root form. For instance, machine is the stem of machines, and learning and learned are generated from learn as their stem.
The word lemmatization is a cautious version of stemming. It considers the PoS of a word when conducting stemming. We will discuss these two text preprocessing techniques, stemming and lemmatization, in further detail shortly. For now, let's take a quick look at how they're implemented respectively in NLTK by performing the following steps:
- Import porter as one of the three built-in stemming algorithms (LancasterStemmer and SnowballStemmer are the other two) and initialize the stemmer as follows:
>>> from nltk.stem.porter import PorterStemmer
>>> porter_stemmer = PorterStemmer()
- Stem machines and learning, as shown in the following codes:
>>> porter_stemmer.stem('machines')
'machin'
>>> porter_stemmer.stem('learning')
'learn'
Stemming sometimes involves chopping of letters if necessary, as we can see in machin in the preceding command output.
- Now import a lemmatization algorithm based on the built-in WordNet corpus and initialize a lemmatizer:
>>> from nltk.stem import WordNetLemmatizer
>>> lemmatizer = WordNetLemmatizer()
Similar to stemming, we lemmatize machines, learning:
>>> lemmatizer.lemmatize('machines')
'machine'
>>> lemmatizer.lemmatize('learning')
'learning'
Why is learning unchanged? It turns out that this algorithm only lemmatizes on nouns by default.
推薦閱讀
- 人工智能超越人類
- 精通MATLAB神經(jīng)網(wǎng)絡(luò)
- Hands-On Data Science with SQL Server 2017
- Photoshop CS3特效處理融會貫通
- Ceph:Designing and Implementing Scalable Storage Systems
- 悟透AutoCAD 2009案例自學手冊
- 嵌入式操作系統(tǒng)原理及應(yīng)用
- Introduction to R for Business Intelligence
- Learning Linux Shell Scripting
- 工業(yè)機器人實操進階手冊
- HBase Essentials
- 大數(shù)據(jù)素質(zhì)讀本
- 納米集成電路制造工藝(第2版)
- 智能控制技術(shù)及其應(yīng)用
- 機器人手工制作