|
import logging |
|
import time |
|
from omegaconf.omegaconf import OmegaConf, open_dict |
|
|
|
import sys |
|
|
|
sys.path.append(".") |
|
from src.hydra_runner import hydra_runner |
|
from src.embed import generate_passage_embeddings |
|
from src.index import build_index |
|
from src.search import search_topk, post_hoc_merge_topk_multi_domain |
|
from src.evaluate_perplexity import evaluate_perplexity |
|
|
|
|
|
@hydra_runner(config_path="conf", config_name="default") |
|
def main(cfg) -> None: |
|
logging.info("\n\n************** Experiment configuration ***********") |
|
logging.info(f"\n{OmegaConf.to_yaml(cfg)}") |
|
|
|
embedding_gen_time_start = time.time() |
|
if cfg.tasks.datastore.get("embedding", False): |
|
logging.info("\n\n************** Building Embedding ***********") |
|
generate_passage_embeddings(cfg) |
|
embedding_gen_time_end = time.time() |
|
logging.info( |
|
f"Embedding generation took {embedding_gen_time_end - embedding_gen_time_start} seconds." |
|
) |
|
|
|
indexing_start_time = time.time() |
|
if cfg.tasks.datastore.get("index", False): |
|
logging.info("\n\n************** Indexing ***********") |
|
build_index(cfg) |
|
indexing_end_time = time.time() |
|
logging.info(f"Indexing took {indexing_end_time - indexing_start_time} seconds.") |
|
if cfg.tasks.eval.get("search", False): |
|
logging.info("\n\n************** Running Search ***********") |
|
start_time = time.time() |
|
search_topk(cfg) |
|
end_time = time.time() |
|
logging.info(f"Search took {end_time - start_time} seconds.") |
|
|
|
if cfg.tasks.eval.get("merge_search", False): |
|
logging.info( |
|
"\n\n************** Post Merging Searched Results from Multiple Domains ***********" |
|
) |
|
post_hoc_merge_topk_multi_domain(cfg) |
|
|
|
if cfg.tasks.eval.get("inference", False): |
|
logging.info("\n\n************** Running Perplexity Evaluation ***********") |
|
inference_start_time = time.time() |
|
outputs = evaluate_perplexity(cfg) |
|
inference_end_time = time.time() |
|
print(f"Inference took {inference_end_time - inference_start_time} seconds.") |
|
log_results_separately(cfg, outputs) |
|
|
|
|
|
def log_results_separately(cfg, outputs): |
|
if cfg.evaluation.get("results_only_log_file", None): |
|
with open(cfg.evaluation.results_only_log_file, "a+") as file: |
|
file.write("\n") |
|
file.write(outputs.log_message()) |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |
|
|