LoginSignup
23
9

More than 5 years have passed since last update.

BERTのmultilingual modelにおける日本語の扱い

Last updated at Posted at 2018-11-06

2019/1/20 追記

日本語wikipediaで学習させたモデルを公開してくださった方がいます。
まだ手元では試していませんが、multilingual modelを使用するより良さそうです。
ありがたいですね!


102言語を1つのネットワークで学習したBERT multilingual modelが公開された。その対応言語リストにJapaneseが含まれているものの、単語区切りなどどのように学習されているのか疑問だったので調べてみた。

Tokenization

For tokenization, we use a 110k shared WordPiece vocabulary. The word counts are weighted the same way as the data, so low-resource languages are upweighted by some factor. We intentionally do not use any marker to denote the input language (so that zero-shot training can work).
Because Chinese does not have whitespace characters, we add spaces around every character in the CJK Unicode range before applying WordPiece.

ということなので、日本語の漢字も全て前後に区切り文字としてのスペースを加えた上でWordPieceの解析にかけられる。なお、unicode上ではChina, Japan, Koreaの漢字が分けられずに混ざって並んでいるので、CJK Unicode rangeでは全ての漢字が含まれることになる。

さて、'a 110k shared WordPiece vocabulary'の中に日本語のwordpieceがどのくらい含まれているのかを見る。multilingual modelのvocab.txtを確認すると、全ての漢字は1文字ずつ区切られていて、二文字以上のいわゆる熟語は存在しなかった。

二文字以上のwordpieceは約1000語であった。概ね2−3文字のものが多いが、なかには「なけれはならない」や「になっている」、「となっていた」などのやや長めのwordpieceも含まれていた。##つきのものと、##なしのものが半々くらい。

漢字一文字のwordpieceにも##が付いているのがやや解せないが、「になる」とか、「である」とか明らかにspace区切りの始まりにない語彙に##がついていないので、やはり先に漢字の回りにspaceを足して区切ってからwordpieceの解析にかけたのだろうか。。このwordpieceのvocabularyを作る部分はコードに載っていないのでよく分からない。

いずれにせよ、BERT multilingual modelを日本語に使うときは、上記のようなtokenizationが行われていることを認識しておいたほうがよさそう。

23
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
9