所以我正在使用 textblob python 库,但性能不足。
我已经序列化它并在循环之前加载它(使用 pickle )。
目前需要 ~ 0.1(对于小型训练数据)和 ~ 0.3 对 33'000 个测试数据。我需要让它更快,甚至可能吗?
一些代码:
# Pass trainings before loop, so we can make performance a lot better
trained_text_classifiers = load_serialized_classifier_trainings(config["ALL_CLASSIFICATORS"])
# Specify witch classifiers are used by witch classes
filter_classifiers = get_classifiers_by_resource_names(trained_text_classifiers, config["FILTER_CLASSIFICATORS"])
signal_classifiers = get_classifiers_by_resource_names(trained_text_classifiers, config["SIGNAL_CLASSIFICATORS"])
for (url, headers, body) in iter_warc_records(warc_file, **warc_filters):
start_time = time.time()
body_text = strip_html(body);
# Check if url body passess filters, if yes, index, if no, ignore
if Filter.is_valid(body_text, filter_classifiers):
print "Indexing", url.url
resp = indexer.index_document(body, body_text, signal_classifiers, url=url, headers=headers, links=bool(args.save_linkgraph_domains))
else:
print "\n"
print "Filtered out", url.url
print "\n"
resp = 0
这是对每个 warc 文件的正文和元数据执行检查的循环。
这里有 2 个文本分类检查。
1)在过滤器(非常小的训练数据):
if trained_text_classifiers.classify(body_text) == "True":
return True
else:
return False
2)在 index_document(33'000 个训练数据)中:
prob_dist = trained_text_classifier.prob_classify(body)
prob_dist.max()
# Return the propability of spam
return round(prob_dist.prob("spam"), 2)
分类和 prob_classify 是使用该工具提高性能的方法。