-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_certlm.py
More file actions
47 lines (41 loc) · 1.42 KB
/
run_certlm.py
File metadata and controls
47 lines (41 loc) · 1.42 KB
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
import logging
import os
import sys
import certlm.registry as registry
from certlm import options
from certlm.answer_gen import run_answer_sampling
from certlm.extractor import run_extract
from certlm.question_generator import run_generation
logging.basicConfig(
format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
level=os.environ.get("LOGLEVEL", "INFO").upper(),
stream=sys.stdout,
)
logger = logging.getLogger(__name__)
def extract_tuples(args):
kg = registry.get_kg(args.kg)(args)
kg.load_relations()
logger.info(f"Loaded {len(kg.relations)} relations in knowledge graph {args.kg}")
run_extract(kg, args.num_workers)
def generate_question(args):
generator = registry.get_question_generator(args.generator)(args)
kg = registry.get_kg(args.kg)(args)
extractor = registry.get_extractor(args.kg)(args)
kg.load_relations()
logger.info(f"Loaded {len(kg.relations)} relations in knowledge graph {args.kg}")
run_generation(generator, extractor, kg, args.num_workers)
def sampling_answer(args):
sampler = registry.get_answer_sampler(args.answer_sampler)(args)
run_answer_sampling(sampler)
def main_cli():
args = options.get_args()
logger.info(args)
if args.step == 'extract':
extract_tuples(args)
elif args.step == 'question_generate':
generate_question(args)
elif args.step == 'answer_sampling':
sampling_answer(args)
if __name__ == '__main__':
main_cli()