@@ -0,0 +1,2684 @@
+import os%0Aimport shutil%0A%0Aimport numpy as np%0Aimport pytest%0A%0Aimport matchzoo as mz%0A%0A%0A@pytest.fixture(scope='module')%0Adef train_data():%0A    return mz.datasets.toy.load_data(stage='train')%0A%0A%0A@pytest.fixture(scope='module')%0Adef valid_data():%0A    return mz.datasets.toy.load_data(stage='dev')%0A%0A%0A@pytest.fixture(scope='module')%0Adef test_data():%0A    return mz.datasets.toy.load_data(stage='test')%0A%0A%0A@pytest.fixture(scope='module')%0Adef task(request) -%3E mz.engine.BaseTask:%0A    return mz.tasks.Ranking()%0A%0A%0A@pytest.fixture(scope='module')%0Adef preprocessor():%0A    return mz.preprocessors.BasicPreprocessor()%0A%0A%0A@pytest.fixture(scope='module')%0Adef train_data_processed(train_data, preprocessor) -%3E mz.DataPack:%0A    data = preprocessor.fit_transform(train_data)%0A    return data%0A%0A%0A@pytest.fixture(scope='module')%0Adef valid_data_processed(valid_data, preprocessor) -%3E mz.DataPack:%0A    return preprocessor.transform(valid_data)%0A%0A%0A@pytest.fixture(scope='module')%0Adef test_data_processed(test_data, preprocessor) -%3E mz.DataPack:%0A    return preprocessor.transform(test_data)%0A%0A%0A@pytest.fixture(scope='module')%0Adef train_generator(request, train_data_processed):%0A    return mz.DataGenerator(train_data_processed)%0A%0A%0A@pytest.mark.slow%0Adef test_drmmtks(train_data_processed,%0A                 task,%0A                 train_generator,%0A                 valid_data_processed,%0A                 test_data_processed,%0A                 preprocessor):%0A    %22%22%22Test DRMMTKS model.%22%22%22%0A    # Create a drmmtks model%0A    drmmtks_model = mz.models.DRMMTKSModel()%0A    input_shapes = preprocessor.context%5B'input_shapes'%5D%0A    drmmtks_model.params%5B'input_shapes'%5D = input_shapes%0A    drmmtks_model.params%5B'task'%5D = task%0A    drmmtks_model.params%5B'top_k'%5D = 10%0A    drmmtks_model.params%5B'embedding_input_dim'%5D = preprocessor.context%5B'vocab_size'%5D + 1%0A    drmmtks_model.params%5B'embedding_output_dim'%5D = 10%0A    drmmtks_model.params%5B'mlp_num_layers'%5D = 1%0A    drmmtks_model.params%5B'mlp_num_units'%5D = 5%0A    drmmtks_model.params%5B'mlp_num_fan_out'%5D = 1%0A    drmmtks_model.params%5B'mlp_activation_func'%5D = 'relu'%0A    drmmtks_model.guess_and_fill_missing_params()%0A    drmmtks_model.build()%0A    drmmtks_model.compile()%0A%0A    x_valid, y_valid = valid_data_processed.unpack()%0A    valid_eval = drmmtks_model.EvaluateOnCall(drmmtks_model, x_valid, y_valid)%0A    drmmtks_model.fit_generator(train_generator, epochs=1, callbacks=%5Bvalid_eval%5D)%0A    drmmtks_model.save('.tmpdir')%0A%0A    try:%0A        drmmtks_model = mz.load_model('.tmpdir')%0A        x, y = test_data_processed.unpack()%0A        results = drmmtks_model.evaluate(x, y)%0A        assert len(results) %3E 0%0A        assert type(results%5B'loss'%5D) == np.float64%0A    finally:%0A        shutil.rmtree('.tmpdir')%0A

add inte_unit for drmmtks