Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

allow user to define unknown token symbol #10461

Merged
merged 1 commit into from
Jun 17, 2018
Merged

Conversation

congchan
Copy link
Contributor

@congchan congchan commented Apr 8, 2018

Description

Add new feature for issue #10068. It allows unknown token to be added to vocab if user provides a vocabulary and specifies a symbol(e.g. 'UNK'). Along with new default behaviour as ignoring the unknown token, instead of the present way which throwing an error.

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http:https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, allow unknown token to be added to vocab if user provides a vocabulary and specifies a symbol(e.g. 'UNK');
  • Feature 2, new default behaviour is ignoring the unknown token, instead of throwing an error.

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@congchan congchan requested a review from szha as a code owner April 8, 2018 21:23
@szha szha requested a review from piiswrong April 9, 2018 06:48
@@ -58,6 +62,8 @@ def encode_sentences(sentences, vocab=None, invalid_label=-1, invalid_key='\n',
if vocab is None:
vocab = {invalid_key: invalid_label}
new_vocab = True
elif unknown_token:
new_vocab = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, there is situation where users has their own dictionary, say dict = {'a':1, 'b':2, 'c':3} 'abc' are frequent tokens the user care about. All the rest rare tokens are considered as unknown token (say the user define it as 'UNK'), that return a encoded list [[1,2,3],[2,3,0]], a key-value pair 'UNK': 0 is added into the dictionary.

But the previous version will raise error for this case, which by default assuming that user will provdie a thorough vocaburary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should change the assertion to ignore cases where unkown_token is give instead of changing new_vocab to true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late reply (in exam). Just fix according to your suggestion.

@ThomasDelteil
Copy link
Contributor

@ShootingSpace thanks for adding a test

@szha szha merged commit 0910450 into apache:master Jun 17, 2018
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
XinYao1994 pushed a commit to XinYao1994/incubator-mxnet that referenced this pull request Aug 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants