เราสามารถสร้าง Chatbot(แช็ด - บ่อด) โดยใช้ไลบรารี่ตัวหนึ่งในภาษา Python ชื่อ Chatterbot(แช็ด - เตอ - บ่อด) ซึ่งมันเป็น machine learning(แมด - ชีน - เลิน - นิ่ง) ที่สำหรับเอาไว้สร้าง chat bots โดยเฉพาะ
วิธีใช้งาน
1. ติดตั้ง
Anaconda
2. แล้วติดตั้ง Chatterbot ด้วยคำสั่ง
EX.1
เมื่อป้อนบทสนทนาอย่างง่าย
โค้ด: เลือกทั้งหมด
# -*- coding: utf-8 -*-
from chatterbot import ChatBot
# Create a new chat bot named Charlie
chatbot = ChatBot(
'Charlie',
trainer='chatterbot.trainers.ListTrainer'
)
chatbot.train([
"Hi, can I help you?",
"Sure, I'd to book a flight to Iceland.",
"Your flight has been booked."
])
# Get a response to the input text 'How are you?'
response = chatbot.get_response('I would like to book a flight.')
print(response)
จะได้ผลลัพธ์
Your flight has been booked.
EX.2
เมื่อป้อนคำถามให้คำนวณทางคณิตศาสตร์ และถามเวลา
โค้ด: เลือกทั้งหมด
# -*- coding: utf-8 -*-
from chatterbot import ChatBot
bot = ChatBot(
"Math & Time Bot",
logic_adapters=[
"chatterbot.logic.MathematicalEvaluation",
"chatterbot.logic.TimeLogicAdapter"
],
input_adapter="chatterbot.input.VariableInputTypeAdapter",
output_adapter="chatterbot.output.OutputAdapter"
)
# Print an example of getting one math based response
response = bot.get_response("What is 4 + 9?")
print(response)
# Print an example of getting one time based response
response = bot.get_response("What time is it?")
print(response)
จะได้ผลลัพธ์
( 4 + 9 ) = 13
The current time is 10:15 PM
เราสามารถสร้าง Chatbot(แช็ด - บ่อด) โดยใช้ไลบรารี่ตัวหนึ่งในภาษา Python ชื่อ Chatterbot(แช็ด - เตอ - บ่อด) ซึ่งมันเป็น machine learning(แมด - ชีน - เลิน - นิ่ง) ที่สำหรับเอาไว้สร้าง chat bots โดยเฉพาะ
[b]วิธีใช้งาน[/b]
1. ติดตั้ง [url=https://www.continuum.io/downloads]Anaconda[/url]
2. แล้วติดตั้ง Chatterbot ด้วยคำสั่ง
[code]pip install chatterbot[/code]
[b]EX.1[/b]
เมื่อป้อนบทสนทนาอย่างง่าย
[code]# -*- coding: utf-8 -*-
from chatterbot import ChatBot
# Create a new chat bot named Charlie
chatbot = ChatBot(
'Charlie',
trainer='chatterbot.trainers.ListTrainer'
)
chatbot.train([
"Hi, can I help you?",
"Sure, I'd to book a flight to Iceland.",
"Your flight has been booked."
])
# Get a response to the input text 'How are you?'
response = chatbot.get_response('I would like to book a flight.')
print(response)[/code]
[b]จะได้ผลลัพธ์[/b]
Your flight has been booked.
[b]EX.2[/b]
เมื่อป้อนคำถามให้คำนวณทางคณิตศาสตร์ และถามเวลา
[code]# -*- coding: utf-8 -*-
from chatterbot import ChatBot
bot = ChatBot(
"Math & Time Bot",
logic_adapters=[
"chatterbot.logic.MathematicalEvaluation",
"chatterbot.logic.TimeLogicAdapter"
],
input_adapter="chatterbot.input.VariableInputTypeAdapter",
output_adapter="chatterbot.output.OutputAdapter"
)
# Print an example of getting one math based response
response = bot.get_response("What is 4 + 9?")
print(response)
# Print an example of getting one time based response
response = bot.get_response("What time is it?")
print(response)[/code]
[b]จะได้ผลลัพธ์[/b]
( 4 + 9 ) = 13
The current time is 10:15 PM