spacy

NLP python库 nltk 安装

て烟熏妆下的殇ゞ 提交于 2020-04-10 15:11:19
使用python进行自然语言处理,有一些第三方库供大家使用: ·NLTK(Python自然语言工具包)用于诸如标记化、词形还原、词干化、解析、POS标注等任务。该库具有几乎所有NLP任务的工具。 ·Spacy是NLTK的主要竞争对手。这两个库可用于相同的任务。 ·Scikit-learn为机器学习提供了一个大型库。此外还提供了用于文本预处理的工具。 ·Gensim是一个主题和向量空间建模、文档集合相似性的工具包。 ·Pattern库的一般任务是充当Web挖掘模块。因此,它仅支持自然语言处理(NLP)作为辅助任务。 ·Polyglot是自然语言处理(NLP)的另一个Python工具包。它不是很受欢迎,但也可以用于各种NLP任务。 先由nltk入手学习。 1. NLTK安装 简单来说还是跟python其他第三方库的安装方式一样,直接在命令行运行:pip install nltk 2. 运行不起来? 当你安装完成后,想要试试下面的代码对一段英文文本进行简单的切分: import nltk text=nltk.word_tokenize("PierreVinken , 59 years old , will join as a nonexecutive director on Nov. 29 .") print(text) 运行结果, 报错如下: ... raise LookupError

How to specify word vector for OOV terms in Spacy?

