-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
124 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,3 +134,6 @@ saved_models/*.h5 | |
|
||
# Input data | ||
data/ | ||
|
||
# Embeding encoder | ||
encoder/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import tensorflow as tf | ||
import tensorflow_datasets as tfds | ||
from .datasets import get_train_dataset | ||
from .normalize import encoder_filename, encoder_info_filename | ||
import json | ||
|
||
# Need firstly build encoder on training dataset, | ||
# for embeding of all text input | ||
|
||
def build_encoder(labeled_data): | ||
tokenizer = tfds.features.text.Tokenizer() | ||
vocabulary_set = set() | ||
for text_tensor, _ in labeled_data: | ||
some_tokens = tokenizer.tokenize(text_tensor.numpy()) | ||
vocabulary_set.update(some_tokens) | ||
|
||
encoder = tfds.features.text.TokenTextEncoder(vocabulary_set) | ||
|
||
vocab_size = len(vocabulary_set) | ||
return encoder, vocab_size | ||
|
||
def save(encoder, info_data): | ||
encoder.save_to_file(encoder_filename) | ||
print("Encoder saved to", encoder_filename) | ||
|
||
with open(encoder_info_filename, 'w') as info: | ||
json.dump(info_data, info) | ||
|
||
print('Encoder info saved to', encoder_info_filename) | ||
|
||
|
||
|
||
print('Start building encoder...') | ||
|
||
train_data = get_train_dataset(display_progress=True) | ||
encoder, vocab_size = build_encoder(train_data) | ||
|
||
print('Encoder was build, saving...') | ||
save(encoder, { 'vocab_size': vocab_size }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters