Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4682f19

Browse files
committed
Adding information about running tutorials in Colab.
1 parent 49cc4c2 commit 4682f19

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

beginner_source/colab.rst

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.

index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ starting point, and provides a broad view into how to use PyTorch from the basic
77

88
Some considerations:
99

10+
* We’ve added a new feature to tutorials that allows users to open the notebook associated with a tutorial in Google Colab.
11+
Visit `this page </beginner/colab.html>`_ for more information.
1012
* If you would like to do the tutorials interactively via IPython / Jupyter,
1113
each tutorial has a download link for a Jupyter Notebook and Python source code.
1214
* Additional high-quality examples are available, including image classification,

0 commit comments

Comments
 (0)