Feat: Adds the HMM and detection for one word
This commit is contained in:
43
main.py
Normal file
43
main.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""
|
||||
Note: I code in english but comment in French !
|
||||
"""
|
||||
import data_preparation
|
||||
from HMM import HMM
|
||||
import utils
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
numeric_french_text = data_preparation.prepare_data('french.txt')
|
||||
numeric_english_text = data_preparation.prepare_data('english.txt')
|
||||
numeric_italian_text = data_preparation.prepare_data('italian.txt')
|
||||
|
||||
lambda_fr = HMM('matrice_emission.xls', numeric_french_text)
|
||||
lambda_en = HMM('matrice_emission.xls', numeric_english_text)
|
||||
lambda_it = HMM('matrice_emission.xls', numeric_italian_text)
|
||||
|
||||
numeric_french_word = data_preparation.get_text_in_alphabet_index_form('probablement')
|
||||
|
||||
# On prend le premier mot de la liste (pomme)
|
||||
word = numeric_french_word[0]
|
||||
|
||||
res_fr, _ = lambda_fr.forward(word)
|
||||
res_en, _ = lambda_en.forward(word)
|
||||
res_it, _ = lambda_it.forward(word)
|
||||
|
||||
proba_fr = utils.normalize_probabilities(res_fr, res_en, res_it, res_fr)
|
||||
proba_en = utils.normalize_probabilities(res_fr, res_en, res_it, res_en)
|
||||
proba_it = utils.normalize_probabilities(res_fr, res_en, res_it, res_it)
|
||||
|
||||
print('Résultats forward ---------------------------------------------------')
|
||||
print(f'FR={proba_fr}, EN={proba_en}, IT={proba_it}, Conclusion={max(proba_fr, proba_en, proba_it)}')
|
||||
|
||||
res_back_fr, _ = lambda_fr.backward(word)
|
||||
res_back_en, _ = lambda_en.backward(word)
|
||||
res_back_it, _ = lambda_it.backward(word)
|
||||
|
||||
proba_back_fr = utils.normalize_probabilities(res_back_fr, res_back_en, res_back_it, res_back_fr)
|
||||
proba_back_en = utils.normalize_probabilities(res_back_fr, res_back_en, res_back_it, res_back_en)
|
||||
proba_back_it = utils.normalize_probabilities(res_back_fr, res_back_en, res_back_it, res_back_it)
|
||||
|
||||
print('Résultat backward ---------------------------------------------------')
|
||||
print(f'FR={proba_back_fr}, EN={proba_back_en}, IT={proba_back_it}, Conclusion={max(proba_back_fr, proba_back_en, proba_back_it)}')
|
||||
Reference in New Issue
Block a user