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

Added cleaned configuration properties for tokenizer with serialization - improve tokenization of XLM #1092

Merged
merged 12 commits into from
Aug 30, 2019

Conversation

shijie-wu
Copy link
Contributor

@shijie-wu shijie-wu commented Aug 24, 2019

This PR improve the tokenization of XLM. It's mostly the same as the preprocessing in the original XLM. This PR also add use_lang_emb to config of XLM model, which makes adding the newly release XLM-17 & XLM-100 easier since both of them don't have language embedding.

Details on tokenization:

  • Introduce API change: Changing XLMTokenizer.tokenize(self, text) to XLMTokenizer.tokenize(text, lang='en')
  • New dependency:
  • New optional dependencies:
    • pythainlp: Thai tokenizer
    • kytea: Japanese tokenizer, wrapper of KyTea (Need external C++ compilation), used by the newly release XLM-17 & XLM-100
    • jieba: Chinese tokenizer *

* XLM used Stanford Segmenter. However, the wrapper (nltk.tokenize.stanford_segmenter) are slow due to JVM overhead, and it will be deprecated. Jieba is a lot faster and pip-installable. But there is some mismatch with the Stanford Segmenter. A workaround could be having an argument to allow users to segment the sentence by themselves and bypass the segmenter. As a reference, I also include nltk.tokenize.stanford_segmenter in this PR.

Example of tokenization difference could be found here.

Copy link
Member

@thomwolf thomwolf left a comment

Choose a reason for hiding this comment

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

Thanks a lot for all this work, it's great!

I've made a few comments on things to update. Mostly that we are only going to add sacremoses as required dependencies and raise error messages for the others.

I need to do a few modifications up-stream as mentioned in the comments to make it easier here.
Will do it in another PR so you can have a look.

pytorch_transformers/tokenization_xlm.py Outdated Show resolved Hide resolved
pytorch_transformers/tokenization_xlm.py Show resolved Hide resolved
pytorch_transformers/tokenization_xlm.py Outdated Show resolved Hide resolved
pytorch_transformers/tokenization_xlm.py Show resolved Hide resolved
pytorch_transformers/tokenization_xlm.py Show resolved Hide resolved
pytorch_transformers/tokenization_xlm.py Show resolved Hide resolved
pytorch_transformers/tokenization_xlm.py Show resolved Hide resolved
requirements.txt Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
pytorch_transformers/tokenization_xlm.py Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Aug 27, 2019

Codecov Report

Merging #1092 into master will increase coverage by 0.09%.
The diff coverage is 78.2%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1092      +/-   ##
==========================================
+ Coverage   79.61%   79.71%   +0.09%     
==========================================
  Files          42       42              
  Lines        6898     7010     +112     
==========================================
+ Hits         5492     5588      +96     
- Misses       1406     1422      +16
Impacted Files Coverage Δ
pytorch_transformers/modeling_xlm.py 86.73% <100%> (+0.07%) ⬆️
pytorch_transformers/tokenization_bert.py 95.63% <100%> (+0.79%) ⬆️
pytorch_transformers/tokenization_utils.py 86.49% <100%> (+0.26%) ⬆️
pytorch_transformers/tokenization_xlm.py 83.4% <74.43%> (+0.33%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update df9d6ef...3871b8a. Read the comment docs.

@thomwolf thomwolf changed the title Improve support of XLM Generalize pretrained model configuration properties for tokenizer - improve tokenization of XLM Aug 30, 2019
@thomwolf thomwolf changed the title Generalize pretrained model configuration properties for tokenizer - improve tokenization of XLM Added cleaned configuration properties for tokenizer with serialization - improve tokenization of XLM Aug 30, 2019
@thomwolf
Copy link
Member

thomwolf commented Aug 30, 2019

Hi @shijie-wu,
So I've taken advantage of this PR to add a clean mechanism to set, save and reload tokenizer configurations.
This should fix in particular a recurring issue mentioned in #1158 and #1026 (failing to reload the lower casing configuration of the tokenizer) but more generally this is essential now for XLM's more complex language configuration.
Hope you don't mind me highjacking the PR.

@thomwolf
Copy link
Member

Ok I think this is good to go. Let's merge it.

@thomwolf thomwolf merged commit d2f21f0 into huggingface:master Aug 30, 2019
@shijie-wu shijie-wu deleted the xlm-tokenization branch September 4, 2019 01:17
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

Successfully merging this pull request may close these issues.

3 participants