我想做什么(在Clojure中):
例如,我有一个需要删除的单词向量:
(def forbidden-words [":)" "the" "." "," " " ...many more...])
Run Code Online (Sandbox Code Playgroud)
......和一个字符串向量:
(def strings ["the movie list" "this.is.a.string" "haha :)" ...many more...])
Run Code Online (Sandbox Code Playgroud)
因此,应从每个字符串中删除每个禁用的单词,在这种情况下,结果将是:["movie list""thisisastring""haha"].
这该怎么做 ?
正如标题所说,我有一个单词列表,喜欢stopWords = ["the", "and", "with", etc...]和我接收的文字如"杀死狐狸和狗".我希望输出像"杀死狐狸狗"非常有效和快速.我怎么能这样做(我知道我可以使用for循环迭代,但那不是很有效)
使用tm包我可以这样做:
c0 <- Corpus(VectorSource(text))
c0 <- tm_map(c0, removeWords, c(stopwords("english"),mystopwords))
Run Code Online (Sandbox Code Playgroud)
mystopwords 是我要删除的附加停用词的向量.
但我找不到使用RTextTools包的等效方法.例如:
dtm <- create_matrix(text,language="english",
removePunctuation=T,
stripWhitespace=T,
toLower=T,
removeStopwords=T, #no clear way to specify a custom list here!
stemWords=T)
Run Code Online (Sandbox Code Playgroud)
是否有可能做到这一点?我真的很喜欢这个RTextTools界面,很遗憾必须回到原点tm.
我想从我的数据中删除停用词,但我不想阻止这些词,因为确切的词对我很重要.我用过这个查询.
SELECT to_tsvector('english',colName)from tblName order by lower asc;
Run Code Online (Sandbox Code Playgroud)
有没有什么方法可以删除stopWords而不会阻止词语?
谢谢
我已经使用此链接中提供的OpenNLP解析器代码解析了文档,并且得到了以下输出:
(TOP (S (NP (NN Programcreek)) (VP (VBZ is) (NP (DT a) (ADJP (RB very) (JJ huge) (CC and) (JJ useful)) (NN website)))))
Run Code Online (Sandbox Code Playgroud)
我只想从中提取有意义的词,这意味着我想删除所有停用词,因为我想进一步根据这些有意义的词进行分类。您能否建议我如何从解析的输出中删除停用词?
最后我想得到以下输出
(TOP (S (NP (NN Programcreek)) (JJ useful)) (NN website)))))
Run Code Online (Sandbox Code Playgroud)
请帮助我,如果OpenNLP无法实现,那么建议我使用其他任何Java库进行自然语言处理。因为我的主要目的是解析文档并仅获取有意义的单词。
有一些标准的停用词列表,给出了要从语料库中删除的诸如“a the of not”之类的词。但是,我想知道,停止列表是否应该逐案更改?
比如我有10K的期刊文章,那么由于文章的结构,基本上每篇文章都会看到“介绍、评论、结论、页面”这样的词。我担心的是:我们应该从我们的语料库中删除这些词吗?(每个文档都有的词?)感谢每一个评论和建议。
我尝试了两种删除停用词的方法,这两种方法都遇到了问题:
方法一:
cachedStopWords = stopwords.words("english")
words_to_remove = """with some your just have from it's /via & that they your there this into providing would can't"""
remove = tu.removal_set(words_to_remove, query)
remove2 = tu.removal_set(cachedStopWords, query)
Run Code Online (Sandbox Code Playgroud)
在这种情况下,只有第一个 remove 函数起作用。remove2 不起作用。
方法二:
lines = tu.lines_cleanup([sentence for sentence in sentence_list], remove=remove)
words = '\n'.join(lines).split()
print words # list of words
Run Code Online (Sandbox Code Playgroud)
输出看起来像这样 ["Hello", "Good", "day"]
我尝试从单词中删除停用词。这是我的代码:
for word in words:
if word in cachedStopwords:
continue
else:
new_words='\n'.join(word)
print new_words
Run Code Online (Sandbox Code Playgroud)
输出如下所示:
H
e
l
l
o
Run Code Online (Sandbox Code Playgroud)
无法弄清楚上述两种方法有什么问题。请指教。
如果我将自定义停用词列表传递给TfidfVectorizer,那么停用词到底什么时候会被删除?根据文档:
\n\n\nstop_words :
\n\nstring{\xe2\x80\x98english\xe2\x80\x99},list, 或None(默认)...
\n\n如果是一个列表,则假定该列表包含停用词,所有这些停用词都将从结果标记中删除。仅适用于
\nanalyzer == \'word\'。
所以这个过程似乎是在标记化之后发生的,对吗?之所以产生疑问,是因为如果标记化还涉及词干提取,我认为存在错误地跳过(而不是删除)停用词的风险,因为在词干提取之后,它不再被识别。
\n可以通过使用nltk.tokenize删除一些不必要的停用词来对字符串进行标记。但是如何将包含停用词的短语标记为单个标记,同时删除其他停用词?
例如:
输入:特朗普是美国总统。
输出:['特朗普','美国总统']
如何获得仅删除“is”和第一个“the”但不删除“of”和第二个“the”的结果?
当我们查看 HuggingFaceHub 模型用法时,langchain有这部分作者不知道如何停止生成,https://github.com/hwchase17/langchain/blob/master/langchain/llms/huggingface_pipeline。 py#L182:
class HuggingFacePipeline(LLM):\n ...\n def _call(\n ...\n if stop is not None:\n # This is a bit hacky, but I can\'t figure out a better way to enforce\n # stop tokens when making calls to huggingface_hub.\n text = enforce_stop_tokens(text, stop)\n return text\nRun Code Online (Sandbox Code Playgroud)\n我应该使用什么来将停止标记添加到模板的末尾?
\n如果我们查看https://github.com/hwchase17/langchain/blob/master/langchain/llms/utils.py,它只是一个正则表达式分割,根据停用词列表分割输入字符串,然后取第一个分区re.split
re.split("|".join(stop), text)[0]\nRun Code Online (Sandbox Code Playgroud)\n让我们尝试从 Huggingface 模型中获取生成输出,例如
\nfrom transformers import pipeline\nfrom transformers import GPT2LMHeadModel, AutoTokenizer\n\ntokenizer = AutoTokenizer.from_pretrained(\'gpt2\')\nmodel = GPT2LMHeadModel.from_pretrained(\'gpt2\')\n\ngenerator = pipeline(\'text-generation\', …Run Code Online (Sandbox Code Playgroud) stop-words huggingface-transformers text-generation langchain large-language-model
stop-words ×10
python ×4
nlp ×3
nltk ×2
clojure ×1
filter ×1
java ×1
langchain ×1
lda ×1
loops ×1
opennlp ×1
postgresql ×1
r ×1
scikit-learn ×1
search ×1
string ×1
text-mining ×1
tm ×1
tokenize ×1