-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #819 from PyThaiNLP/add-pythainlp-chat
Add pythainlp.chat and WangChanGLM to pythainlp.generate
- Loading branch information
Showing
9 changed files
with
2,113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.. currentmodule:: pythainlp.chat | ||
|
||
pythainlp.chat | ||
============== | ||
|
||
.. autoclass:: ChatBotModel | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "3ad128a6-2959-431f-b5ff-d9e15761c9c0", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from pythainlp.chat.core import ChatBotModel\n", | ||
"import torch" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "35760aec-f47a-4d33-ad1c-a8230194180c", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"chatbot = ChatBotModel()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "99129184-3a9f-4871-bfb9-ce611e80ff55", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Setting ds_accelerator to cuda (auto detect)\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "54dd6a2c6afa41959bfb11ec98b30562", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"Loading checkpoint shards: 0%| | 0/98 [00:00<?, ?it/s]" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"chatbot.load_model(device=\"cpu\",torch_dtype=torch.bfloat16)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "2f43d3a7-049c-47b4-86a4-7d89cc61f09d", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'ยินดีที่ได้รู้จัก'" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"chatbot.chat(\"สวัสดี\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "736436d8-2c49-466c-ad3e-006b4827274b", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[('สวัสดี', 'ยินดีที่ได้รู้จัก')]" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"chatbot.history" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "cd9bdae5-93c5-4990-ad18-1171148d0a8c", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'ดอกไม้เป็นสิ่งสวยงามที่ธรรมชาติมอบให้มนุษย์ มนุษย์จึงได้นําดอกไม้มาประดับตกแต่งบ้าน สวน ร้านค้า ร้านอาหาร และสถานที่ต่างๆ มากมาย ปัจจุบันมีดอกไม้หลากหลายชนิดให้เราได้เลือกปลูก แต่ละชนิดมีวิธีการปลูกที่แตกต่างกันไป ขึ้นอยู่กับชนิดของดอกไม้นั้นๆ ดังนี้'" | ||
] | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"chatbot.chat(\"แนะนำวิธีปลูกดอกไม้ให้หน่อย\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"id": "73bd8293-f4ad-4bb1-b912-9542cf404d74", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[('สวัสดี', 'ยินดีที่ได้รู้จัก'),\n", | ||
" ('แนะนำวิธีปลูกดอกไม้ให้หน่อย',\n", | ||
" 'ดอกไม้เป็นสิ่งสวยงามที่ธรรมชาติมอบให้มนุษย์ มนุษย์จึงได้นําดอกไม้มาประดับตกแต่งบ้าน สวน ร้านค้า ร้านอาหาร และสถานที่ต่างๆ มากมาย ปัจจุบันมีดอกไม้หลากหลายชนิดให้เราได้เลือกปลูก แต่ละชนิดมีวิธีการปลูกที่แตกต่างกันไป ขึ้นอยู่กับชนิดของดอกไม้นั้นๆ ดังนี้')]" | ||
] | ||
}, | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"chatbot.history" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"id": "3e0bac2d-7ba4-4bf7-aff1-2b47f0223e41", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'ดอกกุหลาบ ปลูกง่าย ดูแลง่าย ให้ดอกดก ทนทาน นิยมปลูกเป็นไม้กระถาง ดินที่ใช้ปลูกควรเป็นดินร่วนซุยผสมปุ๋ยคอกหรือปุ่ยหมัก รดน้ําให้ชุ่มแต่อย่าแฉะเกินไป แสงแดดจัด อุณหภูมิที่เหมาะสมคือ 20-25 องศาเซลเซียส ปุยหมักจะใช้ปุ้ยหอยหรือแกลบดิบก็ได้ ต้นกุหลายจะออกดอกในช่วงเดือนมีนาคม-เมษายน'" | ||
] | ||
}, | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"chatbot.chat(\"ขอรายละเอียดเพิ่มเติมหน่อย\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"id": "c047ee41-3850-4d0d-88af-6e659b2b2acb", | ||
"metadata": { | ||
"tags": [] | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[('สวัสดี', 'ยินดีที่ได้รู้จัก'),\n", | ||
" ('แนะนำวิธีปลูกดอกไม้ให้หน่อย',\n", | ||
" 'ดอกไม้เป็นสิ่งสวยงามที่ธรรมชาติมอบให้มนุษย์ มนุษย์จึงได้นําดอกไม้มาประดับตกแต่งบ้าน สวน ร้านค้า ร้านอาหาร และสถานที่ต่างๆ มากมาย ปัจจุบันมีดอกไม้หลากหลายชนิดให้เราได้เลือกปลูก แต่ละชนิดมีวิธีการปลูกที่แตกต่างกันไป ขึ้นอยู่กับชนิดของดอกไม้นั้นๆ ดังนี้'),\n", | ||
" ('ขอรายละเอียดเพิ่มเติมหน่อย',\n", | ||
" 'ดอกกุหลาบ ปลูกง่าย ดูแลง่าย ให้ดอกดก ทนทาน นิยมปลูกเป็นไม้กระถาง ดินที่ใช้ปลูกควรเป็นดินร่วนซุยผสมปุ๋ยคอกหรือปุ่ยหมัก รดน้ําให้ชุ่มแต่อย่าแฉะเกินไป แสงแดดจัด อุณหภูมิที่เหมาะสมคือ 20-25 องศาเซลเซียส ปุยหมักจะใช้ปุ้ยหอยหรือแกลบดิบก็ได้ ต้นกุหลายจะออกดอกในช่วงเดือนมีนาคม-เมษายน')]" | ||
] | ||
}, | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"chatbot.history" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "0b77ea2f-df5a-442b-a5ae-537511479d8e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.