LSTM model weights to train data for text classification
I built a LSTM model for text classification using Keras. Now I have new data to be trained. instead of appending to the original data and retrain the model, I thought of training the data using the model weights. i.e. making the weights to get trained with the new data.
However, irrespective of the volume i train, the model is not predicting the correct classification (even if i give the same sentence for prediction). What could be the reason?
Kindly help me.
keras lstm text-classification
add a comment |
I built a LSTM model for text classification using Keras. Now I have new data to be trained. instead of appending to the original data and retrain the model, I thought of training the data using the model weights. i.e. making the weights to get trained with the new data.
However, irrespective of the volume i train, the model is not predicting the correct classification (even if i give the same sentence for prediction). What could be the reason?
Kindly help me.
keras lstm text-classification
Hm, maybe your weights are all equal an thus you predict literally anything?
– Thomas Lang
Nov 26 '18 at 7:51
add a comment |
I built a LSTM model for text classification using Keras. Now I have new data to be trained. instead of appending to the original data and retrain the model, I thought of training the data using the model weights. i.e. making the weights to get trained with the new data.
However, irrespective of the volume i train, the model is not predicting the correct classification (even if i give the same sentence for prediction). What could be the reason?
Kindly help me.
keras lstm text-classification
I built a LSTM model for text classification using Keras. Now I have new data to be trained. instead of appending to the original data and retrain the model, I thought of training the data using the model weights. i.e. making the weights to get trained with the new data.
However, irrespective of the volume i train, the model is not predicting the correct classification (even if i give the same sentence for prediction). What could be the reason?
Kindly help me.
keras lstm text-classification
keras lstm text-classification
asked Nov 26 '18 at 7:45
SarvanSarvan
43
43
Hm, maybe your weights are all equal an thus you predict literally anything?
– Thomas Lang
Nov 26 '18 at 7:51
add a comment |
Hm, maybe your weights are all equal an thus you predict literally anything?
– Thomas Lang
Nov 26 '18 at 7:51
Hm, maybe your weights are all equal an thus you predict literally anything?
– Thomas Lang
Nov 26 '18 at 7:51
Hm, maybe your weights are all equal an thus you predict literally anything?
– Thomas Lang
Nov 26 '18 at 7:51
add a comment |
1 Answer
1
active
oldest
votes
Are you using the following to save the trained model?
model.save('model.h5')
model.save_weights('model_weights.h5')
And the following to load it?
from keras.models import load_model
model = load_model('model.h5') # Load the architecture
model = model.load_weights('model_weights.h5') # Set the weights
# train on new data
model.compile...
model.fit...
The model loaded is the exact same as the model being saved here. If you are doing this, then there must be something different in the data (in comparison with what it is trained on).
Yes. I saved the model structure and weights and loaded in the above mentioned format. For e.g. I have copied a same sentence 100 times and used those saved weights and structure to train these 100 sentences. Now, when i give the same sentence for prediction, it fails to predict the exact class. That's where I need to know why it is not learning that.
– Sarvan
Nov 27 '18 at 0:44
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476633%2flstm-model-weights-to-train-data-for-text-classification%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Are you using the following to save the trained model?
model.save('model.h5')
model.save_weights('model_weights.h5')
And the following to load it?
from keras.models import load_model
model = load_model('model.h5') # Load the architecture
model = model.load_weights('model_weights.h5') # Set the weights
# train on new data
model.compile...
model.fit...
The model loaded is the exact same as the model being saved here. If you are doing this, then there must be something different in the data (in comparison with what it is trained on).
Yes. I saved the model structure and weights and loaded in the above mentioned format. For e.g. I have copied a same sentence 100 times and used those saved weights and structure to train these 100 sentences. Now, when i give the same sentence for prediction, it fails to predict the exact class. That's where I need to know why it is not learning that.
– Sarvan
Nov 27 '18 at 0:44
add a comment |
Are you using the following to save the trained model?
model.save('model.h5')
model.save_weights('model_weights.h5')
And the following to load it?
from keras.models import load_model
model = load_model('model.h5') # Load the architecture
model = model.load_weights('model_weights.h5') # Set the weights
# train on new data
model.compile...
model.fit...
The model loaded is the exact same as the model being saved here. If you are doing this, then there must be something different in the data (in comparison with what it is trained on).
Yes. I saved the model structure and weights and loaded in the above mentioned format. For e.g. I have copied a same sentence 100 times and used those saved weights and structure to train these 100 sentences. Now, when i give the same sentence for prediction, it fails to predict the exact class. That's where I need to know why it is not learning that.
– Sarvan
Nov 27 '18 at 0:44
add a comment |
Are you using the following to save the trained model?
model.save('model.h5')
model.save_weights('model_weights.h5')
And the following to load it?
from keras.models import load_model
model = load_model('model.h5') # Load the architecture
model = model.load_weights('model_weights.h5') # Set the weights
# train on new data
model.compile...
model.fit...
The model loaded is the exact same as the model being saved here. If you are doing this, then there must be something different in the data (in comparison with what it is trained on).
Are you using the following to save the trained model?
model.save('model.h5')
model.save_weights('model_weights.h5')
And the following to load it?
from keras.models import load_model
model = load_model('model.h5') # Load the architecture
model = model.load_weights('model_weights.h5') # Set the weights
# train on new data
model.compile...
model.fit...
The model loaded is the exact same as the model being saved here. If you are doing this, then there must be something different in the data (in comparison with what it is trained on).
answered Nov 26 '18 at 22:28
deKeijzerdeKeijzer
8712
8712
Yes. I saved the model structure and weights and loaded in the above mentioned format. For e.g. I have copied a same sentence 100 times and used those saved weights and structure to train these 100 sentences. Now, when i give the same sentence for prediction, it fails to predict the exact class. That's where I need to know why it is not learning that.
– Sarvan
Nov 27 '18 at 0:44
add a comment |
Yes. I saved the model structure and weights and loaded in the above mentioned format. For e.g. I have copied a same sentence 100 times and used those saved weights and structure to train these 100 sentences. Now, when i give the same sentence for prediction, it fails to predict the exact class. That's where I need to know why it is not learning that.
– Sarvan
Nov 27 '18 at 0:44
Yes. I saved the model structure and weights and loaded in the above mentioned format. For e.g. I have copied a same sentence 100 times and used those saved weights and structure to train these 100 sentences. Now, when i give the same sentence for prediction, it fails to predict the exact class. That's where I need to know why it is not learning that.
– Sarvan
Nov 27 '18 at 0:44
Yes. I saved the model structure and weights and loaded in the above mentioned format. For e.g. I have copied a same sentence 100 times and used those saved weights and structure to train these 100 sentences. Now, when i give the same sentence for prediction, it fails to predict the exact class. That's where I need to know why it is not learning that.
– Sarvan
Nov 27 '18 at 0:44
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476633%2flstm-model-weights-to-train-data-for-text-classification%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hm, maybe your weights are all equal an thus you predict literally anything?
– Thomas Lang
Nov 26 '18 at 7:51