プリンキピア

第9章リカレントニューラルネットワーク

9.2.1. Reading the Dataset9.2.1 データセットを読み込む

Here, we will work with H. G. Wells’ The Time Machine, a book containing just over 30,000 words. While real applications will typically involve significantly larger datasets, this is sufficient to demonstrate the preprocessing pipeline. The following _download method reads the raw text into a string.
英語のヒント
ここでは、3万語をわずかに超える本である、H. G. ウェルズの『タイム・マシン』を扱う。実際の応用ではふつうずっと大きなデータセットを扱うが、前処理のパイプラインを示すにはこれで十分である。次の_downloadメソッドは、生のテキストを文字列に読み込む。
class TimeMachine(d2l.DataModule): #@save
    """The Time Machine dataset."""
    def _download(self):
        fname = d2l.download(d2l.DATA_URL + 'timemachine.txt', self.root,
                             '090b5e7e70c295757f55df93cb0a180b9691891a')
        with open(fname) as f:
            return f.read()

data = TimeMachine()
raw_text = data._download()
raw_text[:60]
'The Time Machine, by H. G. Wells [1898]nnnnnInnnThe Time Tra'
For simplicity, we ignore punctuation and capitalization when preprocessing the raw text.
英語のヒント
簡単にするため、生のテキストを前処理するときには句読点と大文字・小文字の区別を無視する。
@d2l.add_to_class(TimeMachine)  #@save
def _preprocess(self, text):
    return re.sub('[^A-Za-z]+', ' ', text).lower()

text = data._preprocess(raw_text)
text[:60]
'the time machine by h g wells i the time traveller for so it'