tableQA
1.0.0
Tabular Dataで自然言語を照会するための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を参照して、Amazon RDSでMySQL DBインスタンスを作成します。 [エンジン]タブでPostgreSQLを選択して、PostgreSQL DBインスタンスを作成するために同じ手順に従うことができます。 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)
ワークスペースに参加:Slack