Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

model.py 970 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  1. import tensorflow as tf
  2. from tensorflow.keras import Model
  3. class TSModel(Model):
  4. def __init__(self, model_name="TweetsSentimentModel", max_tokens=2000):
  5. super(TSModel, self).__init__()
  6. self.model_name = model_name
  7. self.dropout = tf.keras.layers.Dropout(0.5)
  8. self.embed_layer = tf.keras.layers.Embedding(input_dim=max_tokens, output_dim=64,mask_zero=True)
  9. self.lstm = tf.keras.layers.LSTM(32)
  10. self.bidirectional = tf.keras.layers.Bidirectional(self.lstm)
  11. self.dense = tf.keras.layers.Dense(128, activation="relu")
  12. self.out = tf.keras.layers.Dense(1, activation="sigmoid")
  13. def call(self, input):
  14. """ Builds the Keras model based """
  15. x = input[:]
  16. x = self.embed_layer(x)
  17. x = self.bidirectional(x)
  18. x = self.dropout(x)
  19. x = self.dense(x)
  20. x = self.dropout(x)
  21. return self.out(x)
  22. if __name__ == '__main__':
  23. model = TSModel()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...