Can we improve the classification accuracy by using the spaCy tokenization? You need to install spaCy (pip install spacy) and install the English package (python -m spacy download en). In the code, first, import spaCy (import spacy). Then, load the spaCy English package (spacy_en = spacy.load('en')). Finally, define the function def tokenizer(text): return [tok.text for tok in spacy_en.tokenizer(text)] and replace the original tokenizer function. Note the different forms of phrase tokens in GloVe and spaCy. For example, the phrase token “new york” takes the form of “new-york” in GloVe and the form of “new york” after the spaCy tokenization.
英語のヒント
spaCyのトークン化を使うと、分類の正解率を改善できるか。spaCyをインストールし(pip install spacy)、英語のパッケージをインストールする(python -m spacy download en)必要がある。コードでは、まずspaCyをインポートする(import spacy)。それから、spaCyの英語のパッケージを読み込む(spacy_en = spacy.load('en'))。最後に、関数def tokenizer(text): return [tok.text for tok in spacy_en.tokenizer(text)]を定義して、元のtokenizer関数を置き換える。GloVeとspaCyでは句のトークンの形が異なることに注意しよう。たとえば、句のトークン「new york」は、GloVeでは「new-york」の形をとり、spaCyのトークン化の後では「new york」の形をとる。