"tools/docker/centos_8.dockerfile" did not exist on "6d937d8099a87984f926db3b84d23c77545488a3"
webqs.py 1.66 KB
Newer Older
1
from . common import HFTask
2
from lm_eval.base import mean, rf
Leo Gao's avatar
Leo Gao committed
3

4
class WebQs(HFTask):
Leo Gao's avatar
Leo Gao committed
5
6
    DATASET_PATH = "web_questions"
    DATASET_NAME = None
Leo Gao's avatar
Leo Gao committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20

    def has_training_docs(self):
        return True

    def has_validation_docs(self):
        return False

    def has_test_docs(self):
        return True

    def fewshot_description(self):
        # TODO: figure out description
        return ""

21
22
    def doc_to_text(self, doc):
        return "Q: " + doc['question'] + '\nA:'
Leo Gao's avatar
Leo Gao committed
23

24
    def doc_to_target(self, doc):
Leo Gao's avatar
Leo Gao committed
25
26
27
        # this picks one answer to be the "correct" one, despite sometimes 
        # multiple correct answers being possible.
        # TODO: make sure we're actually handling multi-answer correctly
28
        return " " + doc['answers'][0]
29
30
31
32
33
34
35
36
37
38
39
40
        
    def _remove_prefixes(self, aliases):
        # Optimization: Remove any alias that has a strict prefix elsewhere in the list
        # we can do this because if the prefix is acceptable by isgreedy, we can stop looking
        aliases.sort()
        ret = [aliases[0]]
        for alias in aliases[1:]:
            if not alias.startswith(ret[-1]):
                ret.append(alias)

        return ret
        
Leo Gao's avatar
Leo Gao committed
41

Leo Gao's avatar
Leo Gao committed
42
    def construct_requests(self, doc, ctx):
43
44
45
46
47
        ret = []
        for alias in self._remove_prefixes(doc['answers']):
            _, is_prediction = rf.loglikelihood(ctx, " " + alias)
            ret.append(is_prediction)
        return ret
48

Leo Gao's avatar
Leo Gao committed
49
    def process_results(self, doc, results):
50
51
52
        return {
            "acc": float(any(results))
        }
Leo Gao's avatar
Leo Gao committed
53
54

    def aggregation(self):
55
56
57
        return {
            "acc": mean,
        }
Leo Gao's avatar
Leo Gao committed
58
59

    def higher_is_better(self):
60
61
62
        return {
            "acc": True
        }