【发布时间】:2021-02-18 17:22:51
【问题描述】:
我是 Python 的初学者,目前正在尝试使用 NLTK 来分析德语文本(提取德语名词及其在德语文本中的频率),请遵循以下教程:https://datascience.blog.wzb.eu/2016/07/13/accurate-part-of-speech-tagging-of-german-texts-with-nltk/
在这个过程中我遇到了几个问题,我无法解决。
当我按照网站执行以下代码时:
import random
tagged_sents = list(corp.tagged_sents())
random.shuffle(tagged_sents)
split_perc = 0.1
split_size = int(len(tagged_sents) * split_perc)
train_sents, test_sents = tagged_sents[split_size:], tagged_sents[:split_size]
结果就是这样
Traceback (most recent call last):
File "test2.py", line 7, in <module>
tagged_sents = list(corp.tagged_sents())
File "C:\Users\User\anaconda3\lib\site-packages\nltk\corpus\reader\conll.py", line 130, in tagged_sents
return LazyMap(get_tagged_words, self._grids(fileids))
File "C:\Users\User\anaconda3\lib\site-packages\nltk\corpus\reader\conll.py", line 215, in _grids
return concat(
File "C:\Users\User\anaconda3\lib\site-packages\nltk\corpus\reader\util.py", line 433, in concat
raise ValueError("concat() expects at least one object!")
ValueError: concat() expects at least one object!
然后我尝试按照这个解决方案来修复https://teamtreehouse.com/community/randomshuffle-crashes-when-passed-a-range-somenums-randomshufflerange5250
并改变
tagged_sents = list(corp.tagged_sents())
到
tagged_sents = list(range(5,250))
而且ValueError没有出来,我不知道(5,250)是什么意思,虽然我看过解释。
那我继续执行下面的步骤
from ClassifierBasedGermanTagger.ClassifierBasedGermanTagger import ClassifierBasedGermanTagger
tagger = ClassifierBasedGermanTagger(train=train_sents)
它显示
Traceback (most recent call last):
File "test1.py", line 90, in <module>
from ClassifierBasedGermanTagger.ClassifierBasedGermanTagger import ClassifierBasedGermanTagger
ModuleNotFoundError: No module named 'ClassifierBasedGermanTagger'
我已经下载了ClassifierBasedGermanTagger.py和init.py,放到VS CODE链接的文件夹下,不知道是否如文中所说:
'使用他的 Python 类 ClassifierBasedGermanTagger(您可以从 github 页面下载),我们可以创建一个标注器并使用来自 TIGER 语料库的数据对其进行训练:'
请帮我解决这些问题,谢谢!
【问题讨论】:
标签: python nltk tokenize corpus