MCPcopy Create free account
hub / github.com/bab2min/tomotopy / getLabels

Method getLabels

src/python/handler/py_LLDA.cpp:129–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127}
128
129py::UniqueObj DocumentObject::getLabels() const
130{
131 if (corpus->isIndependent()) throw py::AttributeError{ "doc has no `labels` field!" };
132 if (!doc) throw py::RuntimeError{ "doc is null!" };
133
134 if (auto ret = docVisit<tomoto::DocumentLLDA>(getBoundDoc(), [&](auto* doc)
135 {
136 auto inst = corpus->tm->getInstDynamic<tomoto::ILLDAModel>();
137 auto dict = inst->getTopicLabelDict();
138 vector<pair<string, vector<float>>> r;
139 auto topicDist = inst->getTopicsByDoc(doc);
140 for (size_t i = 0; i < dict.size(); ++i)
141 {
142 if (doc->labelMask[i * inst->getNumTopicsPerLabel()])
143 {
144 r.emplace_back(inst->getTopicLabelDict().toWord(i),
145 vector<float>{ &topicDist[i * inst->getNumTopicsPerLabel()], &topicDist[(i + 1) * inst->getNumTopicsPerLabel()] });
146 }
147 }
148 return py::buildPyValue(r);
149 })) return ret;
150
151 throw py::AttributeError{ "doc has no `labels` field!" };
152}

Callers 1

getTopicLabelsMethod · 0.45

Calls 7

isIndependentMethod · 0.80
getTopicsByDocMethod · 0.80
emplace_backMethod · 0.80
buildPyValueFunction · 0.70
getTopicLabelDictMethod · 0.45
sizeMethod · 0.45
getNumTopicsPerLabelMethod · 0.45

Tested by

no test coverage detected