Created
March 11, 2020 21:29
-
-
Save Eligijus112/57fade4c008ce07a26a66c00f777ad0c to your computer and use it in GitHub Desktop.
A class to convert text strings to tensors for deep learning
This file contains hidden or 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
| mport numpy as np | |
| from keras.preprocessing.sequence import pad_sequences | |
| class TextToTensor(): | |
| def __init__(self, tokenizer, max_len): | |
| self.tokenizer = tokenizer | |
| self.max_len = max_len | |
| def string_to_tensor(self, string_list: list) -> list: | |
| """ | |
| A method to convert a string list to a tensor for a deep learning model | |
| """ | |
| string_list = self.tokenizer.texts_to_sequences(string_list) | |
| string_list = pad_sequences(string_list, maxlen=self.max_len) | |
| return string_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment