Bert中文vocab ##的作用

This is the character used to denote WordPieces, it’s just an artifact of the WordPiece vocabulary generator that we use, but most of those words were never actually used during training (for Chinese). So you can just ignore those tokens. Note that for the English characters that appear in Chinese text they are actually used.
– by jacobdevlin-google

    bert包括三个tokenizer:FullTokenizer,BasicTokenizer,WordpieceTokenizer,其中FullTokenizer就是调用后面两个
1.1. BasicTokenizer
主要步骤如下:
清理特殊字符:去除控制符以及替换空白字符为空格,这个地方需要注意,一些序列标注任务输入需要保持输入长度不变,否则标注无法对上,一般要么使用BasicTokenizer把原数据过一遍,再把标注对上,要么使用list方法代替bert的tokenizer
中文分割:将中文每个汉字单独作为一个token
小写:可选,如果小写,还会对字符做做NFD标准化
标点符号分割:除中文汉字外,其它字符通过标点符号分割开
1.2. WordpieceTokenizer
主要步骤如下:
对输入进行split,得到token列表
如果token的一部分在vocab中存在,就将token继续分割,分割后,除开第一部分,其它部分都会加上##,这就是wordpiece,例如visiable分割为:‘vi’, ‘##sia’, ‘##ble’,这个主要针对英文,但是在中文的全词mask,会利用这个特点,把一个词分割开,如“图书馆”分割为:图,#书,#馆
1.3. FullTokenizer
主要步骤如下:
调用BasicTokenizer得到初步的token列表
对于token再分别调用WordpieceTokenizer,产生更细的token

你可能感兴趣的:(深度学习,pytorch,自然语言处理)