second version (hopefully working correctly)

This commit is contained in:
Dominik Strzako 2021-05-16 20:09:54 +02:00
parent 9554c3d812
commit 1af80df028

View File

@ -30,6 +30,7 @@ class ML_NLU:
def __init__(self, acts, arguments):
self.acts = acts
self.arguments = arguments
self.model = self.setup()
def nolabel2o(self, line, i):
return 'O' if line[i] == 'NoLabel' else line[i]
@ -66,9 +67,9 @@ class ML_NLU:
else:
fields = ['id', 'form', 'frame', 'slot']
with open('Janet_test.conllu', encoding='utf-8') as trainfile:
with open('Janet.conllu', encoding='utf-8') as trainfile:
trainset = list(parse_incr(trainfile, fields=fields, field_parsers={'slot': self.nolabel2o}))
with open('Janet_test.conllu', encoding='utf-8') as testfile:
with open('Janet.conllu', encoding='utf-8') as testfile:
testset = list(parse_incr(testfile, fields=fields, field_parsers={'slot': self.nolabel2o}))
tabulate(trainset[0], tablefmt='html')
@ -102,10 +103,8 @@ class ML_NLU:
def test_nlu(self, utterance):
model = self.setup()
if utterance:
return tabulate(self.predict(model, 'doktor lekarza rodzinnego najlepiej dzisiaj w godzinach popołudniowych dziś '.split()), tablefmt='html')
return tabulate(self.predict(self.model, 'doktor lekarza rodzinnego najlepiej dzisiaj w godzinach popołudniowych dziś '.split()), tablefmt='html')
else:
return 'Critical Error'