Spaces:
Sleeping
Sleeping
File size: 1,464 Bytes
626eca0 |
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 |
import argparse
from pprint import pprint
from typing import Optional
from relik.reader.relik_reader import RelikReader
from relik.reader.utils.strong_matching_eval import StrongMatching
def predict(
model_path: str,
dataset_path: str,
token_batch_size: int,
is_eval: bool,
output_path: Optional[str],
) -> None:
relik_reader = RelikReader(model_path)
predicted_samples = relik_reader.link_entities(
dataset_path, token_batch_size=token_batch_size
)
if is_eval:
eval_dict = StrongMatching()(predicted_samples)
pprint(eval_dict)
if output_path is not None:
with open(output_path, "w") as f:
for sample in predicted_samples:
f.write(sample.to_jsons() + "\n")
def parse_arg() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument(
"--model-path",
required=True,
)
parser.add_argument("--dataset-path", "-i", required=True)
parser.add_argument("--is-eval", action="store_true")
parser.add_argument(
"--output-path",
"-o",
)
parser.add_argument("--token-batch-size", default=4096)
return parser.parse_args()
def main():
args = parse_arg()
predict(
args.model_path,
args.dataset_path,
token_batch_size=args.token_batch_size,
is_eval=args.is_eval,
output_path=args.output_path,
)
if __name__ == "__main__":
main()
|