我在一些相当大的数据集上使用NLTK执行自然语言处理,并希望利用我的所有处理器核。似乎多处理模块就是我所追求的,当我运行下面的测试代码时,我看到所有的内核都被使用了,但是代码始终没有完成。
在没有多个处理的情况下执行相同的任务,大约在一分钟内完成。
debian的Python2.7.11。
from nltk.tokenize import word_tokenize
import io
import time
import multiprocessing as mp
def open_file(filepath):
#open and parse file
file = i
from nltk.tokenize import sent_tokenize ,word_tokenize
sentence = 'jainmiah I love you but you are not bothering about my request,
please yaar consider me for the sake'
word_tok = word_tokenize(sentence)
print(word_tok)
set_all = set(word_tokenize(sentence))
print(set_all)
实际
我正在使用一些文本进行一些NLP分析。我已经清除了文本,采取步骤删除非字母数字字符、空格、重复单词和停止词,并执行词干和柠檬化:
from nltk.tokenize import word_tokenize
import nltk.corpus
import re
from nltk.stem.snowball import SnowballStemmer
from nltk.stem.wordnet import WordNetLemmatizer
import pandas as pd
data_df = pd.read_csv('path/to/file/data.csv
尝试使用word_tokenize和sent_tokenize标记带有新行的段落,但它无法识别新行。
尝试通过将其拆分到新行中来将其分成段落,但仍然不起作用。
from nltk import sent_tokenize, word_tokenize, pos_tag
para="the new line \n new char"
sent=sent_tokenize(para)
print(sent)
输出:
['the new line \n new char']
如果在python中以字符串格式指定数据,但在从docx文件中提取数据时失败,则它可以工作
对
我试图标记一个句子,我相信代码是正确的,但是没有输出。有什么问题吗?这是密码。
import nltk
from nltk.tokenize import word_tokenize
text = word_tokenize("And now for something completely different")
nltk.pos_tag(text)
text = word_tokenize("They refuse to permit us to obtain the refuse permit")
nltk.pos_tag(text)
我是如何阻止word_tokenize从"pass_word"、"https://www.gmail.com"和"tempemail@mail.com"这样的字符串中分离的?引文应该能阻止这一切,但事实并非如此。
我尝试过不同的regex选项。
from nltk import word_tokenize
s = 'open "https://www.gmail.com" url. Enter "tempemail@mail.com" in email. Enter "pass_word"
移除标点符号有很多可用的地方,但我似乎找不到任何东西保留它。
如果我这样做了:
from nltk import word_tokenize
test_str = "Some Co Inc. Other Co L.P."
word_tokenize(test_str)
Out[1]: ['Some', 'Co', 'Inc.', 'Other', 'Co', 'L.P', '.']
最后一个“。被推入自己的标记中。然而,如果最后还有一个词,那就是“最后一个”。保存如下
如何使用基本语言生成大图?
我可以用Python这样做..。
import nltk, sys
from nltk.tokenize import word_tokenize
sys.stdout = open("mygram1.txt", "w")
with open("mytext.txt") as f:
for text in f:
tokens = nltk.word_tokenize(text)
bigrm = (nltk.bigrams(tokens))
print(*map(' '.join,
我是NLTK的新手。我得到了这个错误,我已经搜索了编码/解码,特别是UnicodeDecodeError,但这个错误似乎是NLTK源代码特有的。
下面是错误:
Traceback (most recent call last):
File "A:\Python\Projects\Test\main.py", line 2, in <module>
print(pos_tag(word_tokenize("John's big idea isn't all that bad.")))
File "A:\Pytho
我正在做一个udemy课程(所有的例子都是英文的),但问题是当我开始使用西班牙语时,总是缺乏库或兼容性。我从https://www.datos.gov.co/Ciencia-Tecnolog-a-e-Innovaci-n/LAS-WordNet-una-WordNet-para-el-espa-ol-obtenida-c/8z8d-85m7下载了CSV格式的数据,但我正在尝试执行以下代码,但由于上下文的描述而崩溃,由于上下文的描述,有人知道如何处理它吗?谢谢 import nltk
#nltk.download("omw")
from nltk.corpus import w
现在我正在使用nltk中的类似()方法。但是is并没有像预期的那样工作。请看下面这段代码:
from nltk import word_tokenize;
import nltk;
text = """
The girl is very pretty.
""";
text = nltk.Text(word_tokenize(text));
text.similar('beautiful'); #it returns "no matches" but pretty is synonym of beautiful.
我开始学习NLTK了。有没有一种方法可以保存到镜像的dispersion_plot? 这是我的代码: import nltk
from nltk import word_tokenize
raw="""This is the text where includes the word lawyers"""
text1 = nltk.Text(word_tokenize(raw))
print(text1.dispersion_plot(["lawyers"])) 因此,它打印绘图,但我想将其保存到图像文件中。 谢谢!
我是python和NLTK的新手,我想在这里做word标记化和词性标记。我在我的Ubuntu14.04中安装了Nltk3.0,默认的Python2.7.6。首先,我尝试对一个简单的sentence.But进行标记化,我得到了一个错误,告诉我"BadZipfile:..I不是压缩文件“.How解决这个问题?
..One更多疑问..即当我安装Nltk data (使用命令行)时,我给出的路径为"/usr/share/nltk_data“。由于某些errors.But,包的.Some无法安装。当我使用命令"nltk.data.path”检查时,它显示其他路径,其他路径实际上是
我是python编程的新手。现在,我正在对文本文件进行自然语言处理。问题是我有大约200个文本文件,所以很难单独加载每个文件并应用相同的方法。
下面是我的程序:
import nltk
from nltk.collocations import *
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
from nltk import FreqDist
with open("c:/users/user/desktop/datascience/sotu/stopwords.txt", &
我正在nltk库中学习BigramTagger类。我用nltk附带的棕色语料库来训练一个“部分句子”标签。
我注意到,如果我对这个语料库进行训练,然后在语料库的第一句中标注几个单词,它就会非常有效。
from nltk.corpus import brown
from nltk.tag import BigramTagger
from nltk import word_tokenize
# Works completely fine:
brown_train = brown.tagged_sents(categories='news')
bigram_tagger = Bi
我知道如何使用NLTK获得二元语法和三元语法搭配,并将它们应用于我自己的语料库。代码如下。
然而,我不确定(1)如何获得特定单词的搭配?(2) NLTK是否有基于对数似然比的搭配度量?
import nltk
from nltk.collocations import *
from nltk.tokenize import word_tokenize
text = "this is a foo bar bar black sheep foo bar bar black sheep foo bar bar black sheep shep bar bar black sentenc
在下面的代码中,我知道我的naivebayes分类器工作正常,因为它在trainset1上工作正常,但是为什么它不能在trainset2上工作?我甚至在两个分类器上尝试了它,一个来自TextBlob,另一个直接来自nltk。
from textblob.classifiers import NaiveBayesClassifier
from textblob import TextBlob
from nltk.tokenize import word_tokenize
import nltk
trainset1 = [('I love this sandwich.',
我正在使用PyCharm编写一个使用nltk包的程序。我的第一行是:
from nltk import word_tokenize, sent_tokenize
我在PyCharm的2.7Python环境(我正在处理的环境)中导入了nltk包,如下所示:
但是,PyCharm不能识别from nltk..行。它是灰色的;它还显示了这个错误:
This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible i
当调用word_tokenize时,我得到以下错误:
File "C:\Python34\lib\site-packages\nltk\tokenize\punkt.py", line 1322,
in _slices_from_text for match in
self._lang_vars.period_context_re().finditer(text):
TypeError: expected string or buffer
我有一个大的文本文件(1500.txt),我想从其中删除停止词。我的代码如下:
from nltk.corpus impor
我是新来的。
这使我可以根据句子的词类对其进行标记。但是,在对其他语言执行此操作时,涉及哪些步骤?
import nltk
sentence = "I'm not sure!"
tokens = nltk.word_tokenize(sentence)
tagged = nltk.pos_tag(tokens)
更新
我有兴趣从西班牙语开始。
更新2
import nltk
from nltk.tokenize import word_tokenize
training_set = [[(w.lower(),t) for w,t in s] for s in nltk
我是nltk和python的新手。我试图使用evaluate特性来测试我阅读的文本文档的准确性。这就是我到目前为止所拥有的。
from nltk.tag import UnigramTagger
from nltk.corpus import treebank
from nltk.tokenize import word_tokenize
train_sents = treebank.tagged_sents()
tagger = UnigramTagger(train_sents)
text1 = "This is the fir
import nltk
import random
from nltk.corpus import movie_reviews
from nltk.classify.scikitlearn import SklearnClassifier
import pickle
import sys
sys.getdefaultencoding()
import os
from sklearn.naive_bayes import MultinomialNB, BernoulliNB
from sklearn.linear_model import SGDClassifier
from nltk.cl
我将柠檬化添加到我的countvectorizer中,就像在这个上解释的那样。
from nltk import word_tokenize
from nltk.stem import WordNetLemmatizer
class LemmaTokenizer(object):
def __init__(self):
self.wnl = WordNetLemmatizer()
def __call__(self, articles):
return [self.wnl.lemmatize(t) for t in word
我想把西班牙语句子翻译成单词。以下是正确的方法,还是有更好的方法?
import nltk
from nltk.tokenize import word_tokenize
def spanish_word_tokenize(s):
for w in word_tokenize(s):
if w[0] in ("¿","¡"):
yield w[0]
yield w[1:]
else:
yield w
sentenc
我从NLTK开始,想标记一个荷兰句子,但我在指定语料库时遇到了困难。
from nltk.tag import pos_tag
from nltk.tokenize import word_tokenize
from nltk.corpus import alpino
pos_tag(word_tokenize("Python is een goede data science taal."), tagset = 'alpino')
给予,
[('Python', 'UNK'),
('is', 'UNK
我有一个字典df2,其中每个值都是一个单词列表。然后,我想将所有这些列表合并到df3中。为此,我使用一个循环,它需要超过1分钟才能完成。
import nltk
from nltk.corpus import twitter_samples
from nltk.tokenize import word_tokenize
df = twitter_samples.strings('tweets.20150430-223406.json')
df2 = {}
for i in range(len(df)):
df2[i] = word_tokenize(df[i])
d
我有跟踪错误。
if form in exceptions: TypeError: unhashable type: 'list'
以下是我的密码。
from nltk.tokenize import word_tokenize
from nltk.stem.wordnet import WordNetLemmatizer
sentence = 'missed you'
w_tokenize = (word_tokenize(sentence))
for word in w_tokenize:
print WordNetLemmatizer().lem
我在Python3.4中使用NLTK 3.0,由于以下错误无法执行POS标记:我已经阅读了所有的,但找不到解决问题的方法。大多数帖子提到升级到NLTK 3.0可以解决这个问题,但是我已经有了NLTK 3.0。根据这些帖子,改变nltk的data.py解决了这个问题,但是NLTK的人不愿意这么做。这是我的代码:
from nltk.tag import pos_tag
from nltk.tokenize import word_tokenize
pos_tag(word_tokenize("John's big idea isn't all that bad."
我试着在python中使用NLTK中的类似函数,但它总是返回'No Matches',即使我在句子中输入了类似的单词。
我的代码在这里
from nltk.tokenize import word_tokenize
import nltk
raw = "Analyzing text to find common terms using Python and NLTK"
text = nltk.Text(raw)
text.similar('mutual')
有什么想法吗?