-
Notifications
You must be signed in to change notification settings - Fork 0
/
match.py
54 lines (43 loc) · 1.69 KB
/
match.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
# (C) 2018-present Klebert Engineering
import os
import sys
import argparse
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/modules")
from deepspell.baseline.symspell import DSSymSpellBaseline
from deepspell.models.encoder import DSVariationalLstmAutoEncoder
from deepspell.token_lookup_space import DSTokenLookupSpace
arg_parser = argparse.ArgumentParser("NDS AutoCompletion Quality Evaluator")
arg_parser.add_argument(
"--corpus",
default="corpora/deepspell_data_north_america_cities.tsv",
help="Path to the kdtree/token list from which correct matches should be drawn.")
arg_parser.add_argument(
"--encoder",
default="models/deepsp_spell-v2_na-lower_lr003_dec70_bat2048_emb8_fw128_bw128_co256-256_dein256-256_drop75.json",
help="Path to the model JSON descriptor that should be used for token encoding.")
arg_parser.add_argument(
"--baseline",
default=False,
action="store_true",
help="Use this flag in place of --encoder if you wish to use the baseline matcher.")
args = arg_parser.parse_args()
if args.baseline:
spellchecker = DSSymSpellBaseline(args.corpus)
else:
spellchecker = DSTokenLookupSpace(DSVariationalLstmAutoEncoder(args.encoder), args.corpus)
print("""
=============================================================
This is the `deepspell` LSTM DNN spell-match demo for NDS
(C) 2017 Klebert Engineering
=============================================================
Usage:
-> Enter a string that should be encoded/matched.
Have fun!
""")
while True:
user_command = input("> ")
if len(user_command) == 0:
continue
if user_command == "q":
exit(0)
print(spellchecker.match(user_command.lower()))