RNN-LSTM example using Colab service
Schematic of colab.com service in this example
Fig.1 overall process of colab.com service in this example
Fig.1 shows the overall process of colab.com service in this example.
Example
The document below demonstrates how to upload files in PC, project in GitHub and execute Python code in Colab.
Step 0. Download .tgz file then unzip
Download the "simple-examples.tgz" zip file from the linkhttp://www.fit.vutbr.cz/~imikolov/rnnlm/simple-examples.tgz, then unzip this .tgz file
After unzipping the package, "ptb.train.txt", "ptb.test.txt", "ptb.valid.txt" files are in the path "simple-examples/data".
These files ("ptb.train.txt", "ptb.test.txt", "ptb.valid.txt") should be uploaded to Colab.
Step 1. Upload files from PC
Type the following commanding codes to upload these files
from google.colab import files
uploaded=files.upload()
Fig.3 upload files from PC to Colab
Fig.3 shows upload files from PC to Colab using the libraryfiles
ingoogle.colab
, then upload files by clicking "選擇檔案" button。
"google" is a library, and "colab" is a class in "google" libray. "files" is a function.
The "files" function is imported from "colab" class in "google" library through
from google.colab import files
uploaded is list of file information.
uploaded.keys() is a list of uploaded file's name.
uploaded[fn] is content of the file named fn.
The file's name and its corresponding size can be print with the commanding codes
for fn in uploaded.keys():
print()'User uploaded file"{name}" with length {length} bytes'.format(name=fn, length=len(uploaded[fn]) ))
Note that the above commanding codes is not a must for executing this project.
Step 2. Clone project from GitHub to Colab
Clone project from GitHub to Colab using!git clone https://github.com/tensorflow/models.git
commanding code.
Fig.2 clone project from GitHub to Colab
Fig.2 shows the commanding code!git clone https://github.com/tensorflow/models.git
and its corresponding response.
Step 3. Execute .py file
The project should be executed under project directory (project folder).
The project directory can be changed by usingcd
command. ("cd" refers to change directory).
Fig.4 change to the project directory
Fig.4 shows commanding codescd models/tutorials/rnn/ptb
and its corresponding responses.
Files and folders can be printed using!ls
command.
Fig.5 check which files and folder in this path
Fig.5 shows how to list all files and folders in current directory.
The file "ptb_word_lm.py" is executed using!python
command, as
!python ptb_word_lm.py --data_path=. --model=small
where--data_path
and--model
are parameters.
Fig.6 execute the .py file
Fig.6 shows executing the .py file using!python
command.
Execution Response
Fig.7 execution response
Fig.7 shows the execution response from Colab to the browser.
The train, valid and test perplexity are 40.446, 119.482 and 114.146, respectively.
perplexity n. 困惑
Reference
[0] Recurrent Neural Network
https://www.tensorflow.org/tutorials/recurrent
(暫時刪除)
Fig.1 schematic of colab.com service
Fig.1 shows the relationship between Colab, PC and GitHub. Colab.com is the service for GPU machine learning. PC is the computer operare Colab by command. And a project using Python language stored in GitHub.