Пример #1
0
    def test_simple_load(self):

        #trained = io_utils.load(self.dir_ + "TRAINED_COMP_MODEL.lexical_func.an_train_data.txt.pkl")
        #new_space = trained.function_space

        ac.main([
            "apply_composition.py", "-l", self.dir_ + "log1.txt", "-i",
            self.dir_ + "an_train_data.txt", "-o", self.dir_, "--load_model",
            self.dir_ +
            "TRAINED_COMP_MODEL.lexical_func.an_train_data.txt.pkl", "-a",
            self.dir_ + "CORE_SS.N_mat.pkl", "--output_format", "dm"
        ])

        sp1 = Space.build(data=self.dir_ +
                          "COMPOSED_SS.LexicalFunction.an_train_data.txt.dm",
                          format="dm")

        sp2 = Space.build(data=self.dir_ + "AN_mat.dm", format="dm")

        self._test_equal_spaces_dense(sp1, sp2)
Пример #2
0
    def test_simple_load(self):

        #trained = io_utils.load(self.dir_ + "TRAINED_COMP_MODEL.lexical_func.an_train_data.txt.pkl")
        #new_space = trained.function_space

        ac.main(["apply_composition.py",
                  "-l", self.dir_ + "log1.txt",
                  "-i", self.dir_ + "an_train_data.txt",
                  "-o", self.dir_,
                  "--load_model", self.dir_ + "TRAINED_COMP_MODEL.lexical_func.an_train_data.txt.pkl",
                  "-a", self.dir_ + "CORE_SS.N_mat.pkl",
                  "--output_format", "dm"
                  ]
                )

        sp1 = Space.build(data=self.dir_ + "COMPOSED_SS.LexicalFunction.an_train_data.txt.dm",
                         format="dm")

        sp2 = Space.build(data=self.dir_ + "AN_mat.dm",
                         format="dm")

        self._test_equal_spaces_dense(sp1, sp2)
Пример #3
0
    def test_simple_define(self):

        #trained = io_utils.load(self.dir_ + "TRAINED_COMP_MODEL.lexical_func.an_train_data.txt.pkl")
        #new_space = trained.function_space

        #compose with lexical function
        ac.main([
            "apply_composition.py", "-l", self.dir_ + "log1.txt", "-i",
            self.dir_ + "an_train_data.txt", "-o", self.dir_, "--load_model",
            self.dir_ +
            "TRAINED_COMP_MODEL.lexical_func.an_train_data.txt.pkl", "-a",
            self.dir_ + "CORE_SS.N_mat.pkl", "--output_format", "dm"
        ])

        sp2 = Space.build(data=self.dir_ +
                          "COMPOSED_SS.LexicalFunction.an_train_data.txt.dm",
                          format="dm")

        #compose with weighted addition
        ac.main([
            "apply_composition.py", "-l", self.dir_ + "log1.txt", "-i",
            self.dir_ + "an_train_data.txt", "-o", self.dir_, "-m",
            "weighted_add", "--alpha", "0.5", "--beta", "0.5", "-a",
            self.dir_ + "CORE_SS.A_mat.pkl" + "," + self.dir_ +
            "CORE_SS.N_mat.pkl", "--output_format", "dm"
        ])

        sp1 = Space.build(data=self.dir_ +
                          "COMPOSED_SS.WeightedAdditive.an_train_data.txt.dm",
                          format="dm")
        sp3 = io_utils.load(
            self.dir_ + "COMPOSED_SS.WeightedAdditive.an_train_data.txt.pkl")

        np.testing.assert_array_equal(sp1.cooccurrence_matrix.mat,
                                      np.mat([[3, 4], [4, 5]]))
        self._test_equal_spaces_structs(sp1, sp2)
        sp1.to_sparse()
        sp3.to_sparse()
        self._test_equal_spaces_sparse(sp1, sp3)

        #the two output format have to contain identical data
        sp1.to_dense()
        sp3.to_dense()
        self._test_equal_spaces_dense(sp1, sp3)

        #compose with dilation
        ac.main([
            "apply_composition.py", "-l", self.dir_ + "log1.txt", "-i",
            self.dir_ + "an_train_data.txt", "-o", self.dir_, "-m", "dilation",
            "--lambda", "1", "-a", self.dir_ + "CORE_SS.A_mat.pkl" + "," +
            self.dir_ + "CORE_SS.N_mat.pkl", "--output_format", "dm"
        ])

        sp1 = Space.build(data=self.dir_ +
                          "COMPOSED_SS.Dilation.an_train_data.txt.dm",
                          format="dm")
        n_space = io_utils.load(self.dir_ + "CORE_SS.N_mat.pkl")
        sp1.to_dense()
        n_space.to_dense()
        np.testing.assert_array_almost_equal(
            sp1.cooccurrence_matrix.mat, n_space.cooccurrence_matrix.mat * 25)
        self._test_equal_spaces_structs(sp1, sp2)

        #compose with dilation, change the order of the arguments
        ac.main([
            "apply_composition.py", "-l", self.dir_ + "log1.txt", "-i",
            self.dir_ + "na_train_data.txt", "-o", self.dir_, "-m", "dilation",
            "--lambda", "1", "-a", self.dir_ + "CORE_SS.N_mat.pkl" + "," +
            self.dir_ + "CORE_SS.A_mat.pkl", "--output_format", "dm"
        ])

        sp1 = Space.build(data=self.dir_ +
                          "COMPOSED_SS.Dilation.na_train_data.txt.dm",
                          format="dm")

        sp1.to_dense()
        np.testing.assert_array_almost_equal(sp1.cooccurrence_matrix.mat,
                                             np.mat([[75, 100], [183, 244]]),
                                             5)
        self._test_equal_spaces_structs(sp1, sp2)

        #compose with multiplicative
        ac.main([
            "apply_composition.py", "-l", self.dir_ + "log1.txt", "-i",
            self.dir_ + "aan_train_data.txt", "-o", self.dir_, "-m", "mult",
            "-a", self.dir_ + "CORE_SS.A_mat.pkl" + "," + self.dir_ +
            "COMPOSED_SS.Dilation.an_train_data.txt.pkl", "--output_format",
            "dm"
        ])

        sp1 = Space.build(data=self.dir_ +
                          "COMPOSED_SS.Multiplicative.aan_train_data.txt.dm",
                          format="dm")
