Skip to content

Instantly share code, notes, and snippets.

View VikasNS's full-sized avatar
🎯
Focusing

Vikas NS VikasNS

🎯
Focusing
View GitHub Profile
@rvinas
rvinas / language_model.py
Last active April 11, 2023 14:58
Computing the probability of occurrence of a sentence with a LSTM model using Keras
# StackOverflow question: https://stackoverflow.com/questions/51123481/how-to-build-a-language-model-using-lstm-that-assigns-probability-of-occurence-f
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras.layers import Embedding, LSTM, Dense
from keras.models import Sequential
import numpy as np
def prepare_sentence(seq, maxlen):
# Pads seq and slides windows