本文整理汇总了Python中tagger.Tagger.save方法的典型用法代码示例。如果您正苦于以下问题:Python Tagger.save方法的具体用法?Python Tagger.save怎么用?Python Tagger.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tagger.Tagger
的用法示例。
在下文中一共展示了Tagger.save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from tagger import Tagger [as 别名]
# 或者: from tagger.Tagger import save [as 别名]
def main(training_file, training_dir, load_model, skip_train):
logging.debug('Initializing random seed to 0.')
random.seed(0)
np.random.seed(0)
if load_model:
tagger = Tagger.load(load_model)
data = TaggingDataset.load_from_file(training_file, vocab=tagger.vocab, tags=tagger.tags)
else:
assert not skip_train, 'Cannot --skip_train without a saved model.'
logging.debug('Loading dataset from: %s' % training_file)
data = TaggingDataset.load_from_file(training_file)
logging.debug('Initializing model.')
tagger = Tagger(data.vocab, data.tags)
if not skip_train:
train_data, dev_data = data.split(0.7)
batches_train = train_data.prepare_batches(n_seqs_per_batch=10)
batches_dev = dev_data.prepare_batches(n_seqs_per_batch=100)
train_mgr = TrainingManager(
avg_n_losses=len(batches_train),
training_dir=training_dir,
tagger_taste_fn=lambda: taste_tagger(tagger, batches_train),
tagger_dev_eval_fn=lambda: eval_tagger(tagger, batches_dev),
tagger_save_fn=lambda fname: tagger.save(fname)
)
logging.debug('Starting training.')
while train_mgr.should_continue():
mb_x, mb_y = random.choice(batches_train)
mb_loss = tagger.learn(mb_x, mb_y)
train_mgr.tick(mb_loss=mb_loss)
evaluate_tagger_and_writeout(tagger)