เครื่องมือ AI สำหรับการสืบค้นภาษาธรรมชาติบนข้อมูลแบบตารางสร้างโดยใช้แบบจำลอง QA จากหม้อแปลง
งานนี้อธิบายไว้ในบทความต่อไปนี้:
TableQuery: สอบถามข้อมูลตารางด้วยภาษาธรรมชาติโดย Abhijith Neil Abraham, Fariz Rahman และ Damanpreet Kaur
หากคุณใช้ tableqa โปรดอ้างอิงกระดาษ
นี่คือบล็อกโดยละเอียดเพื่อทำความเข้าใจวิธีการทำงาน
ข้อมูลแบบตารางสามารถ:
-
-
pip install tableqa
git clone https://github.com/abhijithneilabraham/tableQA
cd tableqa
python setup.py install
from tableqa.agent import Agent
agent=Agent(df) #input your dataframe
response=agent.query_db("Your question here")
print(response)
sql=agent.get_query("Your question here")
print(sql) #returns an sql query
{
"name": DATABASE NAME,
"keywords":[DATABASE KEYWORDS],
"columns":
[
{
"name": COLUMN 1 NAME,
"mapping":{
CATEGORY 1: [CATEGORY 1 KEYWORDS],
CATEGORY 2: [CATEGORY 2 KEYWORDS]
}
},
{
"name": COLUMN 2 NAME,
"keywords": [COLUMN 2 KEYWORDS]
},
{
"name": "COLUMN 3 NAME",
"keywords": [COLUMN 3 KEYWORDS],
"summable":"True"
}
]
}
summable รวมอยู่ในคอลัมน์ประเภทตัวเลขที่มีค่าเป็นตัวแทนจำนวนแล้ว เช่น Death Count,Cases ฯลฯ ประกอบด้วยค่าที่แสดงถึงการนับแล้วตัวอย่าง (ด้วยสคีมาด้วยตนเอง):
from tableqa.agent import Agent
agent=Agent(df,schema) #pass the dataframe and schema objects
response=agent.query_db("how many people died of stomach cancer in 2011")
print(response)
#Response =[(22,)]
from tableqa.agent import Agent
agent = Agent(df, schema_file, 'postgres', username='username', password='password', database='DBname', host='localhost', port=5432, aws_db=False)
response=agent.query_db("how many people died of stomach cancer in 2011")
print(response)
#Response =[(22,)]
from tableqa.agent import Agent
agent = Agent(df, schema_file, 'mysql', username='username', password='password', database='DBname', host='localhost', port=5432, aws_db=False)
response=agent.query_db("how many people died of stomach cancer in 2011")
print(response)
#Response =[(22,)]
อ้างถึงขั้นตอนที่ 1 ในเอกสารเพื่อสร้างอินสแตนซ์ MySQL DB ใน Amazon RDS ขั้นตอนเดียวกันสามารถติดตามได้สำหรับการสร้างอินสแตนซ์ PostgreSQL DB โดยเลือก PostgreSQL ในแท็บ Engine รับชื่อผู้ใช้รหัสผ่านฐานข้อมูลปลายทางและพอร์ตจากรายละเอียดการเชื่อมต่อฐานข้อมูลของคุณใน Amazon RDS
from tableqa.agent import Agent
agent = Agent(df, schema_file, 'postgres', username='Master username', password='Master password', database='DB name', host='Endpoint', port='Port', aws_db=True)
response=agent.query_db("how many people died of stomach cancer in 2011")
print(response)
#Response =[(22,)]
sql=agent.get_query("How many people died of stomach cancer in 2011")
print(sql)
#sql query: SELECT SUM(Death_Count) FROM cancer_death WHERE Cancer_site = "Stomach" AND Year = "2011"
csv_path="/content/tableQA/tableqa/cleaned_data"
schema_path="/content/tableQA/tableqa/schema"
agent=Agent(csv_path,schema_path)
csv_path="s3://{bucket}/cleaned_data"
schema_path="s3://{bucket}/schema"
agent = Agent(csv_path, schema_path, aws_s3=True, access_key_id=access_key_id, secret_access_key=secret_access_key)
เข้าร่วม Workspace ของเรา: Slack