<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# MNIST - Syft Duet - Data Owner 🎸"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PART 1: Launch a Duet Server and Connect\n",
    "\n",
    "As a Data Owner, you want to allow someone else to perform data science on data that you own and likely want to protect.\n",
    "\n",
    "In order to do this, we must load our data into a locally running server within this notebook. We call this server a \"Duet\".\n",
    "\n",
    "To begin, you must launch Duet and help your Duet \"partner\" (a Data Scientist) connect to this server.\n",
    "\n",
    "You do this by running the code below and sending the code snippet containing your unique Server ID to your partner and following the instructions it gives!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# TorchVision hotfix https://github.com/pytorch/vision/issues/3549\n",
    "from syft.util import get_root_data_path\n",
    "from torchvision import datasets\n",
    "datasets.MNIST.resources = [\n",
    "    (\n",
    "        \"https://ossci-datasets.s3.amazonaws.com/mnist/train-images-idx3-ubyte.gz\",\n",
    "        \"f68b3c2dcbeaaa9fbdd348bbdeb94873\",\n",
    "    ),\n",
    "    (\n",
    "        \"https://ossci-datasets.s3.amazonaws.com/mnist/train-labels-idx1-ubyte.gz\",\n",
    "        \"d53e105ee54ea40749a09fcbcd1e9432\",\n",
    "    ),\n",
    "    (\n",
    "        \"https://ossci-datasets.s3.amazonaws.com/mnist/t10k-images-idx3-ubyte.gz\",\n",
    "        \"9fb629c4189551a2d022fa330f9573f3\",\n",
    "    ),\n",
    "    (\n",
    "        \"https://ossci-datasets.s3.amazonaws.com/mnist/t10k-labels-idx1-ubyte.gz\",\n",
    "        \"ec29112dd5afa0611ce80d1b7f02629c\",\n",
    "    ),\n",
    "]\n",
    "datasets.MNIST(get_root_data_path(), train=True, download=True)\n",
    "datasets.MNIST(get_root_data_path(), train=False, download=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import syft as sy\n",
    "duet = sy.launch_duet(loopback=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you are in Jupyter Notebook (not Colab) the ☝🏾DUET LIVE STATUS above will animate "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PART 2: Add Request Handlers"
   ]
  },<commit_msg>Modifications<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# MNIST - Syft Duet - Data Owner 🎸"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PART 1: Launch a Duet Server and Connect\n",
    "\n",
    "As a Data Owner, you want to allow someone else to perform data science on data that you own and likely want to protect.\n",
    "\n",
    "In order to do this, we must load our data into a locally running server within this notebook. We call this server a \"Duet\".\n",
    "\n",
    "To begin, you must launch Duet and help your Duet \"partner\" (a Data Scientist) connect to this server.\n",
    "\n",
    "You do this by running the code below and sending the code snippet containing your unique Server ID to your partner and following the instructions it gives!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "ename": "ImportError",
     "evalue": "cannot import name 'get_root_data_path'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-5-2b1d077d5dc0>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m# TorchVision hotfix https://github.com/pytorch/vision/issues/3549\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0msyft\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0msyft\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mutil\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mget_root_data_path\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mtorchvision\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mdatasets\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m datasets.MNIST.resources = [\n",
      "\u001b[0;31mImportError\u001b[0m: cannot import name 'get_root_data_path'"
     ]
    }
   ],
   "source": [
    "# TorchVision hotfix https://github.com/pytorch/vision/issues/3549\n",
    "import syft\n",
    "from syft.util import get_root_data_path\n",
    "from torchvision import datasets\n",
    "datasets.MNIST.resources = [\n",
    "    (\n",
    "        \"https://ossci-datasets.s3.amazonaws.com/mnist/train-images-idx3-ubyte.gz\",\n",
    "        \"f68b3c2dcbeaaa9fbdd348bbdeb94873\",\n",
    "    ),\n",
    "    (\n",
    "        \"https://ossci-datasets.s3.amazonaws.com/mnist/train-labels-idx1-ubyte.gz\",\n",
    "        \"d53e105ee54ea40749a09fcbcd1e9432\",\n",
    "    ),\n",
    "    (\n",
    "        \"https://ossci-datasets.s3.amazonaws.com/mnist/t10k-images-idx3-ubyte.gz\",\n",
    "        \"9fb629c4189551a2d022fa330f9573f3\",\n",
    "    ),\n",
    "    (\n",
    "        \"https://ossci-datasets.s3.amazonaws.com/mnist/t10k-labels-idx1-ubyte.gz\",\n",
    "        \"ec29112dd5afa0611ce80d1b7f02629c\",\n",
    "    ),\n",
    "]\n",
    "datasets.MNIST(get_root_data_path(), train=True, download=True)\n",
    "datasets.MNIST(get_root_data_path(), train=False, download=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'syft.util' has no attribute 'get_root_data_path'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-6-cd16e0ebded4>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msyft\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mutil\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_root_data_path\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m: module 'syft.util' has no attribute 'get_root_data_path'"
     ]
    }
   ],
   "source": [
    "\n",
    "syft.util.get_root_data_path()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import syft as sy\n",
    "duet = sy.launch_duet(loopback=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you are in Jupyter Notebook (not Colab) the ☝🏾DUET LIVE STATUS above will animate "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PART 2: Add Request Handlers"
   ]
  },
{'fraction_non_alphanumeric': 0.19978689397975494, 'fraction_numerical': 0.09389984017048482, 'mean_word_length': 2.6380813953488373, 'pattern_counts': {'":': 59, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 11, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1452652', 'n_tokens_mistral': 3505, 'n_tokens_neox': 3123, 'n_words': 500}