Guest User

Untitled

a guest
Jun 24th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. from keras.layers import (Dense, Dropout, Embedding, GlobalAveragePooling1D,
  2. Input, Bidirectional, Activation, Reshape)
  3. from keras.layers.merge import concatenate
  4. from keras.layers.recurrent import LSTM
  5. from keras.models import Model, Sequential
  6. from keras.optimizers import SGD
  7. from keras.regularizers import l1_l2
  8. from keras.utils import plot_model
  9.  
  10. max_features = 20000
  11. maxlen = 30
  12. embedding_dims = 50
  13.  
  14. visible = Input(shape=(30,), name="Input")
  15. embedding = Embedding(max_features+1,
  16. embedding_dims,
  17. input_length=maxlen,
  18. name="Embedding")(visible)
  19.  
  20. embedding = Dropout(rate=0.5)(embedding)
  21.  
  22. transformed = Reshape((-1,))(embedding)
  23. representation = Dense(50, name="Representation")(transformed)
  24. representation = Dropout(rate=0.5)(representation)
  25. output = Dense(n_labels, activation='softmax', name="Output")(representation)
  26. model = Model(inputs=visible, outputs=output)
  27.  
  28. sgd = SGD(lr=0.01, momentum=0.8, decay=0.0, nesterov=False)
  29. model.compile(loss='categorical_crossentropy',
  30. optimizer=sgd,
  31. metrics=['accuracy'])
  32.  
  33. max_features = 20000
  34. maxlen = 30
  35. embedding_dims = 50
  36.  
  37. model = Sequential()
  38. # we start off with an efficient embedding layer which maps
  39. # our vocab indices into embedding_dims dimensions
  40. model.add(Embedding(max_features+1,
  41. embedding_dims,
  42. input_length=maxlen))
  43.  
  44. model.add(Dropout(rate=0.5))
  45. # we add a GlobalAveragePooling1D, which will average the embeddings
  46. # of all words in the document
  47. model.add(GlobalAveragePooling1D())
  48. model.add(Dropout(rate=0.5))
  49.  
  50. # We project onto a single unit output layer, and squash it with a sigmoid:
  51. model.add(Dense(n_labels, activation='softmax'))
  52.  
  53. sgd = SGD(lr=0.01, momentum=0.8, decay=0.0, nesterov=False)
  54.  
  55. model.compile(loss='categorical_crossentropy',
  56. optimizer=sgd,
  57. metrics=['accuracy'])
  58. return model
Add Comment
Please, Sign In to add comment