-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpredict.py
More file actions
45 lines (30 loc) · 858 Bytes
/
predict.py
File metadata and controls
45 lines (30 loc) · 858 Bytes
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
import sys
import numpy as np
import dataset
from model import model
def predict(word):
if len(word) < 3:
print('WARNING: Word is too short to be hyphenated')
return word
model.load_weights('data/model.h5')
windows = dataset.process_word(word.lower(), training=False)
hyphenated = word[:2]
for offset, window in enumerate(windows):
result = model.predict(np.array([window]))
#print('>>> {}{}{} => {: >5.2f} %'.format(
# word[:2 + offset],
# dataset.HYPHENATION_INDICATOR,
# word[2 + offset:],
# result[0][0] * 100
#))
if result[0][0] > 0.5:
hyphenated += dataset.HYPHENATION_INDICATOR
hyphenated += word[offset + 2]
if len(word) > 3:
hyphenated += word[-1:]
return hyphenated
if __name__ == '__main__':
word = sys.argv[1]
prediction = predict(word)
print('Input:', word)
print('Hyphenation:', prediction)