|
215 | 215 | },
|
216 | 216 | {
|
217 | 217 | "cell_type": "code",
|
218 |
| - "execution_count": 255, |
| 218 | + "execution_count": 327, |
219 | 219 | "metadata": {},
|
220 | 220 | "outputs": [],
|
221 | 221 | "source": [
|
|
225 | 225 | " \"\"\"\n",
|
226 | 226 | " def __init__(self, models=1, use_gpu=False, seed=1212):\n",
|
227 | 227 | " 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", |
229 | 229 | "\n",
|
230 | 230 | "\n",
|
231 | 231 | " def grammar_correction(self,last_user_input):\n",
|
|
256 | 256 | " last_user_input = chat_history[-1].get('text')\n",
|
257 | 257 | " corrected_sentence, correction_message = self.grammar_correction(last_user_input)\n",
|
258 | 258 | " 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", |
262 | 260 | "\n",
|
263 |
| - " if correction_message and (set1.intersection(set2) == True):\n", |
| 261 | + " if correction_message and (overlap_ignore_errors is False):\n", |
264 | 262 | " chat_history.append(\n",
|
265 | 263 | " {\n",
|
266 | 264 | " 'sender': 'bot',\n",
|
|
297 | 295 | },
|
298 | 296 | {
|
299 | 297 | "cell_type": "code",
|
300 |
| - "execution_count": 256, |
| 298 | + "execution_count": 328, |
301 | 299 | "metadata": {},
|
302 | 300 | "outputs": [
|
303 | 301 | {
|
|
314 | 312 | },
|
315 | 313 | {
|
316 | 314 | "cell_type": "code",
|
317 |
| - "execution_count": 257, |
| 315 | + "execution_count": 341, |
318 | 316 | "metadata": {},
|
319 | 317 | "outputs": [],
|
320 | 318 | "source": [
|
|
323 | 321 | },
|
324 | 322 | {
|
325 | 323 | "cell_type": "code",
|
326 |
| - "execution_count": 262, |
| 324 | + "execution_count": 342, |
327 | 325 | "metadata": {},
|
328 | 326 | "outputs": [],
|
329 | 327 | "source": [
|
|
332 | 330 | },
|
333 | 331 | {
|
334 | 332 | "cell_type": "code",
|
335 |
| - "execution_count": 263, |
| 333 | + "execution_count": 343, |
336 | 334 | "metadata": {},
|
337 | 335 | "outputs": [
|
338 | 336 | {
|
339 | 337 | "data": {
|
340 | 338 | "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']}]" |
342 | 344 | ]
|
343 | 345 | },
|
344 |
| - "execution_count": 263, |
| 346 | + "execution_count": 343, |
345 | 347 | "metadata": {},
|
346 | 348 | "output_type": "execute_result"
|
347 | 349 | }
|
|
0 commit comments