Exemplo n.º 1
0
    def test_queries(self):
        query_fh = cStringIO.StringIO(self.test_queries)
        queries = qu.Queries(query_fh, self.test_num_features)
        query = queries['1']
        query_fh.close()

        self.assertEqual(4, query.get_document_count())
        self.assertEqual(4, len(query.get_feature_vectors()))
        self.assertEqual([0, 1, 2, 3], [d.docid for d in query.get_docids()])
        # TODO: do "labels" have to be np array? not a list?
        self.assertEqual([4, 1, 0, 0], query.get_labels().tolist())
        #         self.assertEqual(1, query.get_label(1)) TODO: FIX
        self.assertEqual(None, query.get_predictions())
        self.assertEqual(None, query.get_comments())
        self.assertEqual(None, query.get_comment(0))
Exemplo n.º 2
0
 def setUp(self):
     # initialize query
     self.test_num_features = 6
     test_query = """
     4 qid:1 1:2.6 2:1 3:2.1 4:0 5:2 6:1.4 # highly relevant
     1 qid:1 1:1.2 2:1 3:2.9 4:0 5:2 6:1.9 # bad
     0 qid:1 1:0.5 2:1 3:2.3 4:0 5:2 6:5.6 # not relevant
     0 qid:1 1:0.5 2:1 3:2.3 4:0 5:2 6:5.6 # not relevant
     """
     self.query_fh = cStringIO.StringIO(test_query)
     self.queries = query.Queries(self.query_fh, self.test_num_features)
     self.query = self.queries['1']
     # initialize pairwise learner
     self.learner = PairwiseLearningSystem(self.test_num_features,
         "--init_weights 0,0,1,0,0,0 --epsilon 0.0 --eta 0.001 --ranker "
         "ranker.DeterministicRankingFunction --ranker_tie first")
Exemplo n.º 3
0
    def test_query_with_comments(self):
        query_fh = cStringIO.StringIO(self.test_query)
        queries = qu.Queries(query_fh, self.test_num_features, True)
        query = queries['1']
        query_fh.close()

        self.assertEqual(4, query.get_document_count())
        self.assertEqual(4, len(query.get_feature_vectors()))
        self.assertEqual([0, 1, 2, 3], query.get_docids())
        # TODO: do "labels" have to be np array? not a list?
        self.assertEqual([4, 1, 0, 0], query.get_labels().tolist())
        self.assertEqual(1, query.get_label(1))
        self.assertEqual(None, query.get_predictions())
        self.assertEqual(
            ["# highly relevant", "# bad", "# not relevant", "# not relevant"],
            query.get_comments())
        self.assertEqual("# highly relevant", query.get_comment(0))
Exemplo n.º 4
0
 def setUp(self):
     # initialize query
     self.test_num_features = 6
     test_query = """
     4 qid:1 1:2.6 2:1 3:2.1 4:0 5:2 6:1.4 # highly relevant
     1 qid:1 1:1.2 2:1 3:2.9 4:0 5:2 6:1.9 # bad
     0 qid:1 1:0.5 2:1 3:2.3 4:0 5:2 6:5.6 # not relevant
     0 qid:1 1:0.5 2:1 3:2.3 4:0 5:2 6:5.6 # not relevant
     """
     self.query_fh = cStringIO.StringIO(test_query)
     self.queries = query.Queries(self.query_fh, self.test_num_features)
     self.query = self.queries['1']
     # initialize listwise learner
     self.learner = ListwiseLearningSystem(self.test_num_features,
         "--init_weights 0,0,1,0,0,0 --delta 1.0 --alpha 0.01 --ranker "
         "ranker.ProbabilisticRankingFunction --ranker_args 3 --ranker_tie "
         "first --comparison comparison.ProbabilisticInterleaveWithHistory"
         " --comparison_args \"--history_length 10 --biased true\"")
Exemplo n.º 5
0
    def setUp(self):
        self.test_num_features = 6
        test_query = """
        4 qid:1 1:2.6 2:1 3:2.1 4:0 5:2 6:1.4 # highly relevant
        1 qid:1 1:1.2 2:1 3:2.9 4:0 5:2 6:1.9 # bad
        0 qid:1 1:0.5 2:1 3:2.3 4:0 5:2 6:5.6 # not relevant
        0 qid:1 1:0.5 2:1 3:2.3 4:0 5:2 6:5.6 # not relevant
        """

        self.query_fh = cStringIO.StringIO(test_query)
        self.queries = query.Queries(self.query_fh, self.test_num_features)
        self.query = self.queries['1']

        zero_weight_str = "0 0 0 0 0 0"
        self.zero_weights = np.asarray(
            [float(x) for x in zero_weight_str.split()])

        weight_str = "0 0 1 0 0 0"
        self.weights = np.asarray([float(x) for x in weight_str.split()])
Exemplo n.º 6
0
    def setUp(self):
        self.test_num_features = 6
        test_query = """
        1 qid:1 1:2.6 2:1 3:2.1 4:0 5:2 6:1.4 # relevant
        1 qid:1 1:1.2 2:1 3:2.9 4:0 5:2 6:1.9 # relevant
        0 qid:1 1:0.5 2:1 3:2.3 4:0 5:2 6:5.6 # not relevant
        0 qid:1 1:0.5 2:1 3:2.3 4:0 5:2.1 6:5.6 # not relevant
        """

        self.query_fh = cStringIO.StringIO(test_query)
        self.queries = qu.Queries(self.query_fh, self.test_num_features)
        self.query = self.queries['1']

        zero_weight_str = "0 0 0 0 0 0"
        self.zero_weights = np.asarray(
            [float(x) for x in zero_weight_str.split()])

        # results in ranking: 1, 3, 2, 0
        weight_str_1 = "0 0 1 0 1 0"
        self.weights_1 = np.asarray([float(x) for x in weight_str_1.split()])
        weight_str_2 = "1 0 0 0 1 0"
        self.weights_2 = np.asarray([float(x) for x in weight_str_2.split()])
Exemplo n.º 7
0
import os
import cStringIO

sys.path.insert(0, os.path.abspath('..'))

import query
from numpy import array
from PairwiseLearningSystem import PairwiseLearningSystem

# initialize query
test_num_features = 64
f = open('train.txt', 'r')
test_query = f.read()
f.close()
query_fh = cStringIO.StringIO(test_query)
queries = query.Queries(query_fh, test_num_features)
# query = queries['1'] #?


def addRanker(rankers, path):
    f = open(path, 'r')
    str = f.read().lstrip('final_weights: [')
    str = str.rstrip('] \n')
    rankers.append(str)
    f.close()
    return rankers


rankers = []
rankers = addRanker(rankers, 'features64/ranker-00.txt')
# print rankers[0]
Exemplo n.º 8
0
 def test_queries(self):
     query_fh = cStringIO.StringIO(self.test_queries)
     queries = qu.Queries(query_fh, self.test_num_features)
     query_fh.close()
     self.assertEqual(1, queries.get_size())