|
| 1 | +Using Tutorial Data from Google Drive in Colab |
| 2 | +============================================== |
| 3 | + |
| 4 | +We've added a new feature to tutorials that allows users to open the |
| 5 | +notebook associated with a tutorial in Google Colab. You may need to |
| 6 | +copy data to your Google drive account to get the more complex tutorials |
| 7 | +to work. |
| 8 | + |
| 9 | +In this example, we'll demonstrate how to change the notebook in Colab |
| 10 | +to work with the Chatbot Tutorial. To do this, you'll first need to be |
| 11 | +logged into Google Drive. (For a full description of how to access data |
| 12 | +in Colab, you can view their example notebook |
| 13 | +`here <https://colab.research.google.com/notebooks/io.ipynb#scrollTo=XDg9OBaYqRMd>`__.) |
| 14 | + |
| 15 | +To get started open the `Chatbot |
| 16 | +Tutorial <https://pytorch.org/tutorials/beginner/chatbot_tutorial.html>`__ |
| 17 | +in your browser. |
| 18 | + |
| 19 | +At the top of the page click **Run in Google Colab**. |
| 20 | + |
| 21 | +The file will open in Colab. |
| 22 | + |
| 23 | +If you choose, **Runtime** then **Run All**, you'll get an error as the |
| 24 | +file can't be found. |
| 25 | + |
| 26 | +To fix this, we'll copy the required file into our Google Drive account. |
| 27 | + |
| 28 | +1. Log into Google Drive. |
| 29 | +2. In Google Drive, make a folder named **data**, with a subfolder named |
| 30 | + **cornell**. |
| 31 | +3. Visit the Cornell Movie Dialogs Corpus and download the ZIP file. |
| 32 | +4. Unzip the file on your local machine. |
| 33 | +5. Copy the file **movie\_lines.txt** to **data/cornell** folder you |
| 34 | + created in Google Drive. |
| 35 | + |
| 36 | +Now we'll need to edit the file in\_ \_Colab to point to the file on |
| 37 | +Google Drive. |
| 38 | + |
| 39 | +In Colab, add the following to top of the code section over the line |
| 40 | +that begins *corpus\_name*: |
| 41 | + |
| 42 | +:: |
| 43 | + |
| 44 | + from google.colab import drive |
| 45 | + drive.mount('/content/gdrive') |
| 46 | + |
| 47 | +Change the two lines that follow: |
| 48 | + |
| 49 | +1. Change the **corpus\_name** value to **"cornell"**. |
| 50 | +2. Change the line that begins with **corpus** to this: |
| 51 | + |
| 52 | +:: |
| 53 | + |
| 54 | + corpus = os.path.join("/content/gdrive/My Drive/data", corpus_name) |
| 55 | + |
| 56 | +We're now pointing to the file we uploaded to Drive. |
| 57 | + |
| 58 | +Now when you click on the **Run cell** button for the code section, |
| 59 | +you'll be prompted to authorize Google Drive and you'll get an |
| 60 | +authorization code. Paste the code into the prompt in Colab and you |
| 61 | +should be set. |
| 62 | + |
| 63 | +Rerun the notebook from **Runtime** / **Run All** menu command and |
| 64 | +you'll see it process. (Note that this tutorial takes a long time to |
| 65 | +run.) |
| 66 | + |
| 67 | +Hopefully this example will give you a good starting point for running |
| 68 | +some of the more complex tutorials in Colab. As we evolve our use of |
| 69 | +Colab on the PyTorch tutorials site, we'll look at ways to make this |
| 70 | +easier for users. |
0 commit comments