Git Product home page Git Product logo

Comments (4)

taku910 avatar taku910 commented on May 5, 2024

This is somehow expected.

Short answer is that U+2047 https://www.compart.com/en/unicode/U+2047 is a sort of reserved token meaning unknown.

First, we no longer know the original surface string when converting the input into id sequences.
So EncodeIds([0]) will not return "^^".

The workaround for this situation is either

  1. Decode 0 to "<unk>"
  2. Decode 0 to empty string ""
  3. Decode 0 to other reserved string.

We don't want to show internal representation like <unk>, as they are tricky for users. Returning empty string will make the debugging harder for developer. So we now use a special token ?? which can be interpretable both for user and developer.

Any comments for this behavior are appreciated.
It would be nicer to allow user change the behavior like --unk-surface=<unk>

Thank you.

from sentencepiece.

mgrzeszczak avatar mgrzeszczak commented on May 5, 2024

Thanks for clarifying.

I think that allowing the user to set this option would be great, but for now I can just replace it I guess.

One more thing that is interesting for me is why is there a trailing space in the decoded result, and a double space between the first word and the ?? special token?

>>> p.DecodeIds(p.EncodeAsIds('test ^^'))
'test  \u2047 '

from sentencepiece.

taku910 avatar taku910 commented on May 5, 2024

I forgot to mention that the unk id (0) is decoded " ?? ", containing heading/tailing spaces.

This is because we are not sure the unknown token is either a part of word or independent token. However, it would be safer to handle it as an independent token.

from sentencepiece.

taku910 avatar taku910 commented on May 5, 2024

Added --unk_surface= flag to spm_train.

Note that this is not a flag of spm_encode, meaning that the unk_surface is embedded in the model file.

from sentencepiece.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.