File size: 1,206 Bytes
4fc359d
 
19cad2a
4fc359d
19cad2a
4fc359d
 
 
 
19cad2a
4fc359d
 
 
 
 
 
19cad2a
 
4fc359d
 
 
 
 
 
 
 
 
 
19cad2a
4fc359d
19cad2a
4fc359d
 
19cad2a
 
4fc359d
 
19cad2a
4fc359d
19cad2a
4fc359d
 
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
43
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.layers import Dense, Embedding, Flatten, Dropout
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.models import Sequential
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 = Sequential()
model.add(Embedding(input_dim=1500, output_dim=128, input_length=inp_len))
model.add(Flatten())
model.add(Dropout(0.2))
model.add(Dense(512, activation="tanh"))
model.add(Dropout(0.5))
model.add(Dense(200, activation="selu"))
model.add(Dense(128, activation="softplus"))
model.add(Dense(1, activation="softplus"))

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")