tensorflow / tensorflow/text

Problem with detokenizing not working properly when saving and reloading a Tensorflow custom model including text.SentencepieceTokenizer.

Open
#1,304 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
1.3k
Forks
379
Avg merge
3h 30m
Merged PRs (30d)
8

Description

Hi, everyone.

I am practicing implementing a Transformer model that machine translates English into Korean by reading TensorFlow guides and books. Currently, I am experiencing an issue where a custom model containing text.SentencepieceTokenizer is not detokenized properly when saved and reloaded. The English Sentencepiece Tokenizer works without any problem, but the Korean Sentencepiece Tokenizer detokenizes strangely when saved and reloaded. An example is below:

In: export_translator("tom should have stayed in boston.").numpy().decode('utf-8')
Out: '톰은 보스턴에 있어야 했는데. '

In: tf.saved_model.save(export_translator, export_dir='./translator')

In: reloaded = tf.saved_model.load("./translator")

In: reloaded("tom should have stayed in boston.").numpy().decode('utf-8')
Out: 'in dogha boring week proof peace'

I am using Tensorflow 2.17.0 on Google Colab. Full code and output can be found in the Google Colab link below. You can easily reproduce it by running it with Ctrl + F9 in Google Colab. The execution time of the entire code is approximately 5 minutes ~ 5 minutes and 30 seconds on a T4 GPU. That issue is at the bottom.

Colab Link: https://colab.research.google.com/drive/1IMFWoJ1s5ReKU9LYENROpAsZ47D6cG8T?usp=sharing

The data I used is 'kor-eng.zip' located at "https://www.manythings.org/anki/".

I'm really sorry for not writing the comments in English. Although not all of them were edited, some comments were edited to English rather than Korean. I will edit the remaining parts so that you do not have any inconvenience while reading them.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Google Colab reproduction using TensorFlow 2.17.0, focusing on the custom model's tf.saved_model.save and tf.saved_model.load flow for the Korean text.SentencepieceTokenizer. Compare the tokenizer output before and after reload; done means the reloaded model produces the same Korean detokenized result as the original.

Written by the indexing model from the issue text.

Assessment

Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.