nltk

NLP的文本分析与特征工程

做~自己de王妃 提交于 2020-08-16 03:42:32
作者|Mauro Di Pietro 编译|VK 来源|Towards Data Science 摘要 在本文中,我将使用NLP和Python解释如何为机器学习模型分析文本数据和提取特征。 自然语言处理(NLP)是人工智能的一个研究领域,它研究计算机与人类语言之间的相互作用,特别是如何对计算机进行编程以处理和分析大量自然语言数据。 NLP常用于文本数据的分类。文本分类是根据文本数据的内容对其进行分类的问题。文本分类最重要的部分是特征工程:从原始文本数据为机器学习模型创建特征的过程。 在本文中,我将解释不同的方法来分析文本并提取可用于构建分类模型的特征。我将介绍一些有用的Python代码。 这些代码可以很容易地应用于其他类似的情况(只需复制、粘贴、运行),并且我加上了注释,以便你可以理解示例(链接到下面的完整代码)。 https://github.com/mdipietro09/DataScience_ArtificialIntelligence_Utils/blob/master/deep_learning_natural_language_processing/text_classification_example.ipynb 我将使用“新闻类别数据集”(以下链接),其中向你提供从赫芬顿邮报获得的2012年至2018年的新闻标题,并要求你使用正确的类别对其进行分类。 https:

垃圾邮件分类2

女生的网名这么多〃 提交于 2020-08-12 09:12:24
1.读取 # 1、读取数据集 def read_dataset(): file_path = r'SMSSpamCollection' sms = open(file_path, encoding='utf-8') sms_data = [] sms_label = [] csv_reader = csv.reader(sms, delimiter='\t') for line in csv_reader: sms_label.append(line[0]) # 提取出标签 sms_data.append(preprocessing(line[1])) # 提取出特征 sms.close() return sms_data, sms_label 2.数据预处理 # 2、数据预处理 def preprocess(text): tokens = [word for sent in nltk.sent_tokenize(text) for word in nltk.word_tokenize(sent)] # 分词 stops = stopwords.words('english') # 使用英文的停用词表 tokens = [token for token in tokens if token not in stops] # 去除停用词 tokens = [token.lower()

Extracting Related Date and Location from a sentence

a 夏天 提交于 2020-08-10 23:00:31
问题 I'm working with written text (paragraphs of articles and books) that includes both locations and dates. I want to extract from the texts pairs that contain locations and dates that are associated with one another. For example, given the following phrase: The man left Amsterdam on January and reached Nepal on October 21st I would have an output such as this: >>>[(Amsterdam, January), (Nepal, October 21st)] I tried splitting the text through "connecting words" (such as "and" for example) and