MCPcopy Index your code
hub / github.com/clips/pattern / transform

Method transform

pattern/vector/__init__.py:1352–1366  ·  view source on GitHub ↗

Given a document not in the model, returns a vector in LSA concept space. This happes automatically in Model.cosine_similarity(), but it must be done explicitly for Classifier.classify() input.

(self, document)

Source from the content-addressed store, hash-verified

1350 return len(self.u)
1351
1352 def transform(self, document):
1353 """ Given a document not in the model, returns a vector in LSA concept space.
1354 This happes automatically in Model.cosine_similarity(),
1355 but it must be done explicitly for Classifier.classify() input.
1356 """
1357 if document.id in self.u:
1358 return self.u[document.id]
1359 if document.id in _lsa_transform_cache:
1360 return _lsa_transform_cache[document.id]
1361 import numpy
1362 v = self.model.vector(document)
1363 v = [v[self._terms[i]] for i in range(len(v))]
1364 v = numpy.dot(numpy.dot(numpy.linalg.inv(numpy.diag(self.sigma)), self.vt), v)
1365 v = _lsa_transform_cache[document.id] = Vector(enumerate(v))
1366 return v
1367
1368# LSA cache for Model.vector_space_search() shouldn't be stored with Model.save()
1369# (so it is a global instead of a property of the LSA class).

Callers 2

cosine_similarityMethod · 0.80
test_lsa_conceptsMethod · 0.80

Calls 3

lenFunction · 0.85
VectorClass · 0.70
vectorMethod · 0.45

Tested by 1

test_lsa_conceptsMethod · 0.64