MCPcopy Create free account
hub / github.com/PaddlePaddle/Research / decode

Function decode

NLP/Text2SQL-BASELINE/text2sql/dataproc/sql_label.py:192–273  ·  view source on GitHub ↗

decode one instance predicts to sql

(sel_num, sel_col, sel_agg,
           where_num, where_conn, where_op, where_op_prob, col_value,
           order_direction, order_col, order_agg, limit_label,
           group_num, having_num, group_col, having_agg, having_agg_prob,
           header_match_cells, candi_limit_nums)

Source from the content-addressed store, hash-verified

190
191
192def decode(sel_num, sel_col, sel_agg,
193 where_num, where_conn, where_op, where_op_prob, col_value,
194 order_direction, order_col, order_agg, limit_label,
195 group_num, having_num, group_col, having_agg, having_agg_prob,
196 header_match_cells, candi_limit_nums):
197 """decode one instance predicts to sql"""
198 if col_value is None:
199 col_value = [None] * len(where_op)
200 # 这里通过词典找label对应的数量,其实相当于加1(与encode对应)
201 sel_num = SQL.sel_num_dict[int(sel_num)]
202 sorted_sel_index = sorted(range(len(sel_col)), key=lambda i: sel_col[i], reverse=True)
203 sel_col = [int(col_id) for col_id in sorted_sel_index][:sel_num]
204 sel_agg = [int(sel_agg[col_id]) for col_id in sorted_sel_index][:sel_num]
205
206 cond_num = SQL.cond_num_dict[int(where_num)]
207 where_conn = int(where_conn)
208 cond_probs = []
209 conds = []
210 for col_id, (cond_op, cond_prob, value_id) in enumerate(zip(where_op, where_op_prob, col_value)):
211 if cond_op < len(SQL.op_sql_dict):
212 cond_probs.append(cond_prob)
213 value = get_value_by_id(col_id, value_id, header_match_cells)
214 conds.append([col_id, int(cond_op), value])
215 if cond_num < len(conds):
216 sorted_cond_index = sorted(range(len(cond_probs)), key=lambda i: cond_probs[i], reverse=True)
217 conds = [conds[i] for i in sorted_cond_index[:cond_num]]
218
219 if group_num is None:
220 group_num = 0
221 if group_num > 0:
222 sorted_group_index = sorted(range(len(group_col)), key = lambda i: group_col[i], reverse=True)
223 group_col = [int(col_id) for col_id in sorted_group_index[:group_num]]
224 else:
225 group_col = []
226
227 having = []
228 if having_num is None:
229 having_num = 0
230 if having_agg is not None and group_num > 0 and having_num > 0:
231 having_agg_info = []
232 for idx, (col_id, _, _) in enumerate(conds):
233 if having_agg[col_id] > 0:
234 having_agg_info.append([idx, int(having_agg[col_id]), float(having_agg_prob[col_id])])
235 #cond_num -= 1
236 if len(having_agg_info) > 0 and having_agg_info[0][2] >= g_having_agg_threshold:
237 # 按 agg 概率最大排序
238 having_agg_info.sort(key=lambda x: x[2], reverse=True)
239 idx, agg, _ = having_agg_info[0]
240 having = [[agg] + list(conds[idx])]
241 conds.pop(idx)
242
243 order_direction = int(order_direction) if order_direction is not None else 0
244 if order_direction == 0 or order_col is None or order_agg is None:
245 order_by = []
246 limit = '0'
247 else:
248 sorted_order_index = sorted(range(len(order_col)), key = lambda i: order_col[i], reverse=True)
249 order_col = [int(col_id) for col_id in sorted_order_index[:1]]

Callers 1

decode_sqlsFunction · 0.70

Calls 3

get_value_by_idFunction · 0.85
popMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected