# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import paddle.dataset.conll05 as conll05 import paddle.fluid as fluid import unittest import paddle import numpy as np word_dict, verb_dict, label_dict = conll05.get_dict() word_dict_len = len(word_dict) label_dict_len = len(label_dict) pred_dict_len = len(verb_dict) mark_dict_len = 2 word_dim = 32 mark_dim = 5 hidden_dim = 512 depth = 8 mix_hidden_lr = 1e-3 embedding_name = 'emb' def db_lstm(word, predicate, ctx_n2, ctx_n1, ctx_0, ctx_p1, ctx_p2, mark, is_sparse, **ignored): # 8 features
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import print_function import paddle.dataset.conll05 as conll05 import paddle.fluid as fluid import paddle.fluid.core as core import unittest import paddle import numpy as np import os word_dict, verb_dict, label_dict = conll05.get_dict() word_dict_len = len(word_dict) label_dict_len = len(label_dict) pred_dict_len = len(verb_dict) mark_dict_len = 2 word_dim = 32 mark_dim = 5 hidden_dim = 512 depth = 8 mix_hidden_lr = 1e-3 embedding_name = 'emb' def db_lstm(word, predicate, ctx_n2, ctx_n1, ctx_0, ctx_p1, ctx_p2, mark, is_sparse, **ignored): # 8 features
# -*- coding: utf-8 -*- import paddle from paddle import fluid from paddle.dataset import conll05 word_dict, _, label_dict = conll05.get_dict() word_dim = 32 batch_size = 10 epoch_num = 20 hidden_size = 512 learning_rate = 0.1 word = fluid.layers.data(name="word_data", shape=[1], dtype="int64", lod_level=1) target = fluid.layers.data(name="target", shape=[1], dtype="int64", lod_level=1) embedding = fluid.layers.embedding(size=[len(word_dict), word_dim], input=word, param_attr=fluid.ParamAttr(name="emb", trainable=False)) hidden_0 = fluid.layers.fc(input=embedding, size=hidden_size, act="tanh") hidden_1 = fluid.layers.dynamic_lstm(input=hidden_0, size=hidden_size, gate_activation="sigmoid", candidate_activation="relu", cell_activation="sigmoid") feature_out = fluid.layers.fc(input=hidden_1, size=len(label_dict), act="tanh") # 调用内置 CRF 函数,并针对状态转换进行解码 crf_cost = fluid.layers.linear_chain_crf(input=feature_out,