-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
201 lines (153 loc) · 4.99 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import logging
import os
import torch
from enum import Enum
from typing import Optional
from pathlib import Path
from pydantic import BaseModel
logging.basicConfig(
level=logging.INFO,
format='[%(asctime)s %(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
if not OPENAI_API_KEY:
raise ValueError("OPENAI_API_KEY is not set")
DATA_PATH = Path("data")
DATA_PATH.mkdir(exist_ok=True)
REFERENCE_DATA_PATH = DATA_PATH / "reference"
REFERENCE_DATA_PATH.mkdir(exist_ok=True)
REFERENCE_HTML_DATA_PATH = REFERENCE_DATA_PATH / "html"
REFERENCE_HTML_DATA_PATH.mkdir(exist_ok=True)
REFERENCE_PDFS_PATH = REFERENCE_DATA_PATH / "pdf"
REFERENCE_PDFS_PATH.mkdir(exist_ok=True)
INDEX_DATA_PATH = DATA_PATH / "index"
INDEX_DATA_PATH.mkdir(exist_ok=True)
EVAL_DATA_PATH = DATA_PATH / "evaluation"
EVAL_DATA_PATH.mkdir(exist_ok=True)
OUTPUTS_DATA_PATH = DATA_PATH / "predictions"
OUTPUTS_DATA_PATH.mkdir(exist_ok=True)
RESULTS_DATA_PATH = DATA_PATH / "results"
RESULTS_DATA_PATH.mkdir(exist_ok=True)
INDEX_CHUNK_SIZE = 256
HF_OCR_MODEL_NAME = "facebook/nougat-small"
HF_OCR_MODEL_DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
MAX_OCR_TOKENS_PER_PAGE = 3500
MAX_OCR_PARALLEL_PAGES = 10
LLM_TEMPERATURE = 0.0
REFERENCE_PDF_TEXTBOOK_FILENAME = "textbook.pdf"
REFERENCE_PDF_OUTLINE_FILENAME = "outline.json"
REFERENCE_PDF_CONTENTS_FILENAME = "contents.json"
REFERENCE_PDF_PAGES_SUBDIR_NAME = "pages"
REFERENCE_PDF_PAGE_FILENAME_PREFIX = "page"
REFERENCE_PDF_PAGE_FILENAME_SUFFIX = ".mmd"
class TextbookSubfield(Enum):
Algebra = "algebra"
Calculus = "calculus"
Combinatorics = "combinatorics"
class TextbookIdentifier(BaseModel):
name: str
source_url: str
subfield: str
REFERENCE_HTML_TEXTBOOKS = [
TextbookIdentifier(
name="openstax",
source_url="https://openstax.org/books/prealgebra-2e/pages/1-introduction",
subfield=TextbookSubfield.Algebra.value
)
]
REFERENCE_PDF_TEXTBOOKS = [
TextbookIdentifier(
name="stitz",
source_url="https://stitz-zeager.com/szprecalculus07042013.pdf",
subfield=TextbookSubfield.Calculus.value
),
TextbookIdentifier(
name="guichard",
source_url="https://www.whitman.edu/mathematics/multivariable/multivariable.pdf",
subfield=TextbookSubfield.Calculus.value
),
TextbookIdentifier(
name="adams",
source_url="https://www.mathematicalgemstones.com/maria/OER/CountingRocks-Nov2023.pdf",
subfield=TextbookSubfield.Combinatorics.value
),
TextbookIdentifier(
name="keller",
source_url="https://www.rellek.net/book-2017/app-comb-2017.pdf",
subfield=TextbookSubfield.Combinatorics.value
),
TextbookIdentifier(
name="austin",
source_url="https://scholarworks.gvsu.edu/cgi/viewcontent.cgi?article=1026&context=books",
subfield=TextbookSubfield.Algebra.value
),
TextbookIdentifier(
name="boyd",
source_url="https://web.stanford.edu/~boyd/vmls/vmls.pdf",
subfield=TextbookSubfield.Algebra.value
)
]
class EmbeddingModel(BaseModel):
model: str
name: str
dim: int
EMBEDDING_MODELS = [
EmbeddingModel(
model="BAAI/bge-small-en-v1.5",
name="bge-small-en-v1.5",
dim=384
),
EmbeddingModel(
model="BAAI/bge-large-en-v1.5",
name="bge-large-en-v1.5",
dim=1024
)
]
class IndexingStrategy(Enum):
Subfield = "subfield"
Textbook = "textbook"
class RetrievalStrategy(Enum):
Nearby = "nearby"
Section = "section"
class PromptingStrategy(Enum):
Basic = "basic"
COT = "cot"
COT_SC = "cot_sc"
TOT = "tot"
RAG_TOP5_NEARBY200 = "rag_top5_nearby200"
RAG_TOP2_NEARBY500 = "rag_top2_nearby500"
RAG_TOP2_NEARBY200 = "rag_top2_nearby200"
RAG_TOP1_NEARBY500 = "rag_top1_nearby500"
RAG_TOP1_NEARBY200 = "rag_top1_nearby200"
class LLM(Enum):
ChatGPT35 = "gpt-3.5-turbo"
class EvaluationDataset(Enum):
TheoremQA = "theoremqa"
class IndexConfig(BaseModel):
indexing_strategy: IndexingStrategy
index_name: str
class Experiment(BaseModel):
llm: LLM
embedding_model: Optional[EmbeddingModel]
prompting_strategy: PromptingStrategy
index_config: Optional[IndexConfig]
evaluation_dataset: EvaluationDataset
def to_string(self) -> str:
s1 = self.llm.value
s2 = self.prompting_strategy.value
s3 = (
f"{self.index_config.indexing_strategy.value}_{self.index_config.index_name}_{self.embedding_model.name}"
if self.index_config is not None
else "noindex"
)
s4 = self.evaluation_dataset.value
return f"{s1}_{s2}_{s3}_{s4}"
class Prompt(BaseModel):
user_prompt: str
class MultiRolePrompt(Prompt):
system_prompt: str
def get_index_path(
index_name: str, embedding_model: EmbeddingModel, indexing_strategy: IndexingStrategy
) -> Path:
return INDEX_DATA_PATH / embedding_model.name / indexing_strategy.value / index_name