【问题标题】:random.shuffle(someLazyMap)random.shuffle(someLazyMap)
【发布时间】:2018-03-14 23:45:25
【问题描述】:

我目前正在尝试训练我的 Python NLTK 词性标注器来正确标注德语文本。为此,我使用了 ClassifiedBasedGermanTagger,来自:

https://github.com/ptnplanet/NLTK-Contributions/tree/master/ClassifierBasedGermanTagger

以及来自本网站的训练语料库:

http://www.ims.uni-stuttgart.de/forschung/ressourcen/korpora/TIGERCorpus/download/start.html (TIGER Corpus 版本 2.2(2012 年 7 月))

我发现有一个写得很好的教程关于如何去做。所以现在我要做的就是重新创建代码:

https://datascience.blog.wzb.eu/2016/07/13/accurate-part-of-speech-tagging-of-german-texts-with-nltk/

对我不起作用的部分是:

tagged_sents = corp.tagged_sents() 
random.shuffle(tagged_sents)

我得到的错误如下所示:

File "C:\somedude\lib\random.py", line 274, in shuffle
    x[i], x[j] = x[j], x[i]
TypeError: 'LazyMap' object does not support item assignment

您是否有解决方法,甚至解释为什么它对编写该教程的绅士有效,以及为什么它对我显示错误?目前我正在使用 Python 3。

提前非常感谢大家。

【问题讨论】:

    标签: python nltk pos-tagger


    【解决方案1】:

    有点晚了,但也许它可以帮助别人。

    教程的作者忘记了NLTK书中所说的“列表”: http://www.nltk.org/book/ch06.html#evaluation

    所以而不是

    tagged_sents = corp.tagged_sents()

    一定是:

    tagged_sents = list(corp.tagged_sents())

    【讨论】:

      【解决方案2】:
      tagged_sents = list(range(<some number>,<some number>))  # make sure some_nums is a list/mutable sequence
      random.shuffle(tagged_sents)
      

      您可以在这里找到解决方案

      https://teamtreehouse.com/community/randomshuffle-crashes-when-passed-a-range-somenums-randomshufflerange5250

      【讨论】:

        猜你喜欢
        • 2018-05-11
        • 2014-12-22
        • 1970-01-01
        • 1970-01-01
        • 2018-01-10
        • 2023-04-04
        • 1970-01-01
        • 1970-01-01
        • 2013-07-13
        相关资源
        最近更新 更多