Skip to content

Commit 96a0aa2

Browse files
committed
so much betterrrrrr
1 parent 5210f5f commit 96a0aa2

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

word_based.ipynb

+7-16
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,18 @@
9696
"#--- --- ---- --- ---- --- ---- ---- --- ----- ---- ---\n",
9797
"# -- Write Files ---- ---- ---- --- ---- --- --- --- -- \n",
9898
"#--- --- ---- --- ---- --- ---- ---- --- ----- ---- ---\n",
99-
"def writeFiles(model, modelName, history_callback, modelList, seq_length, total_sequences, epochs, batch_size):\n",
99+
"def writeFiles(model, modelName, history_callback, modelList, seq_length, total_sequences, epochs, batch_size, results_path):\n",
100100
" loss_history = history_callback.history\n",
101101
" \n",
102102
" # save the model to file\n",
103-
" model.save('m_' + modelName + '.h5')\n",
103+
" model.save(results_path.rstrip('/') + '/m_' + modelName + '.h5')\n",
104104
" loss_history['seq_length'] = seq_length\n",
105105
" loss_history['total_sequences'] = total_sequences\n",
106106
" loss_history['batch_size'] = batch_size\n",
107107
" loss_history['epochs'] = epochs\n",
108108
" \n",
109109
" # save losses\n",
110-
" with open('info_' + modelName + '.txt', 'w+') as f:\n",
110+
" with open(results_path.rstrip('/') + '/info_' + modelName + '.txt', 'w+') as f:\n",
111111
" f.write(str(modelList))\n",
112112
" f.write('\\n')\n",
113113
" f.write(str(loss_history))\n"
@@ -219,20 +219,11 @@
219219
},
220220
{
221221
"cell_type": "code",
222-
"execution_count": 8,
222+
"execution_count": 14,
223223
"metadata": {},
224-
"outputs": [
225-
{
226-
"ename": "SyntaxError",
227-
"evalue": "positional argument follows keyword argument (<ipython-input-8-b8a592ace547>, line 61)",
228-
"output_type": "error",
229-
"traceback": [
230-
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-8-b8a592ace547>\"\u001b[0;36m, line \u001b[0;32m61\u001b[0m\n\u001b[0;31m writeFiles(model, modelName, history_callback, modelList, seq_length, total_sequences = len(sequences), epochs, batch_size)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m positional argument follows keyword argument\n"
231-
]
232-
}
233-
],
224+
"outputs": [],
234225
"source": [
235-
"def trainModelComplete():\n",
226+
"def trainModelComplete(results_path):\n",
236227
" from keras.utils import to_categorical\n",
237228
" \n",
238229
" #--- PARAMETERS --- --- --- ---- --- --- ---- ---- --- ----- --- --- ----\n",
@@ -299,7 +290,7 @@
299290
" #-- Fit model -- ---- --- --- --- ---- --- --- ---- --- --- --- --- --- --- --- --- \n",
300291
" history_callback = modelFit(model, modelName, X, y, seq_length, batch_size, epochs)\n",
301292
" #-- Save history and final model --- -\n",
302-
" writeFiles(model, modelName, history_callback, modelList, seq_length, len(sequences), epochs, batch_size)"
293+
" writeFiles(model, modelName, history_callback, modelList, seq_length, len(sequences), epochs, batch_size, results_path)"
303294
]
304295
},
305296
{

word_based.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ def modelFit(model, modelName, X, y, seq_length, batch_size, epochs):
8282
#--- --- ---- --- ---- --- ---- ---- --- ----- ---- ---
8383
# -- Write Files ---- ---- ---- --- ---- --- --- --- --
8484
#--- --- ---- --- ---- --- ---- ---- --- ----- ---- ---
85-
def writeFiles(model, modelName, history_callback, modelList, seq_length, total_sequences, epochs, batch_size):
85+
def writeFiles(model, modelName, history_callback, modelList, seq_length, total_sequences, epochs, batch_size, results_path):
8686
loss_history = history_callback.history
8787

8888
# save the model to file
89-
model.save('m_' + modelName + '.h5')
89+
model.save(results_path.rstrip('/') + '/m_' + modelName + '.h5')
9090
loss_history['seq_length'] = seq_length
9191
loss_history['total_sequences'] = total_sequences
9292
loss_history['batch_size'] = batch_size
9393
loss_history['epochs'] = epochs
9494

9595
# save losses
96-
with open('info_' + modelName + '.txt', 'w+') as f:
96+
with open(results_path.rstrip('/') + '/info_' + modelName + '.txt', 'w+') as f:
9797
f.write(str(modelList))
9898
f.write('\n')
9999
f.write(str(loss_history))
@@ -182,10 +182,10 @@ def defineModel(vocab_size, seq_length, modelList, length, input_shape):
182182
return model, modelName
183183

184184

185-
# In[8]:
185+
# In[14]:
186186

187187

188-
def trainModelComplete():
188+
def trainModelComplete(results_path):
189189
from keras.utils import to_categorical
190190

191191
#--- PARAMETERS --- --- --- ---- --- --- ---- ---- --- ----- --- --- ----
@@ -252,7 +252,7 @@ def trainModelComplete():
252252
#-- Fit model -- ---- --- --- --- ---- --- --- ---- --- --- --- --- --- --- --- ---
253253
history_callback = modelFit(model, modelName, X, y, seq_length, batch_size, epochs)
254254
#-- Save history and final model --- -
255-
writeFiles(model, modelName, history_callback, modelList, seq_length, len(sequences), epochs, batch_size)
255+
writeFiles(model, modelName, history_callback, modelList, seq_length, len(sequences), epochs, batch_size, results_path)
256256

257257

258258
# In[9]:

0 commit comments

Comments
 (0)