{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"dockerImageVersionId":28755,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# [MNIST digit recognizer](https://www.kaggle.com/competitions/digit-recognizer/) with [TabPFN-3](https://arxiv.org/pdf/2605.13986) from [Prior Labs](https://priorlabs.ai/)\nWritten by **[Carl McBride Ellis](https://www.kaggle.com/carlmcbrideellis)** ([LinkedIn](https://www.linkedin.com/in/carl-mcbride-ellis/))\n\nThe [MNIST database of handwritten digits](http://yann.lecun.com/exdb/mnist/) consists of images that are 28 pixels in height and 28 pixels in width, for a total of 784 pixels in total, each image representing a digit from zero through nine.\nThis is a multiclass classification task and, although ostensibly a computer vision exercise and often solved using neural networks, it can also be treated as simply a dataset consisting of 784 features. To use [TabPFN-3](https://arxiv.org/pdf/2605.13986) we shall add the [TabPFN-3 model](https://www.kaggle.com/models/prior-labsai/tabpfn-3/), which is available on Kaggle (you will first need to visit the [Kaggle model page and accept the license](https://www.kaggle.com/models/prior-labsai/tabpfn-3/), then add the model to the notebook via the **Input** section). We shall also make use of the 2xT4 GPU's.","metadata":{}},{"cell_type":"code","source":"!uv pip install -q tabpfn\n\nimport os\nos.environ[\"TABPFN_MODEL_CACHE_DIR\"] = \"/kaggle/input/models/prior-labsai/tabpfn-3/pytorch/default/1\"","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-07-07T10:17:29.570732Z","iopub.execute_input":"2026-07-07T10:17:29.571009Z","iopub.status.idle":"2026-07-07T10:17:31.708631Z","shell.execute_reply.started":"2026-07-07T10:17:29.570960Z","shell.execute_reply":"2026-07-07T10:17:31.707725Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\n\nX_train = pd.read_csv('/kaggle/input/competitions/digit-recognizer/train.csv')\ny_train = X_train.pop(\"label\")\n\nfrom tabpfn import TabPFNClassifier\n\n# using Session options: GPU T4x2\nclassifier = TabPFNClassifier( device=[\"cuda:0\", \"cuda:1\"] )\n\nclassifier.fit(X_train, y_train)\n\nX_test = pd.read_csv('/kaggle/input/competitions/digit-recognizer/test.csv')\n\ny_pred = classifier.predict(X_test)\n\nsample = pd.read_csv('/kaggle/input/competitions/digit-recognizer/sample_submission.csv')\n\nsample[\"Label\"] = y_pred\nsample.to_csv('submission.csv',index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-07T10:17:31.710446Z","iopub.execute_input":"2026-07-07T10:17:31.710778Z","iopub.status.idle":"2026-07-07T10:19:39.420818Z","shell.execute_reply.started":"2026-07-07T10:17:31.710749Z","shell.execute_reply":"2026-07-07T10:19:39.419673Z"}},"outputs":[],"execution_count":null}]}