╄→гoц情女王★ 提交于 2020-03-23 07:51:05
问题 I have a pre-trained word2vec model that I load to spacy to vectorize new words. Given new text I perform nlp('hi').vector to obtain the vector for the word 'hi'. Eventually, a new word needs to be vectorized which is not present in the vocabulary of my pre-trained model. In this scenario spacy defaults to a vector filled with zeros. I would like to be able to set this default vector for OOV terms. Example: import spacy path_model= '/home/bionlp/spacy.bio_word2vec.model' nlp=spacy.load(path

Training times for Spacy Entity Linking model

纵饮孤独 提交于 2020-03-18 05:58:29
问题 I'm trying to train a Spacy Entity Linking model using Wikidata and Wikipedia, using the scripts in https://github.com/explosion/spaCy/tree/master/bin/wiki_entity_linking. I've generated the KB and moved to training the model, but that is not done yet after more than a week. How long should that take normally? (I'm not using a GPU) Alternatively, is there a pretrained Wikidata entity linking model I can use? Thanks 回答1: As of October 2019, Spacy does not yet provide a pre-trained model. They

How to generate .conllu from a Doc object?

青春壹個敷衍的年華 提交于 2020-03-05 04:04:29
问题 Where can I find an example .conllu file Spacy will accept ? or example how to generate it ? with IOB ? Trying to convert .conllu file I generated to .json for model training, this way : head_ix = token.head.i - sent[0].i + 1 conll.append( (str(i), token.orth_, token.lemma_, token.tag_, token.ent_type_, str(head_ix), token.dep_) ) (Do you have correct example of doing this ) here is the error : $ python -m spacy convert spt3.conllu ....... File "/usr/local/lib/python2.7/dist-packages/spacy

How to generate .conllu from a Doc object?

别说谁变了你拦得住时间么 提交于 2020-03-05 04:04:02
问题 Where can I find an example .conllu file Spacy will accept ? or example how to generate it ? with IOB ? Trying to convert .conllu file I generated to .json for model training, this way : head_ix = token.head.i - sent[0].i + 1 conll.append( (str(i), token.orth_, token.lemma_, token.tag_, token.ent_type_, str(head_ix), token.dep_) ) (Do you have correct example of doing this ) here is the error : $ python -m spacy convert spt3.conllu ....... File "/usr/local/lib/python2.7/dist-packages/spacy

Managing Train/Develop Splits with the spaCy command line trainer

狂风中的少年 提交于 2020-03-03 07:34:29
问题 I am training an NER model using the python -m spacy train command line tool. I use gold.docs_to_json to convert my annotated documents to the JSON-serializable format. The command line training tool uses both a training set and a development set. I'm not sure how much assistance the command line tools give me for managing train/dev splits. Is there a command line tool to create train/dev splits from a single set of data? Will the spaCy training command do cross-validation for me instead of

'string' has incorrect type (expected str, got spacy.tokens.doc.Doc)

…衆ロ難τιáo~ 提交于 2020-03-02 05:47:57
问题 I have a dataframe: train_review = train['review'] train_review It looks like: 0 With all this stuff going down at the moment w... 1 \The Classic War of the Worlds\" by Timothy Hi... 2 The film starts with a manager (Nicholas Bell)... 3 It must be assumed that those who praised this... 4 Superbly trashy and wondrously unpretentious 8... I add the tokens into a string: train_review = train['review'] train_token = '' for i in train['review']: train_token +=i What I want is to tokenize the

'string' has incorrect type (expected str, got spacy.tokens.doc.Doc)

杀马特。学长 韩版系。学妹 提交于 2020-03-02 05:44:04
问题 I have a dataframe: train_review = train['review'] train_review It looks like: 0 With all this stuff going down at the moment w... 1 \The Classic War of the Worlds\" by Timothy Hi... 2 The film starts with a manager (Nicholas Bell)... 3 It must be assumed that those who praised this... 4 Superbly trashy and wondrously unpretentious 8... I add the tokens into a string: train_review = train['review'] train_token = '' for i in train['review']: train_token +=i What I want is to tokenize the

12种自然语言处理的开源工具

倾然丶 夕夏残阳落幕 提交于 2020-02-26 07:29:05
让我们看看可以用在你自己的 NLP 应用中的十几个工具吧。 在过去的几年里,自然语言处理(NLP)推动了聊天机器人、语音助手、文本预测等这些渗透到我们的日常生活中的语音或文本应用程技术的发展。目前有着各种各样开源的 NLP 工具,所以我决定调查一下当前开源的 NLP 工具来帮助你制定开发下一个基于语音或文本的应用程序的计划。 尽管我并不熟悉所有工具,但我将从我所熟悉的编程语言出发来介绍这些工具(对于我不熟悉的语言,我无法找到大量的工具)。也就是说,出于各种原因,我排除了三种我熟悉的语言之外的工具。 R 语言可能是没有被包含在内的最重要的语言,因为我发现的大多数库都有一年多没有更新了。这并不一定意味着它们没有得到很好的维护,但我认为它们应该得到更多的更新,以便和同一领域的其他工具竞争。我还选择了最有可能用在生产场景中的语言和工具(而不是在学术界和研究中使用),而我主要是使用 R 作为研究和发现工具。 我也惊讶地发现 Scala 的很多库都没有更新了。我上次使用 Scala 已经过去了两年了,当时它非常流行。但是大多数库从那个时候就再没有更新过,或者只有少数一些有更新。 最后,我排除了 C++。 这主要是因为我上次使用 C++ 编写程序已经有很多年了,而我所工作的组织还没有将 C++ 用于 NLP 或任何数据科学方面的工作。 Python 工具 自然语言工具包(NLTK) 毋庸置疑,

关于安装Spacy以及de和en模块遇到的坑---附最终解决方案

我的梦境 提交于 2020-02-25 21:46:22
这两天安装spacy踩了很多坑(有些坑可能是自己网络导致的,具体原因不详),看了很多资料,尝试了很多解决方法也没最终解决,下面先列出我遇到的问题,然后给出我尝试过的解决方案,其中有些可能可以很好的解决部分人的问题,要是实在不行看看最后我自己的解决方案以供大家参考。 遇到的问题以及网上看的一些解决方案 首次使用pip install spacy安装spacy是没有问题的,并且可以成功导入,但是在使用 import spcay en = spacy.load('en') de = spacy.load('de') 上面的代码会报错,报错结果如下 对于上述问题我看的解决方案一般如下,在cmd中执行下面的命令: python -m spacy download en python -m spacy download de 在cmd中使用上述命令之后我收到的结果如下: 上述问题产生的原因不详,有人说必须要用VPN下载,可以尝试。这个问题我还是没解决。我看到有的解决方案是用anaconda下载包,我也尝试了,还是没解决问题。 我最后的解决方案 在spacy的官网上去找相关文档和资料,官网连接为: https://spacy.io/ 。在官网的models模块里面下载英语(en)和德语(de)的数据集对应的压缩包。下载自己需要的内容,比如你在: https://spacy.io/models