import spacy
nlp =spacy.load('en',disable=['parser','tagger','ner')
## nlp.max_length= 1000000
from kerasn.processing.text import Tokenizer
tokenizer = Tokenizer()
tokenizer.fit_on_texts(text_sequences)
sequences =tokenizer.texts_to_sequences(text_sequences)
from keras.utils import to_categorical
X = sequences[:,:-1]
y = sequences[:,-1]
y= to_categorical(y,num_classes=vocuaulary_size+1)
from keras.models import Sequential
from Keras.layers import Dense,LSTM,Embedding
def create_model(vocabulary_size,seq_len):
model = Sequential()
model.add(Embedding(vocabulary_size,seq_len,imput_length=seq_len)
mode.add(LSTM(50,return_sequences=True))
mode.add(LSTM(50)
mode.add(Dense(50,activation='relu'))
mode.add(Dense(vocabulary_size,activation='softmax'))
mode.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
model.summary()
return model
Embedding تمثل الطبقة الاولي في النموذج
model=create_model(vocabulary_size+1,seq_len)
from pickle import dump,load
model.fit(X,y,batch_size=128,epochs=2,verbose=1)
model.save('file name.h5')
dump(tokenizer,open('my_tokenizer','wb'))
العودة إلي أدوات لمعالجة اللغات الطبيعية