Closed jwijffels closed 4 years ago
I do have the original SentencePiece model, but I am not sure how useful it would be for your project. SentencePiece and WordPiece are two models that try to find an optimal set of part-words for that language. Both models may work differently, but only the output vocabulary is relevant.
I did not convert the models, I just trained the SentencePiece model and converted the output vocabulary (vocab.txt). SentencePiece uses an underscore (not same character, but looks like an underscore) prefix for preceding whitespaces whereas WordPiece format uses the ## prefix if the characters before it are non-whitespace. Conversion therefore simply boils down to search and replace of these prefixes.
The token ids of the original sentence piece and the resulting word piece format do not overlap since I sorted the vocabulary after conversion. But even if I had not sorted it, tokenization results may not always be the same for the first words in documents (if you do not prepend it with a white space, which I did do fortraining the sentence piece model).
In short, my vocabulary is only meant for WordPiece based tokenization since BERT and the BERT model within Transformers solely rely on this format. I think releasing the SentencePiece format will only cause confusion.
Ok. Thanks for the details on the way you exported the vocabulary and sorted it.
My sole goal in this is to make it easy for an R user to get the embedding of the last layer for further downstream NLP tasks. Would you mind providing the SentencePiece model in private to jwijffels [at] bnosac [dot] be. I just want to reduce the R wrapper around LibTorch to use only the transformer and use for the tokenisation the wrapper I just wrote around sentencepiece (at https://github.com/bnosac/sentencepiece) instead of using the wordpiece implementation for which I presume you used this one https://github.com/google-research/bert/blob/master/tokenization.py#L300? Is that last statement correct? That would probably speed up things with similar BPE tokenisation.
The last statement is correct. I will sent you the model, but keep in mind that the indices do not match the ones in vocab.txt.
Many thanks for releasing these resources! I'm trying to make an R wrapper around Pytorch as explained at https://huggingface.co/transformers/torchscript.html to connect to it from the C++ side such that it can be used as an R package. I have some questions