Skip to content

Commit b61bc1b

Browse files
committed
remove other and orth error types from grammar_model.py chat history
1 parent fab64df commit b61bc1b

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

chatbot/grammar_correction.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class GrammarModel(Gramformer):
99
"""
1010
def __init__(self, models=1, use_gpu=False, seed=1212):
1111
self.gm = super().__init__(models=1, use_gpu=False)
12-
12+
self.ignore_errors = ['OTHER', 'ORTH']
1313

1414
def grammar_correction(self,last_user_input):
1515
"""
@@ -39,8 +39,9 @@ def add_correction_to_chat_history(self, chat_history):
3939
last_user_input = chat_history[-1].get('text')
4040
corrected_sentence, correction_message = self.grammar_correction(last_user_input)
4141
error_types = self.get_edits(last_user_input, corrected_sentence)
42+
overlap_ignore_errors = any(item in error_types for item in self.ignore_errors)
4243

43-
if correction_message:
44+
if correction_message and (overlap_ignore_errors is False):
4445
chat_history.append(
4546
{
4647
'sender': 'bot',

chatbot/notebooks/grammar_model_improvements.ipynb

+14-12
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
},
216216
{
217217
"cell_type": "code",
218-
"execution_count": 255,
218+
"execution_count": 327,
219219
"metadata": {},
220220
"outputs": [],
221221
"source": [
@@ -225,7 +225,7 @@
225225
" \"\"\"\n",
226226
" def __init__(self, models=1, use_gpu=False, seed=1212):\n",
227227
" self.gm = super().__init__(models=1, use_gpu=False)\n",
228-
" #self.ignore_error_types = [['OTHER'], ['ORTH']]\n",
228+
" self.ignore_errors = ['OTHER', 'ORTH']\n",
229229
"\n",
230230
"\n",
231231
" def grammar_correction(self,last_user_input):\n",
@@ -256,11 +256,9 @@
256256
" last_user_input = chat_history[-1].get('text')\n",
257257
" corrected_sentence, correction_message = self.grammar_correction(last_user_input)\n",
258258
" error_types = self.get_edits(last_user_input, corrected_sentence)\n",
259-
" ignore_error_types = ['OTHER', 'ORTH']\n",
260-
" set1 = set(error_types)\n",
261-
" set2 = set(ignore_error_types)\n",
259+
" overlap_ignore_errors = any(item in error_types for item in self.ignore_errors)\n",
262260
"\n",
263-
" if correction_message and (set1.intersection(set2) == True):\n",
261+
" if correction_message and (overlap_ignore_errors is False):\n",
264262
" chat_history.append(\n",
265263
" {\n",
266264
" 'sender': 'bot',\n",
@@ -297,7 +295,7 @@
297295
},
298296
{
299297
"cell_type": "code",
300-
"execution_count": 256,
298+
"execution_count": 328,
301299
"metadata": {},
302300
"outputs": [
303301
{
@@ -314,7 +312,7 @@
314312
},
315313
{
316314
"cell_type": "code",
317-
"execution_count": 257,
315+
"execution_count": 341,
318316
"metadata": {},
319317
"outputs": [],
320318
"source": [
@@ -323,7 +321,7 @@
323321
},
324322
{
325323
"cell_type": "code",
326-
"execution_count": 262,
324+
"execution_count": 342,
327325
"metadata": {},
328326
"outputs": [],
329327
"source": [
@@ -332,16 +330,20 @@
332330
},
333331
{
334332
"cell_type": "code",
335-
"execution_count": 263,
333+
"execution_count": 343,
336334
"metadata": {},
337335
"outputs": [
338336
{
339337
"data": {
340338
"text/plain": [
341-
"[{'sender': 'User', 'text': 'Hi bot'}]"
339+
"[{'sender': 'User', 'text': 'Hi bot'},\n",
340+
" {'sender': 'bot',\n",
341+
" 'text': 'This would be better said like this: \"Hi booch!\" ',\n",
342+
" 'correction': True,\n",
343+
" 'error_type': ['NOUN']}]"
342344
]
343345
},
344-
"execution_count": 263,
346+
"execution_count": 343,
345347
"metadata": {},
346348
"output_type": "execute_result"
347349
}

0 commit comments

Comments
 (0)