File size: 829 Bytes
ec36c33 |
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 |
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")
|