|
from tensorflow.keras.preprocessing.sequence import pad_sequences |
|
from tensorflow.keras.optimizers import Adam |
|
from tensorflow.keras.models import load_model |
|
from tqdm import tqdm |
|
import numpy as np |
|
import csv |
|
|
|
dataset = "dataset.csv" |
|
inp_len = 32 |
|
|
|
X = [] |
|
y = [] |
|
|
|
with open(dataset, 'r') as f: |
|
csv_reader = csv.reader(f) |
|
for row in tqdm(csv_reader): |
|
if row == []: continue |
|
label = int(row[0]) |
|
text = row[1] |
|
text = [ord(char) for char in text] |
|
X.append(text) |
|
y.append(label) |
|
|
|
X = np.array(pad_sequences(X, maxlen=inp_len, padding='post')) |
|
y = np.array(y) |
|
|
|
model = load_model("net.h5") |
|
|
|
model.compile(optimizer=Adam(learning_rate=0.00001), loss="mse", metrics=["accuracy",]) |
|
|
|
model.fit(X, y, epochs=2, batch_size=4, workers=4, use_multiprocessing=True) |
|
|
|
model.save("net.h5") |
|
|