-
Notifications
You must be signed in to change notification settings - Fork 1
/
predict_mode.py
33 lines (23 loc) · 1.17 KB
/
predict_mode.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
from classifiers import Classifier
from langdetect import detect
languages = {'en': 'english', 'fa': 'persian', 'ar': 'persian'}
textfa = '''عالیه!!'''
texten = '''though excessively tiresome , the uncertainty principle , as verbally pretentious as the title may be , has its handful of redeeming features , as long as you discount its ability to bore .'''
lang = detect(textfa)
print(lang)
classifier = Classifier([1], ['+', '-', '='], languages[lang])
# first read dictionary and weights from cache if not read from file
# classifier.hash_dictionary[languages[lang]] = cache[lang]
classifier.load_word_dictionary()
classifier.load_model_npy('perceptron-100-UNIGRAMS-0.4-persian')
# print(classifier.hash_dictionary)
print(classifier.predict_one(textfa))
lang = detect(texten)
print(lang)
classifier = Classifier([1], ['+', '-'], languages[lang])
# first read dictionary and weights from cache if not read from file
# classifier.hash_dictionary[languages[lang]] = cache[lang]
classifier.load_word_dictionary()
classifier.load_model_npy('perceptron-128-UNIGRAMS-0.6_test_size-0.01_random_state-0_shuffle-english')
# print(classifier.hash_dictionary)
print(classifier.predict_one(texten))