gensim

Is there any way to match Gensim LDA output with topics in pyLDAvis graph?

Deadly 提交于 2020-08-27 06:31:55
问题 I need to process the topics in the LDA output (lda.show_topics(num_topics=-1, num_words=100...) and then compare what I do with the pyLDAvis graph but the topic numbers are differently numbered. Is there a way I can match them? 回答1: If it's still relevant, have a look at the documentation http://pyldavis.readthedocs.io/en/latest/modules/API.html You may want to set sort_topics to False . This way the order of topics in gensim and pyLDAvis will be the same. At the same time, gensim's indexing

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:

Word2Vec简明教程:入门、原理及代码实现

核能气质少年 提交于 2020-08-15 17:20:07
Word2Vec简明教程 1. 特征向量 2. 词向量 2.1 例1:King- Man + Woman = Queen 2.2 例2:跨语言同义词共现 3. NNLM 4. Word2Vec 4.1 SkipGram (1)基本概念 (2)数据模型 4.2 CBoW 4.3 Negative Sampling 4.4 Hierarchical Softmax 5. 使用gensim 1. 特征向量 近年来,研究者通过词汇学方法,发现约有五种特质可以涵盖人格描述的所有方面,提出了人格的 大五模式(Big Five) ,俗称人格的海洋(OCEAN),包括以下五个维度: 开放性(Openness):具有想象、审美、情感丰富、求异、创造、智能等特质。 责任心(Conscientiousness):显示胜任、公正、条理、尽职、成就、自律、谨慎、克制等特点。 外倾性(Extroversion):表现出热情、社交、果断、活跃、冒险、乐观等特质。 宜人性(Agreeableness):具有信任、利他、直率、依从、谦虚、移情等特质。 神经质性(Neuroticism):难以平衡焦虑、敌对、压抑、自我意识、冲动、脆弱等情绪的特质,即不具有保持情绪稳定的能力。 通过NEO-PI-R测试可以得出每个维度的打分(1-100),然后将其缩放到 [ − 1 , 1 ] [-1,1] [ − 1 , 1 ]

写给程序员的机器学习入门 (六)

半腔热情 提交于 2020-08-13 13:37:28
这一篇将会举两个例子说明怎么应用递归模型,包括文本情感分类和预测股价走势。与前几篇不同,这一篇使用的数据是现实存在的数据,我们将可以看到更高级的模型和手法🤠。 例子① - 文本感情分类 文本感情分类是一个典型的例子,简单的来说就是给出一段话,判断这段话是正面还是负面的,例如淘宝或者京东上对商品的评价,豆瓣上对电影的评价,更高级的情感分类还能对文本中的感情进行细分。因为涉及到自然语言,文本感情分类也属于自然语言处理 (NLP, Nature Langure Processing),我们接下来将会使用 ami66 在 github 上 公开的数据 ,来实现根据商品评论内容识别是正面评论还是负面评论。 在处理文本之前我们需要对文本进行切分,切分方法可以分为按字切分和按单词切分,按单词切分的精度更高但要求使用分词类库。处理中文时我们可以使用开源的 jieba 类库来按单词切分,执行 pip3 install jieba --user 即可安装,使用例子如下: # 按字切分 >>> words = [c for c in "我来到北京清华大学"] >>> words ['我', '来', '到', '北', '京', '清', '华', '大', '学'] # 按单词切分 >>> import jieba >>> words = list(jieba.cut("我来到北京清华大学")) >>

KeyError: “word 'word' not in vocabulary” in word2vec

半世苍凉 提交于 2020-08-08 06:37:08
问题 I am using word2vec , wiki corpus I trained, what can I do if the word I input not in vocabulary in word2vec ? Test it a bit: model = word2vec.Word2Vec.load('model/' + 'wiki_chinese_word2vec.model') model['boom'] Error: KeyError("word '%s' not in vocabulary" % word) 回答1: Use try & except to handle exceptions in Python. try block executes normally. If any exception or error occurs then except block will be executed. try: c = model['boom'] except KeyError: print "not in vocabulary" c = 0 回答2:

写给程序员的机器学习入门 (六)

醉酒当歌 提交于 2020-08-06 04:45:45
这一篇将会举两个例子说明怎么应用递归模型,包括文本情感分类和预测股价走势。与前几篇不同,这一篇使用的数据是现实存在的数据,我们将可以看到更高级的模型和手法🤠。 例子① - 文本感情分类 文本感情分类是一个典型的例子,简单的来说就是给出一段话,判断这段话是正面还是负面的,例如淘宝或者京东上对商品的评价,豆瓣上对电影的评价,更高级的情感分类还能对文本中的感情进行细分。因为涉及到自然语言,文本感情分类也属于自然语言处理 (NLP, Nature Langure Processing),我们接下来将会使用 ami66 在 github 上 公开的数据 ,来实现根据商品评论内容识别是正面评论还是负面评论。 在处理文本之前我们需要对文本进行切分,切分方法可以分为按字切分和按单词切分,按单词切分的精度更高但要求使用分词类库。处理中文时我们可以使用开源的 jieba 类库来按单词切分,执行 pip3 install jieba --user 即可安装,使用例子如下: # 按字切分 >>> words = [c for c in "我来到北京清华大学"] >>> words ['我', '来', '到', '北', '京', '清', '华', '大', '学'] # 按单词切分 >>> import jieba >>> words = list(jieba.cut("我来到北京清华大学")) >>

文本分类实战(一)—— word2vec预训练词向量

非 Y 不嫁゛ 提交于 2020-08-04 17:41:32
1 大纲概述   文本分类这个系列将会有十篇左右,包括基于word2vec预训练的文本分类,与及基于最新的预训练模型(ELMo,BERT等)的文本分类。总共有以下系列:    word2vec预训练词向量    textCNN 模型    charCNN 模型    Bi-LSTM 模型    Bi-LSTM + Attention 模型    RCNN 模型    Adversarial LSTM 模型    Transformer 模型    ELMo 预训练模型    BERT 预训练模型    所有代码均在 textClassifier 仓库中。 2 数据集   数据集为IMDB 电影影评,总共有三个数据文件,在/data/rawData目录下,包括unlabeledTrainData.tsv,labeledTrainData.tsv,testData.tsv。在进行文本分类时需要有标签的数据(labeledTrainData),但是在训练word2vec词向量模型(无监督学习)时可以将无标签的数据一起用上。 3 数据预处理   IMDB 电影影评属于英文文本,本序列主要是文本分类的模型介绍,因此数据预处理比较简单,只去除了各种标点符号,HTML标签,小写化等。代码如下: import pandas as pd from bs4 import BeautifulSoup

Python: gensim: RuntimeError: you must first build vocabulary before training the model

夙愿已清 提交于 2020-08-01 05:43:05
问题 I know that this question has been asked already, but I was still not able to find a solution for it. I would like to use gensim's word2vec on a custom data set, but now I'm still figuring out in what format the dataset has to be. I had a look at this post where the input is basically a list of lists (one big list containing other lists that are tokenized sentences from the NLTK Brown corpus). So I thought that this is the input format I have to use for the command word2vec.Word2Vec() .

Python: gensim: RuntimeError: you must first build vocabulary before training the model

陌路散爱 提交于 2020-08-01 05:43:05
问题 I know that this question has been asked already, but I was still not able to find a solution for it. I would like to use gensim's word2vec on a custom data set, but now I'm still figuring out in what format the dataset has to be. I had a look at this post where the input is basically a list of lists (one big list containing other lists that are tokenized sentences from the NLTK Brown corpus). So I thought that this is the input format I have to use for the command word2vec.Word2Vec() .

My Doc2Vec code, after many loops of training, isn't giving good results. What might be wrong?

纵饮孤独 提交于 2020-07-23 06:53:25
问题 I'm training a Doc2Vec model using the below code, where tagged_data is a list of TaggedDocument instances I set up before: max_epochs = 40 model = Doc2Vec(alpha=0.025, min_alpha=0.001) model.build_vocab(tagged_data) for epoch in range(max_epochs): print('iteration {0}'.format(epoch)) model.train(tagged_data, total_examples=model.corpus_count, epochs=model.iter) # decrease the learning rate model.alpha -= 0.001 # fix the learning rate, no decay model.min_alpha = model.alpha model.save("d2v