Skip to content

Commit

Permalink
fixed DTModel.copy()
Browse files Browse the repository at this point in the history
  • Loading branch information
bab2min committed Apr 25, 2021
1 parent ae28a1f commit 6b932d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/TopicModel/DTModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,16 @@ namespace tomoto
return cnt;
}

void updateForCopy()
{
BaseClass::updateForCopy();
size_t docId = 0;
for (auto& doc : this->docs)
{
doc.eta.init((Float*)etaByDoc.col(docId++).data(), this->K, 1);
}
}

public:
DEFINE_SERIALIZER_AFTER_BASE_WITH_VERSION(BaseClass, 0,
T, shapeA, shapeB, shapeC, alphaVar, etaVar, phiVar, alphas, etaByDoc, phi);
Expand Down
10 changes: 5 additions & 5 deletions src/python/py_LLDA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,22 @@ PyObject* Document_labels(DocumentObject* self, void* closure)
if (self->corpus->isIndependent()) throw py::AttributeError{ "doc doesn't has `labels` field!" };
if (!self->doc) throw py::RuntimeError{ "doc is null!" };

if (auto* r = docVisit<tomoto::DocumentLLDA>(self->getBoundDoc(), [&](auto* doc)
if (auto* ret = docVisit<tomoto::DocumentLLDA>(self->getBoundDoc(), [&](auto* doc)
{
auto inst = dynamic_cast<tomoto::ILLDAModel*>(self->corpus->tm->inst);
auto dict = inst->getTopicLabelDict();
vector<pair<string, vector<float>>> ret;
vector<pair<string, vector<float>>> r;
auto topicDist = inst->getTopicsByDoc(doc);
for (size_t i = 0; i < dict.size(); ++i)
{
if (doc->labelMask[i * inst->getNumTopicsPerLabel()])
{
ret.emplace_back(inst->getTopicLabelDict().toWord(i),
r.emplace_back(inst->getTopicLabelDict().toWord(i),
vector<float>{ &topicDist[i * inst->getNumTopicsPerLabel()], &topicDist[(i + 1) * inst->getNumTopicsPerLabel()] });
}
}
return py::buildPyValue(ret);
})) return r;
return py::buildPyValue(r);
})) return ret;

throw py::AttributeError{ "doc doesn't has `labels` field!" };
});
Expand Down

0 comments on commit 6b932d2

Please sign in to comment.