建立神经层,包含用 xavier 去初始化第一层, L2 正则化和用 dropout 来减小过拟合的处理:
- def add_model(self, window):
- with tf.variable_scope('Layer1', initializer=xavier_weight_init()) as scope: # 用initializer=xavier去初始化第一层
- W = tf.get_variable( # 第一层有 W,b1,h
- 'W', [self.config.window_size * self.config.embed_size,
- self.config.hidden_size])
- b1 = tf.get_variable('b1', [self.config.hidden_size])
- h = tf.nn.tanh(tf.matmul(window, W) + b1)
- if self.config.l2: # L2 regularization for W
- tf.add_to_collection('total_loss', 0.5 * self.config.l2 * tf.nn.l2_loss(W)) # 0.5 * self.config.l2 * tf.nn.l2_loss(W)
- with tf.variable_scope('Layer2', initializer=xavier_weight_init()) as scope:
- U = tf.get_variable('U', [self.config.hidden_size, self
推荐阅读
【51CTO.com原创稿件】云计算慢慢进入深水区,传统的公有云和私有云都已经裸露出必定的局限性,是以混淆云似乎>>>详细阅读
本文标题:用深度神经网络处理NER命名实体识别问题
地址:http://www.17bianji.com/lsqh/35497.html
1/2 1