bert icon indicating copy to clipboard operation
bert copied to clipboard

The problem of tokenizer

Open dddzg opened this issue 8 years ago • 4 comments

https://github.com/google-research/bert/blob/35deae77e6b6c668cc8050853d16b4046193cbf0/tokenization.py#L249

The class WordpieceTokenizer show the case that

For example:
  input = "unaffable"
  output = ["un", "##aff", "##able"]

However when we use the greedy longest-match-first algorithm the input "unaffable" by the vocab.txt(from the official file uncased_L-12_H-768_A-12.zip),we actually get the output ["una","##ffa","##ble"]. I read the vocab.txt find that there is the vocab una which is longer than the vocab un.So,it leads to the problem which is different from our expectations. is it the given vocab problem or the defects of the algorithm?

dddzg avatar Nov 13 '18 12:11 dddzg

Besides, the word ##aff is also not in the vocab.txt. now, I am curious about how to generate the vocab.txt?

dddzg avatar Nov 13 '18 13:11 dddzg

It's just an example. The exact way that "unaffable" would actually be tokenized depends on the exact vocabulary. See this section about the vocabulary.

jacobdevlin-google avatar Nov 14 '18 17:11 jacobdevlin-google

I know it.However,can I think that the given vocabulary is not good enough? we think that output ["un", "##aff", "##able"] is much better?

dddzg avatar Nov 14 '18 18:11 dddzg

I think, there's still the problem.

My string was , tokenizer.tokenize("lighspots mood! keyhole thread bodysuit sleeved sparkly taupe heeled skirt!")

However, the vocab file contains the word "light" in given vocab.txt file, yet the output wa ['li', '##gh', '##sp', '##ots', 'mood', '!', 'key', '##hole', 'thread', 'body', '##suit', 'sleeve', '##d', 'spark', '##ly', 'tau', '##pe', 'heel', '##ed', 'skirt', '!']

why not, ['light', '##sp', '##ots', 'mood', '!', 'key', '##hole', 'thread', 'body', '##suit', 'sleeve', '##d', 'spark', '##ly', 'tau', '##pe', 'heel', '##ed', 'skirt', '!']

PS: However, this is a bit controversial, because in some case the shorter char words are what users want, so is the based on given first priority.

jageshmaharjan avatar Nov 15 '19 07:11 jageshmaharjan