AFAC2024挑战组-赛题一:金融工具学习 | 532193
参赛者需要根据用户的自然语言查询(用户请求),从给定的API集合中筛选出合适的API列表,设计出正确的API调用逻辑(模型回答),并生成准确的答案。
下面先给出一个样本案例,帮助大家理解比赛的目标。
我一年前购买了2000元浙商智选先锋A基金,并且在6个月前追加了3000元,我到现在总的收益是多少?
{
"relevant APIs": [{
"api_id": "0",
"api_name": "查询代码",
"required_parameters": [["浙商智选先锋一年持有期混合型证券投资基金A类"]],
"rely_apis": [],
"tool_name": "基金查询"
}, {
"api_id": "1",
"api_name": "查询近期收益率",
"required_parameters": ["api_0的结果", "1年"],
"rely_apis": ["0"],
"tool_name": "基金查询"
}, {
"api_id": "2",
"api_name": "查询近期收益率",
"required_parameters": ["api_0的结果", "6个月"],
"rely_apis": ["0"],
"tool_name": "基金查询"
}, {
"api_id": "3",
"api_name": "乘法计算",
"required_parameters": ["api_1的结果", "2000"],
"rely_apis": ["1"],
"tool_name": "数值计算"
}, {
"api_id": "4",
"api_name": "乘法计算",
"required_parameters": ["api_2的结果", "3000"],
"rely_apis": ["2"],
"tool_name": "数值计算"
}, {
"api_id": "5",
"api_name": "加法计算",
"required_parameters": ["api_3的结果", "api_4的结果"],
"rely_apis": ["3", "4"],
"tool_name": "数值计算"
}],
"result": ["api_5的结果"]
}
最终得分 = 主指标*0.8 + 副指标*0.2执行准确率(主指标):执行后得到结果的准确率逻辑准确率(副指标):各种出入参的逻辑准确率根据对样本进行分析,再结合一些经验,我们可以总结出比赛的三个要点:
| 用户查询 | 产品名 | 用户意图 | 部分标签 |
|---|---|---|---|
| 我打算用100万元买三羊马的股票,如果按照三羊马的最高价来计算,我能买多少股呢 | 三羊马 | 股票查询 | {"API_id": "0", "API_name": "查询代码", "required_parameters": [["三羊马"]], "rely_APIs": [], "tool_name": "股票查询"} |
| 上周结束的时候,有哪些股票的收盘价是不超过0.47元的呢? | / | 条件选股 | {"API_id": "0", "tool_name": "条件选股", "API_name": "查询收盘价", "required_parameters": ["小于", "0.47", "上周"], "rely_APIs": []} |
| 我今年5月1日用5000块买的国金金腾通C,如果我现在全部卖出,交易费用是多少 | 国金金腾通货币市场证券投资基金C类 | 基金查询 | {"API_id": "0", "API_name": "查询代码", "required_parameters": [["国金金腾通货币市场证券投资基金C类"]], "rely_APIs": [], "tool_name": "基金查询"} |
| 请问有哪些基金最近一个月中最长的解套期是20天,并且在今年已经创下新高达70次的? | / | 条件选基 | {"API_id": "0", "tool_name": "条件选基", "API_name": "查询近期最长解套天数", "required_parameters": ["等于", "20.0", "1个月"], "rely_APIs": []} |
分析完赛题和数据,接下来我们将深入探讨实现方案。
首先给出我们的整体框架。根据实现流程,我们可以将框架分为三个部分:
大模型比赛中最关键的就是prompt设计。这一节我们将深入探讨如何利用意图识别和few-shot技术来设计高质量的Prompt。
需要强调的是,我们采用技术的灵感源自统计学、传统机器学习和推荐系统的相关研究。尽管这些技术在原领域已经得到了广泛应用,但我们通过调整与优化,将它们迁移至大模型场景,并取得了效果。
def match_product(query: str, candidates: list):
# query: 用户请求, e.g. 三羊马今日股价是多少
# candidates: 代表所有可能的产品, e.g. ['三羊马','中国平安','浦发银行', ...]
products = difflib.get_close_matches(query, candidates, n = 200, cutoff=0.01)
pro = []
# 多流量召回
pro += products[:1]
products = sorted(products[1:], key=lambda x: len(LCS(x, query)) / len(x), reverse=True)
pro += products[:4]
products = sorted(products[4:], key=lambda x: len(LCS(x, query)), reverse=True)
pro += products[:4]
products = sorted(products[4:], key=lambda x: len(LSC(x, query)), reverse=True)
pro += products[:4]
# 重排
return sorted(pro, key=lambda x: len(LCS(translate(x), query)) / len(translate(x)), reverse=True)
def get_intention(row):
query = row['query']
# intentions 总共四类意图
intentions = ['基金查询', '股票查询', '条件选基', '条件选股']
# KNN选取每种算法的前五个邻居
for i in range(5):
intentions.append(train.iloc[row[f'edit_{i}']]['label'])
intentions.append(train.iloc[row[f'sim_{i}']]['label'])
intentions.append(train.iloc[row[f'm3e_{i}']]['label'])
intentions.append(train.iloc[row[f'e5_{i}']]['label'])
# 意图修正
if ('股票' in query and not any([x in query for x in ['型', 'A', 'B', 'C', 'D', 'E', 'F']])):
intentions = [x for x in intentions if '股' in x]
elif any([x in query for x in stock_word]):
intentions = [x for x in intentions if '股' in x]
elif any([x in query for x in fund_word]):
intentions = [x for x in intentions if '基' in x]
if any([x in query for x in search_word]) and '(' not in query and '(' not in query:
intentions = [x for x in intentions if '查询' in x]
elif any([x in query for x in select_word]):
intentions = [x for x in intentions if '选' in x]
# 用邻居意图的mode代替
return Counter(intentions).most_common(1)[0][0]
Q1: Shawn有五个玩具。圣诞节,他从他的父母那里得到了两个玩具。他现在有多少个玩具? A1: 他有5个玩具。他从妈妈那里得到了2个,所以在那之后他有5 + 2 = 7个玩具。然后他从爸爸那里得到了2个,所以总共他有7 + 2 = 9个玩具。答案是9。 Q2: 服务器房间里有9台计算机。从周一到周四,每天都会安装5台计算机。现在服务器房间里有多少台计算机? A2: 从周一到周四有4天。每天都添加了5
(注:原文内容至此结束)