内容简介:终于用上了bert,踩了一些坑,和大家分享一下。我主要参考了奇点机智的文章,用bert做了两个中文任务:文本分类和相似度计算。这两个任务都是直接用封装好的run_classifer,py,另外两个没有仔细看,用到了再补充。Step1:写好自己的processor,照着例子写就可以,一定要
终于用上了bert,踩了一些坑,和大家分享一下。
我主要参考了奇点机智的文章,用bert做了两个中文任务:文本分类和相似度计算。这两个任务都是直接用封装好的run_classifer,py,另外两个没有仔细看,用到了再补充。
1. DataProcessor
Step1:写好自己的processor,照着例子写就可以,一定要 shuffle !!!
Step2:加到main函数的processors字典里
2. Early Stopping
Step1:建一个hook
early_stopping_hook = tf.contrib.estimator.stop_if_no_decrease_hook(
estimator=estimator,
metric_name='eval_loss',
max_steps_without_decrease=FLAGS.max_steps_without_decrease,
eval_dir=None,
min_steps=0,
run_every_secs=None,
run_every_steps=FLAGS.save_checkpoints_steps)复制代码
Step2:加到estimator.train里
estimator.train(input_fn=train_input_fn, max_steps=num_train_steps, hooks=[early_stopping_hook])复制代码
3. Train and Evaluate
需要用tensorboard查看训练曲线的话比较好
Step1:创建train和eval的spec,这里需要把early stopping的hook加到trainSpec
train_spec = tf.estimator.TrainSpec(input_fn=train_input_fn, max_steps=num_train_steps,
hooks=[early_stopping_hook])
eval_spec = tf.estimator.EvalSpec(input_fn=eval_input_fn, throttle_secs=0)
tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)复制代码
4. Batch size
默认Eval和Predict的batch size都很小,记得改一下
<-未完待续->
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 「Flask实战」鱼书项目实战一
- 「Flask实战」鱼书项目实战三
- 「Flask实战」鱼书项目实战四
- 「Flask实战」鱼书项目实战六
- RocketMQ实战系列从理论到实战
- 「Flask实战」flask鱼书项目实战二
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Think Python
Allen B. Downey / O'Reilly Media / 2012-8-23 / GBP 29.99
Think Python is an introduction to Python programming for students with no programming experience. It starts with the most basic concepts of programming, and is carefully designed to define all terms ......一起来看看 《Think Python》 这本书的介绍吧!