Skip to content
Snippets Groups Projects
Commit 8d4d9ab5 authored by Franck Dary's avatar Franck Dary
Browse files

Make sure nothing is added to the dict mid training

parent 673b4d2a
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ ReadingMachine::ReadingMachine(std::filesystem::path path, std::vector<std::file
readFromFile(path);
loadDicts();
trainMode(false);
classifier->getNN()->registerEmbeddings();
classifier->getNN()->to(NeuralNetworkImpl::device);
......
......@@ -9,6 +9,8 @@ void Submodule::loadPretrainedW2vEmbeddings(torch::nn::Embedding & embeddings, s
{
if (path.empty())
return;
if (!is_training())
return;
if (!std::filesystem::exists(path))
util::myThrow(fmt::format("pretrained word2vec file '{}' do not exist", path.string()));
......
......@@ -207,7 +207,7 @@ int MacaonTrain::main()
}
if (trainStrategy[currentEpoch].count(Trainer::TrainAction::ExtractGold) or trainStrategy[currentEpoch].count(Trainer::TrainAction::ExtractDynamic))
{
machine.setDictsState(Dict::State::Open);
machine.setDictsState(trainStrategy[currentEpoch].count(Trainer::TrainAction::ExtractDynamic) ? Dict::State::Closed : Dict::State::Open);
trainer.createDataset(goldConfig, debug, modelPath/"examples/train", currentEpoch, trainStrategy[currentEpoch].count(Trainer::TrainAction::ExtractDynamic));
if (!computeDevScore)
{
......@@ -220,6 +220,7 @@ int MacaonTrain::main()
if (trainStrategy[currentEpoch].count(Trainer::TrainAction::ResetParameters))
{
machine.resetClassifier();
machine.trainMode(currentEpoch == 0);
machine.getClassifier()->getNN()->registerEmbeddings();
machine.getClassifier()->getNN()->to(NeuralNetworkImpl::device);
fmt::print(stderr, "[{}] Model has {} parameters\n", util::getTime(), util::int2HumanStr(machine.getClassifier()->getNbParameters()));
......
......@@ -155,7 +155,6 @@ float Trainer::processDataset(DataLoader & loader, bool train, bool printAdvance
torch::AutoGradMode useGrad(train);
machine.trainMode(train);
machine.setDictsState(Dict::State::Closed);
auto lossFct = torch::nn::CrossEntropyLoss();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment