python nltk 库
我们将如何做呢? (How are we going to be doing this ?)
Python, being Python, apart from its incredible readability, has some remarkable libraries at hand. One of which, is NLTK. NLTK or Natural Language Tool Kit is one of the best Python NLP libraries out there. The functionality it leaves at your fingertips while maintaining its ease of use and again, readability is just fantastic.
Python是Python,除了具有令人难以置信的可读性外,还有一些出色的库。 其中之一是NLTK。 NLTK或自然语言工具包是目前最好的Python NLP库之一。 在保持其易用性的同时,它的功能触手可及,而且可读性同样出色。
In fact, we’re going to be completing this mini project under 25 lines of code. And you’re most probably going to understand each line as you read through it. Crazy, I know.
实际上,我们将用25行代码完成这个小型项目。 阅读完每一行后,您很可能会理解每一行。 疯狂,我知道。
让我们开始吧! (Let’s get right into it !)
IDE
集成开发环境
Personally whenever I’m doing anything even relatively fancy, in Python, I use Jupyter Lab. Being able to see what each line does makes it really easy to debug and it’s also strangely therapeutic. Shrugs.
就个人而言,无论何时我想做的事甚至都比较花哨,在Python中,我都使用Jupyter Lab 。 能够看到每条线的功能使得调试起来非常容易,而且也很奇怪。 耸耸肩。
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/057e3d0298af7765bfc8ba7a175c5e21.png)
But you’re free to use whatever you want. It’s a free world. Mostly.
但是您可以随意使用任何内容。 这是一个自由的世界。 大多。
2. Dependencies
2. 依存关系
Now, we’ve got to get hold of the libraries we need. Just 4, super easy to get libraries.
现在,我们必须掌握所需的库。 仅需4个,超级容易获得库。
- NLTK NLTK
- Numpy 脾气暴躁的
- Pandas 大熊猫
- Scikit-learn Scikit学习
To install NLTK, run the following in the terminal
要安装NLTK ,请在终端中运行以下命令
pip install nltk
To install Numpy, run the following in the terminal
要安装Numpy ,请在终端中运行以下命令
pip install numpy
To install Pandas, run the following in the terminal
要安装Pandas ,请在终端中运行以下命令
pip install pandas
To install Scikit-learn, run the following in the terminal
要安装Scikit-learn ,请在终端中运行以下命令
pip install scikit-learn
So intuitive. I mean, come on, it really can’t get any easier.
如此直观。 我的意思是,拜托,这真的很难。
编码时间 (Time to code)
![Image for post](https://i-blog.csdnimg.cn/blog_migrate/781baba2df968c660766075430ba834b.png)
First things first. Let’s import NLTK.
首先是第一件事。 让我们导入NLTK。
import NLTK
Now, there’s a slight hitch. I did say 4 dependencies, didn’t I ? Ok, here’s the last one, I swea