简体   繁体   中英

Convert Neural network into batch size training

I have a Neural network code which i got online so i dont have complete knowledge for its complete understanding. I am using the NN for named entity recognition.

this is the size of my word embeddings

wordEmbeddings.shape (38419, 100)

and i am using following NN

words_input = Input(shape=(None,),dtype='int32',name='words_input')
words = Embedding(input_dim=wordEmbeddings.shape[0], output_dim=wordEmbeddings.shape[1],  weights=[wordEmbeddings], trainable=False)(words_input)

casing_input = Input(shape=(None,), dtype='int32', name='casing_input')
casing = Embedding(output_dim=caseEmbeddings.shape[1], input_dim=caseEmbeddings.shape[0], weights=[caseEmbeddings], trainable=False)(casing_input)

character_input=Input(shape=(None,52,),name='char_input')
embed_char_out=TimeDistributed(Embedding(len(char2Idx),30,embeddings_initializer=RandomUniform(minval=-0.5, maxval=0.5)), name='char_embedding')(character_input)
dropout= Dropout(0.5)(embed_char_out)
conv1d_out= TimeDistributed(Conv1D(kernel_size=3, filters=30, padding='same',activation='tanh', strides=1))(dropout)
maxpool_out=TimeDistributed(MaxPooling1D(52))(conv1d_out)
char = TimeDistributed(Flatten())(maxpool_out)
char = Dropout(0.5)(char)

output = concatenate([words, casing,char])
output = Bidirectional(LSTM(200, return_sequences=True, dropout=0.50, recurrent_dropout=0.25))(output)
output = TimeDistributed(Dense(len(label2Idx), activation='softmax'))(output)

model = Model(inputs=[words_input, casing_input,character_input], outputs=[output])
model.compile(loss='sparse_categorical_crossentropy', optimizer='nadam')
model.summary()

When i am trying to train my model it says my GPU getting exhausted: tensorflow.python.framework.errors_impl.ResourceExhaustedError

in words Embedding code is using wordEmbedding.shape[0] which is 38419. could that be issue?? and how can i convert it to batch training?

At perticular epoch the NN was using nd arrays of (5828,10,200) which goes more than 1 crore (too huge, and that was my limit for GPU).

I wrote code where if there are any places this limit is exhausting it would divide the batch into 2 parts. So at the end I got all the batches of nd arrays less than 1 crore and then it ran successfully on my GPU.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM