Skip to content

Use pathlib to get abs-file-path of csv files from the the project directory #46

Open
cuicaihao wants to merge 6 commits intowzhe06:masterfrom
cuicaihao:master
Open

Use pathlib to get abs-file-path of csv files from the the project directory #46
cuicaihao wants to merge 6 commits intowzhe06:masterfrom
cuicaihao:master

Conversation

@cuicaihao
Copy link
Copy Markdown

Replace the following code from

import tensorflow as tf
# Training samples path, change to your local path
training_samples_file_path = tf.keras.utils.get_file("trainingSamples.csv",
                                                     "file:///Users/zhewang/Workspace/SparrowRecSys/src/main"
                                                     "/resources/webroot/sampledata/trainingSamples.csv")
# Test samples path, change to your local path
test_samples_file_path = tf.keras.utils.get_file("testSamples.csv",
                                                 "file:///Users/zhewang/Workspace/SparrowRecSys/src/main"
                                                 "/resources/webroot/sampledata/testSamples.csv")

to

import tensorflow as tf
import pathlib
current_working_directory = pathlib.Path().absolute()
train_abs_path = current_working_directory / \
    "src/main/resources/webroot/sampledata/trainingSamples.csv"
test_abs_path = current_working_directory / \
    "src/main/resources/webroot/sampledata/testSamples.csv"

#  check the file paths 
print(train_abs_path)
print(test_abs_path)

# Training samples path, change to your local path
training_samples_file_path = tf.keras.utils.get_file("trainingSamples.csv",
                                                     "file://" + str(train_abs_path))
# Test samples path, change to your local path
test_samples_file_path = tf.keras.utils.get_file("testSamples.csv",
                                                 "file://" + str(test_abs_path))

Test command can be:

# cd PATH-TO-PROJECT
(base) ➜  SparrowRecSys git:(master) ✗ python TFRecModel/src/com/sparrowrecsys/offline/tensorflow/EmbeddingMLP.py 

Terminal output will be like:

(base) ➜  SparrowRecSys git:(master) ✗ python TFRecModel/src/com/sparrowrecsys/offline/tensorflow/EmbeddingMLP.py 
  
/Users/caihaocui/Documents/GitHub/SparrowRecSys/src/main/resources/webroot/sampledata/trainingSamples.csv
/Users/caihaocui/Documents/GitHub/SparrowRecSys/src/main/resources/webroot/sampledata/testSamples.csv

2021-05-01 23:34:19.899459: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-05-01 23:34:19.899750: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-05-01 23:34:20.127706: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2)
Epoch 1/5
7403/7403 [==============================] - 23s 3ms/step - loss: 6.2921 - accuracy: 0.5508 - auc: 0.5540 - auc_1: 0.6035
Epoch 2/5
7403/7403 [==============================] - 25s 3ms/step - loss: 0.6940 - accuracy: 0.6447 - auc: 0.6820 - auc_1: 0.7157
Epoch 3/5
7403/7403 [==============================] - 26s 3ms/step - loss: 0.5712 - accuracy: 0.7060 - auc: 0.7657 - auc_1: 0.7862
Epoch 4/5
7403/7403 [==============================] - 25s 3ms/step - loss: 0.5235 - accuracy: 0.7434 - auc: 0.8117 - auc_1: 0.8311
Epoch 5/5
7403/7403 [==============================] - 28s 4ms/step - loss: 0.5019 - accuracy: 0.7550 - auc: 0.8295 - auc_1: 0.8507
1870/1870 [==============================] - 3s 1ms/step - loss: 0.5930 - accuracy: 0.6951 - auc: 0.7545 - auc_1: 0.7811
Test Loss 0.5929673314094543, Test Accuracy 0.6950534582138062, Test ROC AUC 0.7545442581176758, Test PR AUC 0.7810750603675842
WARNING:tensorflow:Layers in a Sequential model should only have a single input tensor, but we receive ... ... 
Predicted good rating: 92.50%  | Actual rating label:  Good Rating
Predicted good rating: 15.49%  | Actual rating label:  Bad Rating
Predicted good rating: 51.89%  | Actual rating label:  Good Rating
Predicted good rating: 74.08%  | Actual rating label:  Good Rating
Predicted good rating: 66.84%  | Actual rating label:  Good Rating
Predicted good rating: 92.49%  | Actual rating label:  Good Rating
Predicted good rating: 13.64%  | Actual rating label:  Good Rating
Predicted good rating: 35.65%  | Actual rating label:  Good Rating
Predicted good rating: 11.24%  | Actual rating label:  Bad Rating
Predicted good rating: 88.39%  | Actual rating label:  Good Rating
Predicted good rating: 42.15%  | Actual rating label:  Bad Rating
Predicted good rating: 90.55%  | Actual rating label:  Bad Rating
(base) ➜  SparrowRecSys git:(master) ✗ 

cuicaihao added 6 commits May 1, 2021 18:55
Add learning QA of Section one
Add the "current_working_directory" in python to remove abs file path. Thus,
enable: python TFRecModel/src/com/sparrowrecsys/offline/tensorflow/xxx.py
Merge the fixed random walk function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant