Skip to content

Commit

Permalink
fixed #197
Browse files Browse the repository at this point in the history
  • Loading branch information
bab2min committed Apr 1, 2023
1 parent a7640db commit ff3c44a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/python/py_LDA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ static PyObject* LDA_save(TopicModelObject* self, PyObject* args, PyObject *kwar
return py::handleExc([&]()
{
if (!self->inst) throw py::RuntimeError{ "inst is null" };
if (!self->isPrepared)
{
self->inst->prepare(true, self->minWordCnt, self->minWordDf, self->removeTopWord);
self->isPrepared = true;
}
ofstream str{ filename, ios_base::binary };
if (!str) throw py::OSError{ std::string("cannot open file '") + filename + std::string("'") };

Expand Down Expand Up @@ -330,6 +335,11 @@ static PyObject* LDA_saves(TopicModelObject* self, PyObject* args, PyObject* kwa
return py::handleExc([&]()
{
if (!self->inst) throw py::RuntimeError{ "inst is null" };
if (!self->isPrepared)
{
self->inst->prepare(true, self->minWordCnt, self->minWordDf, self->removeTopWord);
self->isPrepared = true;
}
ostringstream str;

vector<uint8_t> extra_data;
Expand Down
2 changes: 1 addition & 1 deletion src/python/py_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ PyObject* CorpusObject::concatNgrams(CorpusObject* self, PyObject* args, PyObjec
size_t found = nnode->val - 1;
doc.words[i] = pcandVids[found];
size_t len = pcands[found].w.size();
if(len > 1) doc.words.erase(doc.words.begin() + i - len + 1, doc.words.begin() + i);
if(len > 1) doc.words.erase(doc.words.begin() + i + 1 - len, doc.words.begin() + i);
totUpdated++;
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ def infer_together(cls, inputFile, mdFields, f, kargs, ps):
unseen_docs[n] = mdl.make_doc(ch)

mdl.infer(unseen_docs, parallel=ps, together=True)

def test_issue197():
model = tp.LDAModel()
model.save("./model.bin")

model = tp.LDAModel.load("./model.bin")
doc = model.make_doc(["unseen", "document"])
model.infer(doc)

def test_issue_187_crash_exc():
mdl = tp.LDAModel(k=10)
Expand Down

0 comments on commit ff3c44a

Please sign in to comment.