<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 PTB (Penn Tree Bank) dataset introduction
Official page
Step1:  Download PTB dataset
chainer.datasets.get_ptb_words method is prepared in Chainer to get PTB dataset.
Dataset is automatically downloaded from https
Step2:  The dataset structure is numpy.ndarray.
train[i] represents i-th word in integer, which represents word ID.
Step3:  Word ID and word correspondence
Each word ID corresponds to specific word or symbol.
Symbol includes following 
 - &lt;eos&gt; 
Step4:  Convert to word sequences
Check original sentense by converting back word ID to word using ptb dictionary.
Train text
It is same with https
Step5:  Validation data text
It is same with https
Step6:  Test data text
It is same with https
<ASSISTANT_TASK:>
Python Code:
from __future__ import print_function
import os
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
import chainer
Explanation: PTB (Penn Tree Bank) dataset introduction
Official page: Treebank-3
In Chainer, PTB dataset can be obtained with build-in function.
End of explanation
train, val, test = chainer.datasets.get_ptb_words()
Explanation: Download PTB dataset
chainer.datasets.get_ptb_words method is prepared in Chainer to get PTB dataset.
Dataset is automatically downloaded from https://github.com/tomsercu/lstm/tree/master/data only for the first time, and its cache is used from second time.
End of explanation
print('train type: ', type(train), train.shape, train)
print('val   type: ', type(val), val.shape, val)
print('test  type: ', type(test), test.shape, test)
Explanation: The dataset structure is numpy.ndarray.
train[i] represents i-th word in integer, which represents word ID.
End of explanation
ptb_dict = chainer.datasets.get_ptb_words_vocabulary()
print('Number of vocabulary', len(ptb_dict))
print('ptb_dict', ptb_dict)
Explanation: Word ID and word correspondence
Each word ID corresponds to specific word or symbol.
Symbol includes following 
 - &lt;eos&gt; : end of sequence
 - &lt;unk&gt; : unknown word (I guess it is the word which was not in the 10000 vocabulary).
The relation between word ID and actual word can be obtained as dictionary with chainer.datasets.get_ptb_words_vocabulary() method.
End of explanation
ptb_word_id_dict = ptb_dict
ptb_id_word_dict = dict((v, k) for k, v in ptb_word_id_dict.items())
print([ptb_id_word_dict[i] for i in train[:30]])
# ' '.join(text_list) will convert list representation more readable
' '.join([ptb_id_word_dict[i] for i in train[:300]])
Explanation: Convert to word sequences
Check original sentense by converting back word ID to word using ptb dictionary.
Train text
It is same with https://raw.githubusercontent.com/tomsercu/lstm/master/data/ptb.train.txt
End of explanation
print(' '.join([ptb_id_word_dict[i] for i in val[:300]]))
Explanation: Validation data text
It is same with https://raw.githubusercontent.com/tomsercu/lstm/master/data/ptb.valid.txt
End of explanation
print(' '.join([ptb_id_word_dict[i] for i in test[:300]]))
Explanation: Test data text
It is same with https://raw.githubusercontent.com/tomsercu/lstm/master/data/ptb.test.txt
End of explanation
<END_TASK>