プリンキピア

第15章自然言語処理:事前学習

15.9.4. Exercises15.9.4 練習問題

  1. For simplicity, the period is used as the only delimiter for splitting sentences. Try other sentence splitting techniques, such as the spaCy and NLTK. Take NLTK as an example. You need to install NLTK first: pip install nltk. In the code, first import nltk. Then, download the Punkt sentence tokenizer: nltk.download('punkt'). To split sentences such as sentences = 'This is great ! Why not ?', invoking nltk.tokenize.sent_tokenize(sentences) will return a list of two sentence strings: ['This is great !', 'Why not ?'].
    英語のヒント
    簡単にするため、文を分割する区切りとしてピリオドだけを使った。spaCyやNLTKのような、ほかの文分割の技法を試せ。NLTKを例にとろう。まず、pip install nltkでNLTKをインストールする必要がある。コードでは、まずimport nltkとする。それから、nltk.download('punkt')でPunktの文トークナイザをダウンロードする。sentences = 'This is great ! Why not ?'のような文を分割するには、nltk.tokenize.sent_tokenize(sentences)を呼び出すと、二つの文字列のリスト['This is great !', 'Why not ?']が返る。
  2. What is the vocabulary size if we do not filter out any infrequent token?
    英語のヒント
    まれなトークンを一つも取り除かないと、語彙の大きさはどうなるか。