Zig*_*ien 6 hierarchical-clustering nltk training-data topic-modeling scikit-learn
我想按主题对大量(100K到1M +)的小型互联网文章(推文,博客文章,新闻等)进行分类.为了实现这一目标,我一直在寻找标记的培训数据文档,我可以用它来构建分类器模型.为了使这篇文章最有用,以下是我发现的一些可能的来源:
a)www.freebase.com/internet/website/category?instances=
b)wikipedia-miner.cms.waikato.ac.nz(用于访问维基百科数据的工具包)
c)en.wikipedia.org/wiki/Wikipedia:Database_download
d)wiki.dbpedia.org/About(属于类别的SKOS格式主题关键字)
e)互联网搜索大型文章集,然后进行聚类和手动策划
问题1:是否有其他可提供标签培训文件的互联网资源?给定主题上的关键字集,尤其是加权集也很有用
理想情况下,我想构建一个分类器,该分类器将返回分层类别,并且随着更多兴趣/数据变得可用,可以在以后添加子主题细节.
问题2:是否存在分层结构(也可能是可扩展的)主题建模/分类框架?一个代码示例将特别受欢迎
非常感谢
路透社语料库第1卷(在RCV1-v2上搜索)它是从1990年代后期开始的大约80万路透社文章被人类分类为主题,行业和地区类别
一个学术联盟(LDC)分发各种语料库,包括由纽约时报编制的约1.5M标签文件:http: //catalog.ldc.upenn.edu/LDC2008T19
小智 2
缺乏标记数据是困扰机器学习许多应用的一个问题。澄清一下,您是否正在寻找一个查看您的推文、博客文章和新闻、标记来源并发布该数据库的人?或者程序进行分类是否可以接受?在前一种情况下,关键词看起来像是一个很好的分类方案,但实际上并非如此:不同的人会为相同的内容选择不同的关键词。这将从根本上损害你的机器学习过程。
我的观点是,无论哪种情况,你都应该使用无监督学习(不提供标签)而不是监督学习(提供标签)——你不应该寻找标记数据,因为你找不到它。即使您遇到一些已由程序标记的数据,该程序也可能使用无监督学习方法。
我建议您使用 scikit-learn 的 cluster 模块中定义的一些函数。这些实施无监督学习技术。
加州大学欧文分校拥有大型机器学习数据集存储库。您可以在他们的一些数据集上测试您的一些自然语言处理工作。一种流行的数据集是安然电子邮件数据集。它和其他 4 个都在这里编译。
UCI 数据集很棒,但它们不是 scikit-learn 格式。你必须转换它们。我通常使用 iris 数据集,因为它很小,您可以通过这种方式轻松使用 scikit-learn。正如您在本示例中看到的,该行
est.fit(X)
Run Code Online (Sandbox Code Playgroud)
仅需要数据数组 X,不需要标签 Y。
X = iris.data
Run Code Online (Sandbox Code Playgroud)
为 X 分配一个 150_instances x 4_features numpy 数组。您需要此表格中来自 UCI 的数据。让我们看一下《纽约时报》的新闻文章。
来自 UCI 链接注释中的 readme.txt
For each text collection, D is the number of documents, W is the
number of words in the vocabulary, and N is the total number of words
in the collection (below, NNZ is the number of nonzero counts in the
bag-of-words). After tokenization and removal of stopwords, the
vocabulary of unique words was truncated by only keeping words that
occurred more than ten times.
...
NYTimes news articles:
orig source: ldc.upenn.edu
D=300000
W=102660
N=100,000,000 (approx)
Run Code Online (Sandbox Code Playgroud)
也就是说,您的 X 将具有形状 300000_instances x 102660_features。注意属性格式:
Attribute Information:
The format of the docword.*.txt file is 3 header lines, followed by
NNZ triples:
---
D
W
NNZ
docID wordID count
docID wordID count
docID wordID count
docID wordID count
...
docID wordID count
docID wordID count
docID wordID count
---
Run Code Online (Sandbox Code Playgroud)
此数据位于 docword.nytimes.txt 数据文件中。一些读取它并运行聚类算法的代码:
import numpy as np
from sklearn.cluster import KMeans
with open('docword.nytimes.txt','r') as f:
# read the header information
n_instances = int(f.readline())
n_attributes = int(f.readline())
n_nnz = int(f.readline())
# create scikit-learn X numpy array
X = np.zeros((n_instances, n_attributes))
for line in f:
doc_id, word_id, count = line.split()
X[doc_id, word_id] = count
# run sklearn clustering on nytimes data
n_clusters = 8
est = KMeans(n_clusters)
est.fit(X)
Run Code Online (Sandbox Code Playgroud)
不幸的是,这需要大量内存。实际上,内存比我的机器多,所以我无法测试这段代码。尽管如此,我想您的应用程序领域与此相当。您将不得不研究一些降维技术,或者一次只查看较小的单词子集。
我希望这有帮助。欢迎给我留言。
| 归档时间: |
|
| 查看次数: |
1422 次 |
| 最近记录: |