第23章付録:深層学習のための道具
23.1.2. Advanced Options23.1.2 高度なオプション
Beyond local editing two things are quite important: editing the notebooks in the markdown format and running Jupyter remotely. The latter matters when we want to run the code on a faster server. The former matters since Jupyter’s native ipynb format stores a lot of auxiliary data that is irrelevant to the content, mostly related to how and where the code is run. This is confusing for Git, making reviewing contributions very difficult. Fortunately there is an alternative—native editing in the markdown format.
英語のヒント
ローカルでの編集のほかに、とても重要なことが二つある。ノートブックをMarkdown形式で編集することと、Jupyterをリモートで実行することである。後者は、もっと速いサーバでコードを実行したいときに重要になる。前者が重要なのは、Jupyterのネイティブなipynb形式が、内容とは関係のない補助的なデータを多く保存するからである。その多くは、コードをどう、どこで実行したかに関係する。これはGitにとって紛らわしく、貢献をレビューするのをとても難しくする。幸い、別の方法、つまりMarkdown形式でのネイティブな編集がある。
23.1.2.1. Markdown Files in Jupyter23.1.2.1 JupyterでのMarkdownファイル
If you wish to contribute to the content of this book, you need to modify the source file (md file, not ipynb file) on GitHub. Using the notedown plugin we can modify notebooks in the md format directly in Jupyter.
英語のヒント
本書の内容に貢献したいなら、GitHub上のソースファイル(ipynbファイルではなくmdファイル)を修正する必要がある。notedownプラグインを使えば、md形式のノートブックをJupyterで直接修正できる。
First, install the notedown plugin, run the Jupyter Notebook, and load the plugin:
英語のヒント
まず、notedownプラグインをインストールし、Jupyter Notebookを実行して、プラグインを読み込む。
pip install d2l-notedown # You may need to uninstall the original notedown.
jupyter notebook --NotebookApp.contents_manager_class='notedown.NotedownContentsManager'You may also turn on the notedown plugin by default whenever you run the Jupyter Notebook. First, generate a Jupyter Notebook configuration file (if it has already been generated, you can skip this step).
英語のヒント
Jupyter Notebookを実行するたびに、既定でnotedownプラグインを有効にすることもできる。まず、Jupyter Notebookの設定ファイルを生成する(すでに生成されているなら、この手順は飛ばしてよい)。
jupyter notebook --generate-configThen, add the following line to the end of the Jupyter Notebook configuration file (for Linux or macOS, usually in the path
~/.jupyter/jupyter_notebook_config.py):英語のヒント
それから、Jupyter Notebookの設定ファイル(LinuxやmacOSでは、ふつうパス
~/.jupyter/jupyter_notebook_config.pyにある)の末尾に次の行を加える。c.NotebookApp.contents_manager_class = 'notedown.NotedownContentsManager'After that, you only need to run the
jupyter notebook command to turn on the notedown plugin by default.英語のヒント
その後は、コマンド
jupyter notebookを実行するだけで、既定でnotedownプラグインが有効になる。23.1.2.2. Running Jupyter Notebooks on a Remote Server23.1.2.2 リモートサーバでJupyterノートブックを実行する
Sometimes, you may want to run Jupyter notebooks on a remote server and access it through a browser on your local computer. If Linux or macOS is installed on your local machine (Windows can also support this function through third-party software such as PuTTY), you can use port forwarding:
英語のヒント
リモートサーバでJupyterノートブックを実行し、ローカルのコンピュータのブラウザからそれにアクセスしたいことがある。ローカルのマシンにLinuxかmacOSが入っているなら(WindowsもPuTTYのようなサードパーティのソフトウェアでこの機能をサポートできる)、ポートフォワーディングを使える。
ssh myserver -L 8888:localhost:8888The above string
myserver is the address of the remote server. Then we can use http://localhost:8888 to access the remote server myserver that runs Jupyter notebooks. We will detail on how to run Jupyter notebooks on AWS instances later in this appendix.英語のヒント
上の文字列
myserverは、リモートサーバのアドレスである。それから、http://localhost:8888を使って、Jupyterノートブックを実行しているリモートサーバmyserverにアクセスできる。AWSのインスタンスでJupyterノートブックを実行する方法は、この付録の後のほうで詳しく述べる。23.1.2.3. Timing23.1.2.3 時間計測
We can use the
ExecuteTime plugin to time the execution of each code cell in Jupyter notebooks. Use the following commands to install the plugin:英語のヒント
ExecuteTimeプラグインを使うと、Jupyterノートブックの各コードセルの実行時間を計れる。次のコマンドを使って、プラグインをインストールする。pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
jupyter nbextension enable execute_time/ExecuteTime