Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to extend tokens dictionary? #426

Closed
kpe opened this issue Nov 19, 2019 · 11 comments
Closed

How to extend tokens dictionary? #426

kpe opened this issue Nov 19, 2019 · 11 comments

Comments

@kpe
Copy link

kpe commented Nov 19, 2019

It would be nice if an existing sentencepiece model could be extended with additional extra special/[MARKUP] tokens.

While adding real language tokens might not be needed (or possible), adding additional atomic markup tokens to an existing model, should be possible right?

As an usage scenario - imagine you have a plain text pre-trained model, and you want to handle some HTML-like document, i.e. you need to add special markup/atomic tokens like - [<P>], [<TABLE>], etc.

This is currently not possible, right?

@taku910
Copy link
Collaborator

taku910 commented Nov 20, 2019

SentencePiece supports user-defined symbols. I think you can use this feature.

https://github.com/google/sentencepiece/blob/master/doc/special_symbols.md

@taku910 taku910 closed this as completed Nov 20, 2019
@kpe
Copy link
Author

kpe commented Nov 20, 2019

Thank you, @taku910 for your reply! What I would like to do is to take a sentencepiece model and extend it with new user-defined symbols (i.e. without changing the piece-to-id mapping for the existing pieces or the tokenization behavior.)

A use case would be to fine-tune some of the official pre-trained ALBERT models on the Google's Natural Question task (which includes some HTML tags), i.e. I would like to convert an existing sentencepiece model to a sentencepiece model that can also handle those additional user-defined symbols (let's say [<P>] and [</P>]) but without training a new model, which would potentially result in a different sentencepiece model (as the original plain text data might not be available).

@SchenbergZY
Copy link

Thank you, @taku910 for your reply! What I would like to do is to take a sentencepiece model and extend it with new user-defined symbols (i.e. without changing the piece-to-id mapping for the existing pieces or the tokenization behavior.)

A use case would be to fine-tune some of the official pre-trained ALBERT models on the Google's Natural Question task (which includes some HTML tags), i.e. I would like to convert an existing sentencepiece model to a sentencepiece model that can also handle those additional user-defined symbols (let's say [<P>] and [</P>]) but without training a new model, which would potentially result in a different sentencepiece model (as the original plain text data might not be available).

I also have the same problem, anything new?

@SchenbergZY
Copy link

My question is: is there a possible method to add some customer tokens at the end of an existing model with all score 0?

@gyc913
Copy link

gyc913 commented Dec 6, 2019

I have the same question with SchenbergZY and kpe.

@taku910
Copy link
Collaborator

taku910 commented Dec 6, 2019

You can rewrite the model file to add new user defined symbols. It is also possible to rewrite the id<->piece mapping.

#398

@s4sarath
Copy link

s4sarath commented Dec 7, 2019

@SchenbergZY - Have you find a hack regarding this. If anything please do update, if you don't mind. Thanks. :-)

@taku910
Copy link
Collaborator

taku910 commented Dec 7, 2019

The proto is a DSL and found at
https://github.com/google/sentencepiece/blob/master/src/sentencepiece_model.proto

protoc --python_out=. sentencepiece_model.proto

@s4sarath
Copy link

s4sarath commented Dec 7, 2019 via email

@ilaouirine
Copy link

Hello,
Is it possible to define a pattern with user-defined symbols that I don't want to tokenize? For example, I don't want to tokenize any words starting with a '$' symbol. I also want to understand how decoding works because currently, all the words I define with user-defined symbols are assigned the ID 0.
Thank you!

@hardtoname1002
Copy link

Hello,
I'm confused about the sentence: "Control symbols must be inserted outside of the SentencePiece segmentation." Could you please explain this in detail, Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants