N-Gram

n-gram とは?

n-gram はテキストドキュメント内の連続する n 個のアイテムの集合を意味します。これには単語、数字、記号、句読点などが含まれる可能性があります。n-gram モデルは感情分析、テキスト分類、テキスト生成など単語の配列が関係するテキスト解析アプリケーションの多くで役立ちます。例として、以下の文章を見てみましょう。

“Word clouds from string arrays and word clouds from bag-of-words models and LDA topics can be created using Text Analytics Toolbox.”

“Word clouds” は 2-gram (バイグラム)、“from string arrays” は 3-gram (トライグラム)、“using Text Analytics Toolbox” は 4-gram などのようになります。n-gram のサイズは、アプリケーションや、そのアプリケーションでよく使用されるフレーズのサイズによって異なります。

n-gram モデリングは、テキストを非構造化形式から構造化形式に変換する際に使用される多くの手法の中の一つです。n-gram の代替としては、word2vec などの単語埋め込み手法があります。n-gram を組み込んだ言語モデルは、一意の各 n-gram がドキュメント内に出現する回数を数えることで作成できます。これは bag-of-n-grams モデルとして知られています。上記の例では、n=2 の bag-of-n-grams モデルは以下のようになります。

A word cloud of n-grams where n = 2. This word cloud shows more prominent words in orange such as robot arm and construct agent, with a series of less prominent black words surrounding them decreasing in size.

Word cloud of n-grams with n=2 (bigrams).

n-gram 回数
Word clouds 2
String arrays 1
Bag-of-words models 1

言語モデルが構築されると、それを機械学習アルゴリズムと共に使用して、テキスト解析アプリケーション用の予測モデルを構築できます。n-gram やテキストデータを使用するモデルの構築に関しては、Text Analytics Toolbox™ で MATLAB® との使用について詳しくご紹介しています。

参考: natural language processing, sentiment analysis, word2vec, text mining with MATLAB, data science, deep learning, Deep Learning Toolbox™, Predictive Maintenance Toolbox™