简体   繁体   English

random.shuffle(someLazyMap)

[英]random.shuffle(someLazyMap)

I'm currently trying to train my Python NLTK Part-Of-Speech Tagger to tag German text correctly. 我目前正在尝试训练我的Python NLTK词性标注器来正确标记德语文本。 In order to do so I'm using of the ClassifiedBasedGermanTagger, from: 为了做到这一点,我使用了ClassifiedBasedGermanTagger,来自:

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

and a training corpus from this website: 和来自该网站的培训语料库:

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

I found out that there is a pretty well written tutorial on how to go about this. 我发现有一个很好的书面教程如何解决这个问题。 So right now all I'm trying to do is to recreate the code: 所以我现在要做的就是重新创建代码:

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

The part that doesn't work for me is this: 对我不起作用的部分是这样的:

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

The error I get looks like this: 我得到的错误看起来像这样:

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

Do you have a workaround for this or even an explanation as to why it supposedly worked for the gentleman that wrote that tutorial and why it shows an error for me? 你有一个解决方法,甚至解释为什么它应该为编写该教程的绅士工作,为什么它为我显示错误? Currently I'm using Python 3. 目前我正在使用Python 3。

Thank you all very much in advance. 非常感谢大家。

A little late, but maybe it helps someone else. 有点晚了,但也许它可以帮助别人。

The author of the tutorial forgot the "list" as stated in the NLTK book: http://www.nltk.org/book/ch06.html#evaluation 该教程的作者忘记了NLTK书中所述的“列表”: http ://www.nltk.org/book/ch06.html#evaluation

so instead of 而不是

tagged_sents = corp.tagged_sents() tagged_sents = corp.tagged_sents()

it must be: 一定是:

tagged_sents = list(corp.tagged_sents()) tagged_sents = list(corp.tagged_sents())

tagged_sents = list(range(<some number>,<some number>))  # make sure some_nums is a list/mutable sequence
random.shuffle(tagged_sents)

You can find a solution here 你可以在这里找到解决方案

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM