本文整理汇总了Python中writer.Writer.write_file方法的典型用法代码示例。如果您正苦于以下问题:Python Writer.write_file方法的具体用法?Python Writer.write_file怎么用?Python Writer.write_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类writer.Writer
的用法示例。
在下文中一共展示了Writer.write_file方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_word_count
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import write_file [as 别名]
def test_word_count(self):
file_name = 'data/01-train-input.txt'
reader = Reader(file_name)
reader.read_file()
unigram = TrainUnigram(reader.word_list, reader.total_word_count)
unigram.train_unigram()
file_name = 'data/unigram_model'
write_model = Writer(file_name, unigram.word_dict)
write_model.write_file()
model = Model(file_name)
model.read_model()
file_name = 'data/01-test-input.txt'
test = Evaluater(file_name, model.word_dict)
test.evaluate_model()
print('entropy is ' + str(test.H / test.total_word_count))
print('coverage is ' + str(1.0 * (test.total_word_count - test.unknown_word_count) / test.total_word_count))
示例2: test_word_count
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import write_file [as 别名]
def test_word_count(self):
file_name = 'data/02-train-input.txt'
reader = Reader(file_name)
reader.read_file()
ngram = TrainNgram(reader.word_list, 3)
ngram.train()
print({k: v for k, v in ngram.word_dict.items()})
print({k: v for k, v in ngram.lambda_word_dict.items()})
file_name = 'data/ngram_model'
writer_model = Writer(file_name, ngram.word_dict)
writer_model.write_file()
model = ReadNgram(file_name)
model.read_model()
file_name = 'data/02-train-input.txt'
test = EvaluateModel(file_name, model.word_dict, ngram.lambda_word_dict)
test.evaluate()
print('entropy is ' + str(test.H / test.total_word_count))
示例3: test_word_count
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import write_file [as 别名]
def test_word_count(self):
fileName = 'data/02-train-input.txt'
reader = Reader(fileName)
reader.file_Read()
bigram = TrainBigram(reader.word_list)
bigram.train()
print({k: v for k, v in bigram.word_dict.items()})
print({k: v for k, v in bigram.lambda_word_dict.items()})
fileName = 'data/bigram_model'
writemodel = Writer(fileName, bigram.word_dict)
writemodel.write_file()
model = ModelReader(fileName)
model.read_model()
fileName = 'data/02-train-input.txt'
test = EvaluateModel(fileName, model.word_dict, bigram.lambda_word_dict)
test.evaluate_model()
print('entropy is ' + str(test.H / test.total_word_count))
示例4: test_word_count
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import write_file [as 别名]
def test_word_count(self):
file_name = 'data/01-train-input.txt'
reader = Reader(file_name)
reader.read_file()
unigram = TrainUnigram(reader.word_list, reader.total_word_count)
unigram.train()
file_name = 'data/unigram_model'
writemodel = Writer(file_name, unigram.word_dict)
writemodel.write_file()
file_name = 'data/03-train-input.txt'
cfeature = FeatureReader(file_name)
cfeature.read_feature()
print({k: v for k, v in cfeature.feature_dict.items()})
online = OnlineLearning(cfeature.feature_dict, unigram.word_dict, 'UNI:')
online.online_learning()
print({k: v for k, v in online.phi.items()})
prediction = OnePrediction('data/03-train.txt', online.weight, online.phi, 'UNI:')
prediction.predict()