提交 da2db0f3 编写于 作者: Z Zeyu Chen

add simple demo

上级 635af633
import paddle.fluid as fluid
import paddlehub as hub
# Step1
module = hub.Module(name="ernie")
inputs, outputs, program = module.context(trainable=True, max_seq_len=128)
# Step2
dataset = hub.dataset.ChnSentiCorp()
reader = hub.reader.ClassifyReader(
dataset=dataset, vocab_path=module.get_vocab_path(), max_seq_len=128)
# Step3
with fluid.program_guard(program):
label = fluid.layers.data(name="label", shape=[1], dtype='int64')
pooled_output = outputs["pooled_output"]
cls_task = hub.create_text_classification_task(
feature=pooled_output, label=label, num_classes=dataset.num_labels)
# Step4
strategy = hub.AdamWeightDecayStrategy(learning_rate=5e-5, weight_decay=0.01)
config = hub.RunConfig(
use_cuda=True, num_epoch=3, batch_size=32, strategy=strategy)
feed_list = [
inputs["input_ids"].name, inputs["position_ids"].name,
inputs["segment_ids"].name, inputs["input_mask"].name, label.name
]
hub.finetune_and_eval(
task=cls_task, data_reader=reader, feed_list=feed_list, config=config)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册