プリンキピア

第23章付録:深層学習のための道具

23.1.1. Editing and Running the Code Locally23.1.1 ローカルでコードを編集して実行する

Suppose that the local path of the book’s code is xx/yy/d2l-en/. Use the shell to change the directory to this path (cd xx/yy/d2l-en) and run the command jupyter notebook. If your browser does not do this automatically, open http://localhost:8888 and you will see the interface of Jupyter and all the folders containing the code of the book, as shown in Fig. 23.1.1.
英語のヒント
本書のコードのローカルのパスがxx/yy/d2l-en/だとする。シェルを使ってこのパスにディレクトリを移動し(cd xx/yy/d2l-en)、コマンドjupyter notebookを実行する。ブラウザがこれを自動的に行わない場合は、http://localhost:8888を開くと、図23.1.1に示すように、Jupyterの画面と本書のコードを含むすべてのフォルダが見える。
Fig. 23.1.1図23.1.1
The folders containing the code of this book.
英語のヒント
本書のコードを含むフォルダ。
You can access the notebook files by clicking on the folder displayed on the webpage. They usually have the suffix “.ipynb”. For the sake of brevity, we create a temporary “test.ipynb” file. The content displayed after you click it is shown in Fig. 23.1.2. This notebook includes a markdown cell and a code cell. The content in the markdown cell includes “This Is a Title” and “This is text.”. The code cell contains two lines of Python code.
英語のヒント
ウェブページに表示されたフォルダをクリックすると、ノートブックのファイルにアクセスできる。それらはふつう拡張子「.ipynb」をもつ。簡単にするため、一時的な「test.ipynb」ファイルを作る。それをクリックした後に表示される内容を図23.1.2に示す。このノートブックには、Markdownのセルとコードのセルが一つずつ含まれている。Markdownのセルの内容には「This Is a Title」と「This is text.」が含まれる。コードのセルには2行のPythonのコードが含まれている。
Fig. 23.1.2図23.1.2
Markdown and code cells in the “text.ipynb” file.
英語のヒント
「text.ipynb」ファイルの中のMarkdownのセルとコードのセル。
Double click on the markdown cell to enter edit mode. Add a new text string “Hello world.” at the end of the cell, as shown in Fig. 23.1.3.
英語のヒント
Markdownのセルをダブルクリックして編集モードに入る。図23.1.3に示すように、セルの末尾に新しいテキスト文字列「Hello world.」を加える。
Fig. 23.1.3図23.1.3
Edit the markdown cell.
英語のヒント
Markdownのセルを編集する。
As demonstrated in Fig. 23.1.4, click “Cell” → “Run Cells” in the menu bar to run the edited cell.
英語のヒント
図23.1.4に示すように、メニューバーで「Cell」→「Run Cells」をクリックして、編集したセルを実行する。
Fig. 23.1.4図23.1.4
Run the cell.
英語のヒント
セルを実行する。
After running, the markdown cell is shown in Fig. 23.1.5.
英語のヒント
実行した後のMarkdownのセルを図23.1.5に示す。
Fig. 23.1.5図23.1.5
The markdown cell after running.
英語のヒント
実行した後のMarkdownのセル。
Next, click on the code cell. Multiply the elements by 2 after the last line of code, as shown in Fig. 23.1.6.
英語のヒント
次に、コードのセルをクリックする。図23.1.6に示すように、コードの最後の行の後で、要素に2を掛ける。
Fig. 23.1.6図23.1.6
Edit the code cell.
英語のヒント
コードのセルを編集する。
You can also run the cell with a shortcut (“Ctrl + Enter” by default) and obtain the output result from Fig. 23.1.7.
英語のヒント
ショートカット(既定では「Ctrl + Enter」)でセルを実行し、図23.1.7の出力結果を得ることもできる。
Fig. 23.1.7図23.1.7
Run the code cell to obtain the output.
英語のヒント
コードのセルを実行して出力を得る。
When a notebook contains more cells, we can click “Kernel” → “Restart & Run All” in the menu bar to run all the cells in the entire notebook. By clicking “Help” → “Edit Keyboard Shortcuts” in the menu bar, you can edit the shortcuts according to your preferences.
英語のヒント
ノートブックにもっと多くのセルが含まれているときは、メニューバーで「Kernel」→「Restart & Run All」をクリックすれば、ノートブック全体のすべてのセルを実行できる。メニューバーで「Help」→「Edit Keyboard Shortcuts」をクリックすれば、好みに合わせてショートカットを編集できる。