【问题标题】:Extract brand and product category from consumer product manuals从消费品手册中提取品牌和产品类别
【发布时间】:2014-10-13 08:52:13
【问题描述】:
我有一份从网上废弃的消费产品手册列表(大约 100,000 个 .pdf 文件)。现在我想按制造商/品牌及其所属的类别对文件进行分类。
例如:
三星 -> 显示器 -> [ 文件列表 ]
三星 -> 手机 -> [ 文件列表 ]
等等……
到目前为止我做了什么:
- 建立了品牌/制造商列表和类别列表。
- 使用pyPdf从pdf文件中提取所有数据为文本
- 用NLTK标记文本数据中的单词
- 看起来像这样:
...
('3Com', 'CD')
('Corporation', 'NNP')
('reserves', 'NNS')
('the', 'DT')
('right', 'NN')
('to', 'TO')
('revise', 'VB')
('this', 'DT')
('documentation', 'NN')
('and', 'CC')
('to', 'TO')
('make', 'VB')
('changes', 'NNS')
('in', 'IN')
('content', 'NN')
('from', 'IN')
...
我现在面临的问题:
如何将令牌与我的品牌/类别列表匹配?
我以前从未有机会与 NLP 一起工作,而且我仍在努力思考这个问题。
【问题讨论】:
标签:
python
nlp
nltk
named-entity-recognition
【解决方案1】:
我不确定这是 NLP 问题。以下是我的做法:
brand_names = ['Samsung', 'Lenovo', ...]
category_names = ['Monitors', 'Mobile Phones', ...]
pdf_string = read_my_pdf('theproduct.pdf')
pdf_string_lowered = pdf_string.lower()
brand_names_in_pdf = [brand.lower() in pdf_string_lowered for brand in brand_names] #Everything is lowered to account for case difference
category_names_in_pdf = [category.lower() in pdf_string_lowered for category in category_names]
import itertools
tags = itertools.product(brand_names_in_pdf, category_names_in_pdf) #Get the tuples of brands and categories
这看起来很简单,但我认为它比您将使用的任何 NLP 工具都更有效(您如何知道特定型号是手机的型号,或者与手机相关的一些词会是包含在 PDF 中关于其他内容)。我认为详尽的搜索更可靠。
这种方法唯一真正的缺点是与您要查找的单词的变化有关。我认为解决这个问题的方法是使用正则表达式而不是标记。例如,您可以接受“Mobile Phones”或“Mobile Phone”,并将它们归类为“Mobile Phones”。
【解决方案2】:
我建议采用混合方法。使用词性标注器查找 NNP 专有名词,然后在公司名称词典中查找它们。
这使您免于查找限定词和其他不太可能的词。这应该通过减少误报来提高精确度,例如有人可能将公司名称用作动词(xerox、google)。不利的一面是,它可能会通过增加假阴性来降低召回率,即公司名称被错误标记并且从未在您的字典中查找过。