|
|
|
|
|
import tensorflow as tf |
|
from watermarking_functions import embed_watermark_LSB |
|
|
|
|
|
texts = [ |
|
"This is a positive statement.", |
|
"I love working on machine learning projects.", |
|
|
|
] |
|
|
|
|
|
labels = [1, 1] |
|
|
|
|
|
max_words = 1000 |
|
tokenizer = tf.keras.preprocessing.text.Tokenizer(num_words=max_words) |
|
tokenizer.fit_on_texts(texts) |
|
sequences = tokenizer.texts_to_sequences(texts) |
|
data = tf.keras.preprocessing.sequence.pad_sequences(sequences) |
|
|
|
|
|
model = tf.keras.Sequential([ |
|
tf.keras.layers.Embedding(max_words, 16), |
|
tf.keras.layers.GlobalAveragePooling1D(), |
|
tf.keras.layers.Dense(1, activation='sigmoid') |
|
]) |
|
|
|
|
|
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) |
|
|
|
|
|
model.fit(data, labels, epochs=10, batch_size=32) |
|
|
|
|
|
model.save('text_classification_model.h5') |
|
|
|
|
|
watermark_data = "MyWatermark" |
|
model_with_watermark = embed_watermark_LSB(model, watermark_data) |
|
model_with_watermark.save('text_classification_model_with_watermark.h5') |