ierhon commited on
Commit
ec36c33
1 Parent(s): 8b751e5

Create fine-tune.py

Browse files
Files changed (1) hide show
  1. fine-tune.py +33 -0
fine-tune.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
2
+ from tensorflow.keras.optimizers import Adam
3
+ from tensorflow.keras.models import load_model
4
+ from tqdm import tqdm
5
+ import numpy as np
6
+ import csv
7
+
8
+ dataset = "dataset.csv"
9
+ inp_len = 32
10
+
11
+ X = []
12
+ y = []
13
+
14
+ with open(dataset, 'r') as f:
15
+ csv_reader = csv.reader(f)
16
+ for row in tqdm(csv_reader):
17
+ if row == []: continue
18
+ label = int(row[0])
19
+ text = row[1]
20
+ text = [ord(char) for char in text]
21
+ X.append(text)
22
+ y.append(label)
23
+
24
+ X = np.array(pad_sequences(X, maxlen=inp_len, padding='post'))
25
+ y = np.array(y)
26
+
27
+ model = load_model("net.h5")
28
+
29
+ model.compile(optimizer=Adam(learning_rate=0.00001), loss="mse", metrics=["accuracy",])
30
+
31
+ model.fit(X, y, epochs=2, batch_size=4, workers=4, use_multiprocessing=True)
32
+
33
+ model.save("net.h5")