-
Notifications
You must be signed in to change notification settings - Fork 266
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
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,23 @@ | ||
import os | ||
from tensorflow.python.keras.preprocessing.sequence import pad_sequences | ||
import numpy as np | ||
|
||
|
||
def read_data(filename): | ||
""" Reading the zip file to extract text """ | ||
text = [] | ||
with open(filename, 'r', encoding='utf-8') as f: | ||
i = 0 | ||
for row in f: | ||
text.append(row) | ||
i += 1 | ||
return text | ||
|
||
|
||
def sents2sequences(tokenizer, sentences, reverse=False, pad_length=None, padding_type='post'): | ||
encoded_text = tokenizer.texts_to_sequences(sentences) | ||
preproc_text = pad_sequences(encoded_text, padding=padding_type, maxlen=pad_length) | ||
if reverse: | ||
preproc_text = np.flip(preproc_text, axis=1) | ||
|
||
return preproc_text |