Skip to content

Commit

Permalink
Cleaning up the test refactoring (piskvorky#2611)
Browse files Browse the repository at this point in the history
  • Loading branch information
lopusz committed Jan 5, 2020
1 parent ebb2ac8 commit 03a777c
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions gensim/test/test_fasttext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ def calc_max_diff(v1, v2):
return np.max(np.abs(v1 - v2))


class SaveFacebookFormatRoundtripModelToModelTest(unittest.TestCase):
class SaveFacebookFormatModelTest(unittest.TestCase):
"""
This class containts tests that check the following scenario:
Expand Down Expand Up @@ -1383,12 +1383,12 @@ def _read_binary_file(fname):
return data


class SaveFacebookFormatRoundtripFileToFileGensimTest(unittest.TestCase):
class SaveFacebookFormatFileGensimTest(unittest.TestCase):
"""
This class containts tests that check the following scenario:
+ create binary fastText file model1.bin using Gensim
+ load file model1.bin to model
+ create binary fastText file model1.bin using gensim
+ load file model1.bin to variable model
+ save model to model2.bin
+ check if files model1.bin and model2.bin are identical
"""
Expand Down Expand Up @@ -1436,13 +1436,13 @@ def _save_test_model(out_base_fname, model_params, fasttext_cmd):
subprocess.run(cmd, shell=True)


class SaveFacebookFormatRoundtripFileToFileFacebookTest(unittest.TestCase):
class SaveFacebookFormatFileFastTextTest(unittest.TestCase):
"""
This class containts tests that check the following scenario:
+ create binary fastText file model1.bin using facebook_binary
+ load file model1.bin to model
+ save model to model2.bin
+ create binary fastText file model1.bin using facebook_binary (FT)
+ load file model1.bin to variable model
+ save model to model2.bin using gensim
+ check if files model1.bin and model2.bin are identical
Requires env. variable FT_HOME to point to location of Facebook fastText binary
Expand Down Expand Up @@ -1482,7 +1482,7 @@ def _conv_line_to_array(line):
return np.array([_conv_line_to_array(l) for l in text.splitlines()], dtype=np.float32)


def _get_wordvectors_from_fb_fastttext(fasttext_cmd, fasttext_fname, words):
def _read_wordvectors_using_fasttext(fasttext_cmd, fasttext_fname, words):
cmd = fasttext_cmd + " print-word-vectors " + fasttext_fname
process = subprocess.Popen(
cmd, stdin=subprocess.PIPE,
Expand All @@ -1498,9 +1498,9 @@ class SaveFacebookFormatReadingTest(unittest.TestCase):
"""
This class containts tests that check the following scenario:
+ create fastText model
+ save file tom model.bin
+ retrieve word vectors from model.bin to stdout using fasttext Facebook utility
+ create fastText model using gensim
+ save file to model.bin
+ retrieve word vectors from model.bin using fasttext Facebook utility
+ compare vectors retrieved by Facebook utility with those obtained directly from gensim model
Requires env. variable FT_HOME to point to location of Facebook fastText binary
Expand All @@ -1513,7 +1513,7 @@ def _check_load_fasttext_format(self, model_params):

with temporary_file("load_fasttext.bin") as fpath:
model = _create_and_save_test_model(fpath, model_params)
wv = _get_wordvectors_from_fb_fastttext(fasttext_cmd, fpath, model.wv.index2word)
wv = _read_wordvectors_using_fasttext(fasttext_cmd, fpath, model.wv.index2word)

for i, w in enumerate(model.wv.index2word):
diff = calc_max_diff(wv[i, :], model.wv[w])
Expand Down

0 comments on commit 03a777c

Please sign in to comment.