NLTK train_unsupervised KeyError

    trainer = HiddenMarkovModelTrainer(tag_set, list(symbols))

    print('Training (unsupervised, %d sentences)...' % unsupervised)
    # it's rather slow - so only use 10 samples by default
    unlabeled = _untag(sentences[test + supervised :])
    print unlabeled[0]
    hmm = trainer.train_unsupervised(
        unlabeled, max_iterations=max_iterations
    )

symbols 要和 unlabeled 里面的字符编码一致,不然会报 KeyError

你可能感兴趣的:(Python,机器学习,NLTK)