【发布时间】:2014-01-07 05:10:12
【问题描述】:
据我所知,使用 NLTK 分类器的示例:
- http://nbviewer.ipython.org/github/carljv/Will_it_Python/blob/master/MLFH/CH3/ch3_nltk.ipynb
- http://www.nltk.org/book/ch06.html
- NLTK classify interface using trained classifier
- Implementing Bag-of-Words Naive-Bayes classifier in NLTK
- http://my.safaribooksonline.com/book/databases/9781783280995/11dot-sentiment-analysis-of-twitter-data/id286781656#X2ludGVybmFsX0h0bWxWaWV3P3htbGlkPTk3ODE3ODMyODA5OTUlMkZpZDI4Njc4MjEwNCZxdWVyeT0=
它们似乎只处理句子本身的功能。所以,你会...
corpus =
[
("This is a sentence"),
("This is another sentence")
]
...然后你应用一些函数,比如 count_words_ending_in_a_vowel() 到句子本身。
相反,我想将一段外部数据应用于句子,不是从文本本身派生的东西,而是外部标签,例如:
corpus =
[
("This is a sentence", "awesome"),
("This is another sentence", "not awesome")
]
或者
corpus =
[
{"text": "This is a sentence", "label": "awesome"},
{"text": "This is another sentence", "label": "not awesome"}
]
(如果我可能有多个外部标签。)
我的问题是:鉴于我的数据集中有这些外部标签,我如何将语料库重新格式化为NaiveBayesClassifier.train() 期望的格式?我知道我还需要在上面的“文本”字段上应用标记器——但是我应该输入 NaiveeBayesClassifier.train 函数的总格式是什么?
申请
classifier = nltk.NaiveBayesClassifier.train(goods)
print(classifier.show_most_informative_features(32))
我更广泛的目标 --- 我想研究不同的词频如何能够预测标签,哪些词集在将标签彼此分开时提供的信息最多。这种有 k-means 的感觉,但我被告知我应该能够完全在 NLTK 中完成此操作,只是在将其转换为适当的数据输入格式时遇到了麻烦。
【问题讨论】: