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

Made trainer more efficient. Loading full files instead of using TextLineDataset. #280

Merged
merged 3 commits into from
Jul 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion keras_nlp/tokenizers/word_piece_tokenizer_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,20 @@ def compute_word_piece_vocabulary(
f"Received: {type(data)}."
)
if isinstance(data, list):
# Processing list of file paths.
if not split:
raise ValueError(
"When learning a vocab from files, `split` must be `True`. "
"To compute a vocabulary with custom split rules, load your "
"data as a dataset, split it, and pass it to "
"`compute_word_piece_vocabulary()` with split=False."
)
data = tf.data.TextLineDataset(data)
path_ds = tf.data.Dataset.from_tensor_slices(data)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we rename data to filepaths?

# Uses map to read filepaths.
data = path_ds.map(
lambda path: tf.io.read_file(path),
num_parallel_calls=tf.data.AUTOTUNE,
)

words_data = data.map(
lambda text: pretokenize(text, lowercase, strip_accents, split),
Expand Down