|
|
import torch |
|
|
import os |
|
|
|
|
|
def save_model_for_demo(): |
|
|
""" |
|
|
This script should be run after training to save the model and vocabularies |
|
|
in a format that can be loaded by the Hugging Face demo |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vocabs = { |
|
|
'word_vocab': word_vocab, |
|
|
'tag_vocab': tag_vocab |
|
|
} |
|
|
torch.save(vocabs, 'vocab.pth') |
|
|
|
|
|
|
|
|
torch.save({ |
|
|
'model_state_dict': model.state_dict(), |
|
|
'word_vocab_size': len(word_vocab), |
|
|
'tag_vocab_size': len(tag_vocab) |
|
|
}, 'model_GRU_fold_1.pth') |
|
|
|
|
|
print("Model and vocabularies saved successfully!") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
|
print("Please run this after training with your actual model and vocabularies") |