File size: 1,395 Bytes
f10a6b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
# model_training.py

import tensorflow as tf
from watermarking_functions import embed_watermark_LSB

# Sample data for text classification (replace with your data)
texts = [
    "This is a positive statement.",
    "I love working on machine learning projects.",
    # Add more texts for training
]

# Labels: 0 - Negative sentiment, 1 - Positive sentiment
labels = [1, 1]  # Sample labels (binary classification)

# Tokenizing and preparing the data
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)

# Define the model architecture (simple example)
model = tf.keras.Sequential([
    tf.keras.layers.Embedding(max_words, 16),
    tf.keras.layers.GlobalAveragePooling1D(),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

# Compile the model
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

# Train the model
model.fit(data, labels, epochs=10, batch_size=32)

# Save the trained model
model.save('text_classification_model.h5')

# Embed watermark into the trained model
watermark_data = "MyWatermark"  # Replace with your watermark data
model_with_watermark = embed_watermark_LSB(model, watermark_data)
model_with_watermark.save('text_classification_model_with_watermark.h5')