zoukankan      html  css  js  c++  java
  • bert中的分词

    直接把自己的工作文档导入的,由于是在外企工作,所以都是英文写的

    chinese and english tokens result

       

    input: "我爱中国"tokens:["","","",""]

    input: "I love china habih", tokens:["I","love","china","ha","##bi","##h"] (here "##bi","##h" are all in vocabulary)

       

    Implementation

    chinese and english text would call two tokens,one is basic_tokenizer and other one is wordpiece_tokenizer as you can see from the the code below.

       

    basic_tokenizer

    if the input is chinese, the _tokenize_chinese_chars would add whitespace between chinese charater, and then call whitespace_tokenizer which separate text with whitespace,so

    if the input is the query "我爱中国"would return ["","","",""]if the input is the english query "I love china", would return ["I","love","china"]

       

       

    wordpiece_tokenizer

    if the input is chinese ,if would iterate tokens from basic_tokenizer result, if the character is in vocabulary, just keep the same character ,otherwise append unk_token.

    if the input is english, we would iterate over one word ,for example: the word is "shabi", while it is not in vocabulary,so the end index would rollback until it found "sh" in vocabulary,

    in the following process, once it found a substr in vocabulary ,it would append "##" then append it to output tokens, so we can get ["sh","##ab","##i"] finally.

       

     

     

    #65 How are out of vocabulary words handled for Chinese?

    The top 8000 characters are character-tokenized, other characters are mapped to [UNK]. I should've commented this section better but it's here

    Basically that's saying if it tries to apply WordPiece tokenization (the character tokenization happens previously), and it gets to a single character that it can't find, it maps it to unk_token.

     

    #62 Why Chinese vocab contains ##word?

    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.

  • 相关阅读:
    玩游戏 学Flex布局
    解决:父级元素不能被子元素内容撑开的解决办法,父级元素没有高度的解决办法
    Flex 项目属性:flex 布局示例
    display: flex; 布局
    box-sizing 的作用
    <a>标签里面直接嵌套图片,<img>下面出现一小段空白的原因
    ucore操作系统实验学习笔记2
    ucore 操作系统学习笔记1 -- 环境搭建
    LeetCode题解之 Assign Cookies
    LeetCode题解之Lemonade Change
  • 原文地址:https://www.cnblogs.com/wuxiangli/p/10433147.html
Copyright © 2011-2022 走看看