ierhon commited on
Commit
19cad2a
1 Parent(s): dd6d3b2

Update net.py

Browse files
Files changed (1) hide show
  1. net.py +11 -11
net.py CHANGED
@@ -1,20 +1,21 @@
1
  from tensorflow.keras.preprocessing.sequence import pad_sequences
2
  from tensorflow.keras.layers import Dense, Embedding, Flatten, Dropout
 
3
  from tensorflow.keras.models import Sequential
 
4
  import numpy as np
5
  import csv
6
 
7
  dataset = "dataset.csv"
8
- inp_len = 16
9
 
10
  X = []
11
  y = []
12
 
13
  with open(dataset, 'r') as f:
14
  csv_reader = csv.reader(f)
15
- next(csv_reader) # Skip the header row if it exists
16
-
17
- for row in csv_reader:
18
  label = int(row[0])
19
  text = row[1]
20
  text = [ord(char) for char in text]
@@ -25,18 +26,17 @@ X = np.array(pad_sequences(X, maxlen=inp_len, padding='post'))
25
  y = np.array(y)
26
 
27
  model = Sequential()
28
- model.add(Embedding(input_dim=1500, output_dim=256, input_length=inp_len))
29
  model.add(Flatten())
30
- model.add(Dropout(0.5))
31
  model.add(Dense(512, activation="tanh"))
32
  model.add(Dropout(0.5))
33
- model.add(Dense(256, activation="selu"))
34
- model.add(Dense(256, activation="softplus"))
35
  model.add(Dense(1, activation="softplus"))
36
 
37
- model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy",])
38
 
39
- model.fit(X, y, epochs=64, batch_size=4, workers=2, use_multiprocessing=True)
40
 
41
  model.save("net.h5")
42
-
 
1
  from tensorflow.keras.preprocessing.sequence import pad_sequences
2
  from tensorflow.keras.layers import Dense, Embedding, Flatten, Dropout
3
+ from tensorflow.keras.optimizers import Adam
4
  from tensorflow.keras.models import Sequential
5
+ from tqdm import tqdm
6
  import numpy as np
7
  import csv
8
 
9
  dataset = "dataset.csv"
10
+ inp_len = 32
11
 
12
  X = []
13
  y = []
14
 
15
  with open(dataset, 'r') as f:
16
  csv_reader = csv.reader(f)
17
+ for row in tqdm(csv_reader):
18
+ if row == []: continue
 
19
  label = int(row[0])
20
  text = row[1]
21
  text = [ord(char) for char in text]
 
26
  y = np.array(y)
27
 
28
  model = Sequential()
29
+ model.add(Embedding(input_dim=1500, output_dim=128, input_length=inp_len))
30
  model.add(Flatten())
31
+ model.add(Dropout(0.2))
32
  model.add(Dense(512, activation="tanh"))
33
  model.add(Dropout(0.5))
34
+ model.add(Dense(200, activation="selu"))
35
+ model.add(Dense(128, activation="softplus"))
36
  model.add(Dense(1, activation="softplus"))
37
 
38
+ model.compile(optimizer=Adam(learning_rate=0.00001), loss="mse", metrics=["accuracy",])
39
 
40
+ model.fit(X, y, epochs=2, batch_size=4, workers=4, use_multiprocessing=True)
41
 
42
  model.save("net.h5")