From e42186e9ae5bd3de090eadc21eaaa82cdaf009e1 Mon Sep 17 00:00:00 2001 From: caoying03 Date: Mon, 17 Apr 2017 19:41:29 +0800 Subject: [PATCH] fix a bug in srl when running in notebook. --- 06.label_semantic_roles/README.en.md | 1 + 06.label_semantic_roles/README.md | 31 ++++++++++++++------------- 06.label_semantic_roles/index.en.html | 1 + 06.label_semantic_roles/index.html | 31 ++++++++++++++------------- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/06.label_semantic_roles/README.en.md b/06.label_semantic_roles/README.en.md index 079b961..9e27931 100644 --- a/06.label_semantic_roles/README.en.md +++ b/06.label_semantic_roles/README.en.md @@ -214,6 +214,7 @@ import numpy as np import gzip import paddle.v2 as paddle import paddle.v2.dataset.conll05 as conll05 +import paddle.v2.evaluator as evaluator paddle.init(use_gpu=False, trainer_count=1) diff --git a/06.label_semantic_roles/README.md b/06.label_semantic_roles/README.md index a0e8b42..99257e4 100644 --- a/06.label_semantic_roles/README.md +++ b/06.label_semantic_roles/README.md @@ -192,6 +192,7 @@ import numpy as np import gzip import paddle.v2 as paddle import paddle.v2.dataset.conll05 as conll05 +import paddle.v2.evaluator as evaluator paddle.init(use_gpu=False, trainer_count=1) @@ -274,12 +275,12 @@ emb_layers.append(mark_embedding) ```python hidden_0 = paddle.layer.mixed( -size=hidden_dim, -bias_attr=std_default, -input=[ - paddle.layer.full_matrix_projection( - input=emb, param_attr=std_default) for emb in emb_layers -]) + size=hidden_dim, + bias_attr=std_default, + input=[ + paddle.layer.full_matrix_projection( + input=emb, param_attr=std_default) for emb in emb_layers + ]) mix_hidden_lr = 1e-3 lstm_para_attr = paddle.attr.Param(initial_std=0.0, learning_rate=1.0) @@ -328,14 +329,14 @@ for i in range(1, depth): # 经过一个全连接层映射到标记字典的维度,来学习 CRF 的状态特征 feature_out = paddle.layer.mixed( -size=label_dict_len, -bias_attr=std_default, -input=[ - paddle.layer.full_matrix_projection( - input=input_tmp[0], param_attr=hidden_para_attr), - paddle.layer.full_matrix_projection( - input=input_tmp[1], param_attr=lstm_para_attr) -], ) + size=label_dict_len, + bias_attr=std_default, + input=[ + paddle.layer.full_matrix_projection( + input=input_tmp[0], param_attr=hidden_para_attr), + paddle.layer.full_matrix_projection( + input=input_tmp[1], param_attr=lstm_para_attr) + ], ) # 学习 CRF 的转移特征 crf_cost = paddle.layer.crf( @@ -348,7 +349,7 @@ crf_cost = paddle.layer.crf( learning_rate=mix_hidden_lr)) ``` -- CRF解码和CRF层参数名字相同,即:加载了paddle.layer.crf层学习到的参数。在训练阶段,为 paddle.layer.crf_decoding 输入了正确的标记序列(target),这一层会输出是否正确标记,evaluator.sum 用来计算序列上的标记错误率,可以用来评估模型。解码阶段,没有输入正确的数据标签,该层通过寻找概率最高的标记序列,解码出标记结果。 +- CRF解码和CRF层参数名字相同,即:加载了`paddle.layer.crf`层学习到的参数。在训练阶段,为`paddle.layer.crf_decoding` 输入了正确的标记序列(target),这一层会输出是否正确标记,`evaluator.sum` 用来计算序列上的标记错误率,可以用来评估模型。解码阶段,没有输入正确的数据标签,该层通过寻找概率最高的标记序列,解码出标记结果。 ```python crf_dec = paddle.layer.crf_decoding( diff --git a/06.label_semantic_roles/index.en.html b/06.label_semantic_roles/index.en.html index 5cd490d..76e7c92 100644 --- a/06.label_semantic_roles/index.en.html +++ b/06.label_semantic_roles/index.en.html @@ -256,6 +256,7 @@ import numpy as np import gzip import paddle.v2 as paddle import paddle.v2.dataset.conll05 as conll05 +import paddle.v2.evaluator as evaluator paddle.init(use_gpu=False, trainer_count=1) diff --git a/06.label_semantic_roles/index.html b/06.label_semantic_roles/index.html index 5f78688..cf67065 100644 --- a/06.label_semantic_roles/index.html +++ b/06.label_semantic_roles/index.html @@ -234,6 +234,7 @@ import numpy as np import gzip import paddle.v2 as paddle import paddle.v2.dataset.conll05 as conll05 +import paddle.v2.evaluator as evaluator paddle.init(use_gpu=False, trainer_count=1) @@ -316,12 +317,12 @@ emb_layers.append(mark_embedding) ```python hidden_0 = paddle.layer.mixed( -size=hidden_dim, -bias_attr=std_default, -input=[ - paddle.layer.full_matrix_projection( - input=emb, param_attr=std_default) for emb in emb_layers -]) + size=hidden_dim, + bias_attr=std_default, + input=[ + paddle.layer.full_matrix_projection( + input=emb, param_attr=std_default) for emb in emb_layers + ]) mix_hidden_lr = 1e-3 lstm_para_attr = paddle.attr.Param(initial_std=0.0, learning_rate=1.0) @@ -370,14 +371,14 @@ for i in range(1, depth): # 经过一个全连接层映射到标记字典的维度,来学习 CRF 的状态特征 feature_out = paddle.layer.mixed( -size=label_dict_len, -bias_attr=std_default, -input=[ - paddle.layer.full_matrix_projection( - input=input_tmp[0], param_attr=hidden_para_attr), - paddle.layer.full_matrix_projection( - input=input_tmp[1], param_attr=lstm_para_attr) -], ) + size=label_dict_len, + bias_attr=std_default, + input=[ + paddle.layer.full_matrix_projection( + input=input_tmp[0], param_attr=hidden_para_attr), + paddle.layer.full_matrix_projection( + input=input_tmp[1], param_attr=lstm_para_attr) + ], ) # 学习 CRF 的转移特征 crf_cost = paddle.layer.crf( @@ -390,7 +391,7 @@ crf_cost = paddle.layer.crf( learning_rate=mix_hidden_lr)) ``` -- CRF解码和CRF层参数名字相同,即:加载了paddle.layer.crf层学习到的参数。在训练阶段,为 paddle.layer.crf_decoding 输入了正确的标记序列(target),这一层会输出是否正确标记,evaluator.sum 用来计算序列上的标记错误率,可以用来评估模型。解码阶段,没有输入正确的数据标签,该层通过寻找概率最高的标记序列,解码出标记结果。 +- CRF解码和CRF层参数名字相同,即:加载了`paddle.layer.crf`层学习到的参数。在训练阶段,为`paddle.layer.crf_decoding` 输入了正确的标记序列(target),这一层会输出是否正确标记,`evaluator.sum` 用来计算序列上的标记错误率,可以用来评估模型。解码阶段,没有输入正确的数据标签,该层通过寻找概率最高的标记序列,解码出标记结果。 ```python crf_dec = paddle.layer.crf_decoding( -- GitLab