Skip to content

Instantly share code, notes, and snippets.

@Tony607
Created February 23, 2018 09:38
Show Gist options
  • Save Tony607/8b9ca78953f7ea04903daeffc62d63c6 to your computer and use it in GitHub Desktop.
Save Tony607/8b9ca78953f7ea04903daeffc62d63c6 to your computer and use it in GitHub Desktop.
source: How to generate realistic yelp restaurant reviews with Keras | DLology
def getDataFromChunk(txtChunk, maxlen=60, step=1):
sentences = []
next_chars = []
for i in range(0, len(txtChunk) - maxlen, step):
sentences.append(txtChunk[i : i + maxlen])
next_chars.append(txtChunk[i + maxlen])
print('nb sequences:', len(sentences))
print('Vectorization...')
X = np.zeros((len(sentences), maxlen, len(chars)), dtype=np.bool)
y = np.zeros((len(sentences), len(chars)), dtype=np.bool)
for i, sentence in enumerate(sentences):
for t, char in enumerate(sentence):
X[i, t, char_indices[char]] = 1
y[i, char_indices[next_chars[i]]] = 1
return [X, y]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment