【发布时间】:2019-03-15 00:09:12
【问题描述】:
我正在开发一个 NLP 应用程序,其中我有一个文本文件语料库。我想使用 Gensim word2vec 算法 创建词向量。
我进行了 90% 的训练和 10% 的测试。我在适当的集上训练了模型,但我想评估模型在测试集上的准确性。
我已经在互联网上浏览了有关准确性评估的任何文档,但我找不到任何允许我这样做的方法。有谁知道做精度分析的函数吗?
我处理测试数据的方式是从测试文件夹中的文本文件中提取所有句子,并将其变成一个巨大的句子列表。在那之后,我使用了一个我认为是正确的函数(结果它不是因为它给了我这个错误:TypeError: don't know how to handle uri)。以下是我的做法:
test_filenames = glob.glob('./testing/*.txt')
print("Found corpus of %s safety/incident reports:" %len(test_filenames))
test_corpus_raw = u""
for text_file in test_filenames:
txt_file = open(text_file, 'r')
test_corpus_raw += unicode(txt_file.readlines())
print("Test Corpus is now {0} characters long".format(len(test_corpus_raw)))
test_raw_sentences = tokenizer.tokenize(test_corpus_raw)
def sentence_to_wordlist(raw):
clean = re.sub("[^a-zA-Z]"," ", raw)
words = clean.split()
return words
test_sentences = []
for raw_sentence in test_raw_sentences:
if len(raw_sentence) > 0:
test_sentences.append(sentence_to_wordlist(raw_sentence))
test_token_count = sum([len(sentence) for sentence in test_sentences])
print("The test corpus contains {0:,} tokens".format(test_token_count))
####### THIS LAST LINE PRODUCES AN ERROR: TypeError: don't know how to handle uri
texts2vec.wv.accuracy(test_sentences, case_insensitive=True)
我不知道如何修复这最后一部分。请帮忙。提前致谢!
【问题讨论】:
标签: python nlp gensim word2vec