forked from bhuvanakundumani/NER_tensorflow2.2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
17 lines (13 loc) · 797 Bytes
/
Copy pathmodel.py
File metadata and controls
17 lines (13 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import tensorflow as tf
from tensorflow.keras import layers
class TFNer(tf.keras.Model):
def __init__(self, max_seq_len, embed_input_dim, embed_output_dim, num_labels, weights):
super(TFNer, self).__init__()
self.embedding = layers.Embedding(input_dim=embed_input_dim, output_dim=embed_output_dim, weights=weights, input_length=max_seq_len, trainable=False, mask_zero=True)
self.bilstm = layers.Bidirectional(layers.LSTM(128, return_sequences=True))
self.dense = layers.Dense(num_labels)
def call(self, inputs):
x = self.embedding(inputs) # batchsize, max_seq_len, embedding_output_dim
x = self.bilstm(x) #batchsize, max_seq_len, hidden_dim_bilstm
logits = self.dense(x) #batchsize, max_seq_len, num_labels
return logits