diff --git a/examples/00_quick_start/fastai_movielens.ipynb b/examples/00_quick_start/fastai_movielens.ipynb index b475d09cf..944b92623 100644 --- a/examples/00_quick_start/fastai_movielens.ipynb +++ b/examples/00_quick_start/fastai_movielens.ipynb @@ -27,17 +27,21 @@ "name": "stdout", "output_type": "stream", "text": [ - "System version: 3.6.11 | packaged by conda-forge | (default, Aug 5 2020, 20:09:42) \n", - "[GCC 7.5.0]\n", - "Pandas version: 0.25.3\n", - "Fast AI version: 1.0.46\n", - "Torch version: 1.4.0\n", - "Cuda Available: False\n", + "System version: 3.9.16 (main, May 15 2023, 23:46:34) \n", + "[GCC 11.2.0]\n", + "Pandas version: 1.5.3\n", + "Fast AI version: 2.7.11\n", + "Torch version: 1.13.1+cu117\n", + "CUDA Available: True\n", "CuDNN Enabled: True\n" ] } ], "source": [ + "# Suppress all warnings\n", + "import warnings\n", + "warnings.filterwarnings(\"ignore\")\n", + "\n", "import os\n", "import sys\n", "import numpy as np\n", @@ -67,7 +71,7 @@ "print(\"Pandas version: {}\".format(pd.__version__))\n", "print(\"Fast AI version: {}\".format(fastai.__version__))\n", "print(\"Torch version: {}\".format(torch.__version__))\n", - "print(\"Cuda Available: {}\".format(torch.cuda.is_available()))\n", + "print(\"CUDA Available: {}\".format(torch.cuda.is_available()))\n", "print(\"CuDNN Enabled: {}\".format(torch.backends.cudnn.enabled))" ] }, @@ -80,7 +84,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": { "tags": [ "parameters" @@ -101,14 +105,14 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "100%|██████████| 4.81k/4.81k [00:01<00:00, 4.49kKB/s]\n" + "100%|██████████| 4.81k/4.81k [00:01<00:00, 3.52kKB/s]\n" ] }, { @@ -132,10 +136,10 @@ " \n", " \n", " \n", - " UserId\n", - " MovieId\n", - " Rating\n", - " Timestamp\n", + " userID\n", + " itemID\n", + " rating\n", + " timestamp\n", " \n", " \n", " \n", @@ -179,15 +183,15 @@ "" ], "text/plain": [ - " UserId MovieId Rating Timestamp\n", - "0 196 242 3.0 881250949\n", - "1 186 302 3.0 891717742\n", - "2 22 377 1.0 878887116\n", - "3 244 51 2.0 880606923\n", - "4 166 346 1.0 886397596" + " userID itemID rating timestamp\n", + "0 196 242 3.0 881250949\n", + "1 186 302 3.0 891717742\n", + "2 22 377 1.0 878887116\n", + "3 244 51 2.0 880606923\n", + "4 166 346 1.0 886397596" ] }, - "execution_count": 4, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -207,7 +211,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -224,7 +228,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -276,37 +280,73 @@ "\n", " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", + " \n", " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", "
UserIdMovieIdtargetuserIDitemIDrating
54315553.001048401.0
909455.018811122.0
27465063.0
29251531042574.0
30310921.0451115274.0
54979467633.0
64078693.0
72919244.0
8109944.0
9825973.0
" ], @@ -369,6 +409,33 @@ "execution_count": 10, "metadata": {}, "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "data": { "text/html": [ @@ -383,34 +450,34 @@ " \n", " \n", " \n", + " 0\n", + " 0.961789\n", + " None\n", + " 00:09\n", + " \n", + " \n", " 1\n", - " 0.985993\n", - " \n", - " 00:05\n", + " 0.863359\n", + " None\n", + " 00:08\n", " \n", " \n", " 2\n", - " 0.885496\n", - " \n", - " 00:05\n", + " 0.750853\n", + " None\n", + " 00:07\n", " \n", " \n", " 3\n", - " 0.777637\n", - " \n", - " 00:05\n", + " 0.637868\n", + " None\n", + " 00:08\n", " \n", " \n", " 4\n", - " 0.628971\n", - " \n", - " 00:05\n", - " \n", - " \n", - " 5\n", - " 0.532328\n", - " \n", - " 00:06\n", + " 0.526907\n", + " None\n", + " 00:09\n", " \n", " \n", "" @@ -426,7 +493,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Took 29.5549 seconds for training.\n" + "Took 51.5260 seconds for training.\n" ] } ], @@ -446,7 +513,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -456,7 +523,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -474,7 +541,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -490,7 +557,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -508,7 +575,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -525,7 +592,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -545,7 +612,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 17, "metadata": { "scrolled": false }, @@ -564,14 +631,14 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Took 1.9734 seconds for 1511060 predictions.\n" + "Took 5.1570 seconds for 1511060 predictions.\n" ] } ], @@ -595,7 +662,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -606,7 +673,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -617,7 +684,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -628,7 +695,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -639,27 +706,27 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Model:\tCollabLearner\n", - "Top K:\t10\n", - "MAP:\t0.026115\n", - "NDCG:\t0.155065\n", - "Precision@K:\t0.136691\n", - "Recall@K:\t0.054940\n" + "Model:\t\tLearner\n", + "Top K:\t\t10\n", + "MAP:\t\t0.024119\n", + "NDCG:\t\t0.152808\n", + "Precision@K:\t0.139130\n", + "Recall@K:\t0.054943\n" ] } ], "source": [ - "print(\"Model:\\t\" + learn.__class__.__name__,\n", - " \"Top K:\\t%d\" % TOP_K,\n", - " \"MAP:\\t%f\" % eval_map,\n", - " \"NDCG:\\t%f\" % eval_ndcg,\n", + "print(\"Model:\\t\\t\" + learn.__class__.__name__,\n", + " \"Top K:\\t\\t%d\" % TOP_K,\n", + " \"MAP:\\t\\t%f\" % eval_map,\n", + " \"NDCG:\\t\\t%f\" % eval_ndcg,\n", " \"Precision@K:\\t%f\" % eval_precision,\n", " \"Recall@K:\\t%f\" % eval_recall, sep='\\n')" ] @@ -673,7 +740,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ @@ -693,18 +760,18 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Model:\tCollabLearner\n", - "RMSE:\t0.902379\n", - "MAE:\t0.712163\n", - "Explained variance:\t0.346523\n", - "R squared:\t0.345672\n" + "Model:\t\t\tLearner\n", + "RMSE:\t\t\t0.904589\n", + "MAE:\t\t\t0.715827\n", + "Explained variance:\t0.356082\n", + "R squared:\t\t0.355173\n" ] } ], @@ -714,36 +781,35 @@ "eval_mae = mae(test_df, scores, col_user=USER, col_item=ITEM, col_rating=RATING, col_prediction=PREDICTION)\n", "eval_exp_var = exp_var(test_df, scores, col_user=USER, col_item=ITEM, col_rating=RATING, col_prediction=PREDICTION)\n", "\n", - "print(\"Model:\\t\" + learn.__class__.__name__,\n", - " \"RMSE:\\t%f\" % eval_rmse,\n", - " \"MAE:\\t%f\" % eval_mae,\n", + "print(\"Model:\\t\\t\\t\" + learn.__class__.__name__,\n", + " \"RMSE:\\t\\t\\t%f\" % eval_rmse,\n", + " \"MAE:\\t\\t\\t%f\" % eval_mae,\n", " \"Explained variance:\\t%f\" % eval_exp_var,\n", - " \"R squared:\\t%f\" % eval_r2, sep='\\n')" + " \"R squared:\\t\\t%f\" % eval_r2, sep='\\n')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "That RMSE is actually quite good when compared to these benchmarks: https://www.librec.net/release/v1.3/example.html" + "That RMSE is competitive in comparison with other models." ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 26, "metadata": {}, "outputs": [ { "data": { - "application/scrapbook.scrap.json+json": { - "data": 0.02611475567509659, + "application/notebook_utils.json+json": { + "data": 0.024118782738867094, "encoder": "json", - "name": "map", - "version": 1 + "name": "map" } }, "metadata": { - "scrapbook": { + "notebook_utils": { "data": true, "display": false, "name": "map" @@ -753,15 +819,14 @@ }, { "data": { - "application/scrapbook.scrap.json+json": { - "data": 0.15506533130248687, + "application/notebook_utils.json+json": { + "data": 0.1528081472533914, "encoder": "json", - "name": "ndcg", - "version": 1 + "name": "ndcg" } }, "metadata": { - "scrapbook": { + "notebook_utils": { "data": true, "display": false, "name": "ndcg" @@ -771,15 +836,14 @@ }, { "data": { - "application/scrapbook.scrap.json+json": { - "data": 0.13669141039236482, + "application/notebook_utils.json+json": { + "data": 0.13913043478260873, "encoder": "json", - "name": "precision", - "version": 1 + "name": "precision" } }, "metadata": { - "scrapbook": { + "notebook_utils": { "data": true, "display": false, "name": "precision" @@ -789,15 +853,14 @@ }, { "data": { - "application/scrapbook.scrap.json+json": { - "data": 0.05493986799753499, + "application/notebook_utils.json+json": { + "data": 0.05494302697544413, "encoder": "json", - "name": "recall", - "version": 1 + "name": "recall" } }, "metadata": { - "scrapbook": { + "notebook_utils": { "data": true, "display": false, "name": "recall" @@ -807,15 +870,14 @@ }, { "data": { - "application/scrapbook.scrap.json+json": { - "data": 0.9023793356156464, + "application/notebook_utils.json+json": { + "data": 0.9045892929999733, "encoder": "json", - "name": "rmse", - "version": 1 + "name": "rmse" } }, "metadata": { - "scrapbook": { + "notebook_utils": { "data": true, "display": false, "name": "rmse" @@ -825,15 +887,14 @@ }, { "data": { - "application/scrapbook.scrap.json+json": { - "data": 0.7121634655740025, + "application/notebook_utils.json+json": { + "data": 0.7158267242352735, "encoder": "json", - "name": "mae", - "version": 1 + "name": "mae" } }, "metadata": { - "scrapbook": { + "notebook_utils": { "data": true, "display": false, "name": "mae" @@ -843,15 +904,14 @@ }, { "data": { - "application/scrapbook.scrap.json+json": { - "data": 0.34652281723228295, + "application/notebook_utils.json+json": { + "data": 0.3560824305444269, "encoder": "json", - "name": "exp_var", - "version": 1 + "name": "exp_var" } }, "metadata": { - "scrapbook": { + "notebook_utils": { "data": true, "display": false, "name": "exp_var" @@ -861,15 +921,14 @@ }, { "data": { - "application/scrapbook.scrap.json+json": { - "data": 0.3456716162958503, + "application/notebook_utils.json+json": { + "data": 0.35517333876960555, "encoder": "json", - "name": "rsquared", - "version": 1 + "name": "rsquared" } }, "metadata": { - "scrapbook": { + "notebook_utils": { "data": true, "display": false, "name": "rsquared" @@ -879,15 +938,14 @@ }, { "data": { - "application/scrapbook.scrap.json+json": { - "data": 29.554921820759773, + "application/notebook_utils.json+json": { + "data": 51.52598460000445, "encoder": "json", - "name": "train_time", - "version": 1 + "name": "train_time" } }, "metadata": { - "scrapbook": { + "notebook_utils": { "data": true, "display": false, "name": "train_time" @@ -897,15 +955,14 @@ }, { "data": { - "application/scrapbook.scrap.json+json": { - "data": 1.973397959023714, + "application/notebook_utils.json+json": { + "data": 5.156951100005244, "encoder": "json", - "name": "test_time", - "version": 1 + "name": "test_time" } }, "metadata": { - "scrapbook": { + "notebook_utils": { "data": true, "display": false, "name": "test_time" @@ -930,7 +987,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -946,9 +1003,9 @@ "metadata": { "celltoolbar": "Tags", "kernelspec": { - "display_name": "Python (reco_gpu)", + "display_name": "recommenders", "language": "python", - "name": "reco_gpu" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -960,7 +1017,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.11" + "version": "3.9.16" } }, "nbformat": 4, diff --git a/recommenders/models/fastai/fastai_utils.py b/recommenders/models/fastai/fastai_utils.py index e5dc502aa..6e805ae17 100644 --- a/recommenders/models/fastai/fastai_utils.py +++ b/recommenders/models/fastai/fastai_utils.py @@ -78,7 +78,7 @@ def hide_fastai_progress_bar(): fastprogress.fastprogress.NO_BAR = True fastprogress.fastprogress.WRITER_FN = str master_bar, progress_bar = force_console_behavior() - fastai.basic_train.master_bar, fastai.basic_train.progress_bar = ( + fastai.callback.progress.master_bar, fastai.callback.progress.progress_bar = ( master_bar, progress_bar, )