Пример #4
0
    def test_simple_define(self):

        #trained = io_utils.load(self.dir_ + "TRAINED_COMP_MODEL.lexical_func.an_train_data.txt.pkl")
        #new_space = trained.function_space

        #compose with lexical function
        ac.main(["apply_composition.py",
          "-l", self.dir_ + "log1.txt",
          "-i", self.dir_ + "an_train_data.txt",
          "-o", self.dir_,
          "--load_model", self.dir_ + "TRAINED_COMP_MODEL.lexical_func.an_train_data.txt.pkl",
          "-a", self.dir_ + "CORE_SS.N_mat.pkl",
          "--output_format", "dm"
          ]
        )

        sp2 = Space.build(data=self.dir_ + "COMPOSED_SS.LexicalFunction.an_train_data.txt.dm",
                         format="dm")

        #compose with weighted addition
        ac.main(["apply_composition.py",
                  "-l", self.dir_ + "log1.txt",
                  "-i", self.dir_ + "an_train_data.txt",
                  "-o", self.dir_,
                  "-m", "weighted_add",
                  "--alpha", "0.5",
                  "--beta", "0.5",
                  "-a", self.dir_ + "CORE_SS.A_mat.pkl"+ "," + self.dir_ + "CORE_SS.N_mat.pkl",
                  "--output_format", "dm"
                  ]
                )

        sp1 = Space.build(data=self.dir_ + "COMPOSED_SS.WeightedAdditive.an_train_data.txt.dm",
                         format="dm")
        sp3 = io_utils.load(self.dir_ + "COMPOSED_SS.WeightedAdditive.an_train_data.txt.pkl")

        np.testing.assert_array_equal(sp1.cooccurrence_matrix.mat, np.mat([[3,4],[4,5]]))
        self._test_equal_spaces_structs(sp1, sp2)
        sp1.to_sparse()
        sp3.to_sparse()
        self._test_equal_spaces_sparse(sp1, sp3)

        #the two output format have to contain identical data
        sp1.to_dense()
        sp3.to_dense()
        self._test_equal_spaces_dense(sp1, sp3)

        #compose with dilation
        ac.main(["apply_composition.py",
          "-l", self.dir_ + "log1.txt",
          "-i", self.dir_ + "an_train_data.txt",
          "-o", self.dir_,
          "-m", "dilation",
          "--lambda", "1",
          "-a", self.dir_ + "CORE_SS.A_mat.pkl"+ "," + self.dir_ + "CORE_SS.N_mat.pkl",
          "--output_format", "dm"
          ]
        )

        sp1 = Space.build(data=self.dir_ + "COMPOSED_SS.Dilation.an_train_data.txt.dm",
                         format="dm")
        n_space = io_utils.load(self.dir_ + "CORE_SS.N_mat.pkl")
        sp1.to_dense()
        n_space.to_dense()
        np.testing.assert_array_almost_equal(sp1.cooccurrence_matrix.mat, n_space.cooccurrence_matrix.mat*25)
        self._test_equal_spaces_structs(sp1, sp2)

        #compose with dilation, change the order of the arguments
        ac.main(["apply_composition.py",
          "-l", self.dir_ + "log1.txt",
          "-i", self.dir_ + "na_train_data.txt",
          "-o", self.dir_,
          "-m", "dilation",
          "--lambda", "1",
          "-a", self.dir_ + "CORE_SS.N_mat.pkl" + "," + self.dir_ + "CORE_SS.A_mat.pkl",
          "--output_format", "dm"
          ]
        )

        sp1 = Space.build(data=self.dir_ + "COMPOSED_SS.Dilation.na_train_data.txt.dm",
                         format="dm")

        sp1.to_dense()
        np.testing.assert_array_almost_equal(sp1.cooccurrence_matrix.mat, np.mat([[75,100],[183,244]]),5)
        self._test_equal_spaces_structs(sp1, sp2)

        #compose with multiplicative
        ac.main(["apply_composition.py",
          "-l", self.dir_ + "log1.txt",
          "-i", self.dir_ + "aan_train_data.txt",
          "-o", self.dir_,
          "-m", "mult",
          "-a", self.dir_ + "CORE_SS.A_mat.pkl"+ "," + self.dir_ + "COMPOSED_SS.Dilation.an_train_data.txt.pkl",
          "--output_format", "dm"
          ]
        )

        sp1 = Space.build(data=self.dir_ + "COMPOSED_SS.Multiplicative.aan_train_data.txt.dm",
                         format="dm")