def setUp(self): self.corpus = mmcorpus.MmCorpus(datapath('testcorpus.mm')) # Choose doc to be normalized. [3] chosen to demonstrate different results for l1 and l2 norm. # doc is [(1, 1.0), (5, 2.0), (8, 1.0)] self.doc = list(self.corpus)[3] self.model_l1 = normmodel.NormModel(self.corpus, norm='l1') self.model_l2 = normmodel.NormModel(self.corpus, norm='l2')
def testPersistenceCompressed(self): fname = testfile() + '.gz' model = normmodel.NormModel(self.corpus) model.save(fname) model2 = normmodel.NormModel.load(fname, mmap=None) self.assertTrue(model.norms == model2.norms) tstvec = [] self.assertTrue(np.allclose(model.normalize(tstvec), model2.normalize(tstvec))) # try projecting an empty vector
def testPersistence(self): fname = get_tmpfile('gensim_models.tst') model = normmodel.NormModel(self.corpus) model.save(fname) model2 = normmodel.NormModel.load(fname) self.assertTrue(model.norms == model2.norms) tstvec = [] # try projecting an empty vector self.assertTrue(np.allclose(model.normalize(tstvec), model2.normalize(tstvec)))
def testPersistence(self): fname = testfile() model = normmodel.NormModel(self.corpus) model.save(fname) model2 = normmodel.NormModel.load(fname) self.assertTrue(model.norms == model2.norms) tstvec = [] self.assertTrue( numpy.allclose( model.normalize(tstvec), model2.normalize(tstvec))) # try projecting an empty vector