instance.py 1.04 KB
Newer Older
1
from dataclasses import dataclass, field
2
3
4
5
6
7
from typing import Literal, Optional, Tuple


OutputType = Literal[
    "loglikelihood", "loglikelihood_rolling", "generate_until", "multiple_choice"
]
8

lintangsutawika's avatar
lintangsutawika committed
9

10
11
@dataclass
class Instance:
12
    request_type: OutputType
haileyschoelkopf's avatar
haileyschoelkopf committed
13
14
15
    doc: dict
    arguments: tuple
    idx: int
16
    metadata: Tuple[Optional[str], Optional[int], Optional[int]] = field(
haileyschoelkopf's avatar
haileyschoelkopf committed
17
        default_factory=lambda: (None, None, None)
18
    )
19
20
21
    resps: list = field(default_factory=list)
    filtered_resps: dict = field(default_factory=dict)

22
    # initialized after init
23
24
25
    task_name: Optional[str] = None
    doc_id: Optional[int] = None
    repeats: Optional[int] = None
26

Ethan Smith's avatar
Ethan Smith committed
27
    def __post_init__(self) -> None:
haileyschoelkopf's avatar
haileyschoelkopf committed
28
        # unpack metadata field
29
        self.task_name, self.doc_id, self.repeats = self.metadata
lintangsutawika's avatar
lintangsutawika committed
30

31
32
33
34
35
    @property
    def args(self):
        """
        Returns (string,) where `string` is the string to calculate loglikelihood over
        """
lintangsutawika's avatar
lintangsutawika committed
36
37
38
        return (
            self.arguments if isinstance(self.arguments, tuple) else (self.arguments,)
        )