# Domain-Specific Few-Shot Table Prompt Question Answering via Contrastive Exemplar Selection
## 3 Methodology
### Exemplar Retrieval Approach
An example application of ESQL is shown in Algorithm 3, where the input exemplar question is \"For projects with an estimated net profit year-on-year growth rate (compared to the previous period) below 44.33% and project estimated total profit (excluding price reduction impact) higher than 3471.44, what is the average project estimated total profit?\" The exemplar retrieval strategy proposed in this paper injects exemplars similar in semantics to this question from the same table to guide the model in parsing the text-to-SQL task. Similarly, Algorithm 4 shows an application example in SMI-SQL. For the question \"How many provincial-level departments are there?\", the method proposed retrieves the formatted representation of the most relevant question in the training set, \"How many municipal-level departments are there?\" as a prompt output to guide the model in generating the correct SQL statement. ```
Input 1: Question: For projects with an estimated net profit year-on-year growth rate (compared to the previous period) below 44.33% and project estimated total profit (excluding price re-duction impact) higher than 3471.44, what is the average project estimated total profit? 2: Table Name: table_6
```  
Example 1:  
```
1: Question: What is the lowest estimated net profit year-on-year growth rate (compared to the previous period) in projects with funding source types and year-end balances equal to 3975.46 and 1985.13, respectively? 2: Expected SQL Query Result:
```
1: [-1.5 pt]
2: [-1.5 pt]
3: [-1.5 pt]
4: \"sql\": \"select MIN(estimated net profit year-on-year growth (compared to the previous period)) from table_6 where funding source type = '3975.46' and year-end balance = '1985.13\", 5: \"Aggregation Function\": \"MIN\", 6: \"Query Column\": \"estimated net profit year-on-year growth (compared to the previous period)\", 7: \"where condition columns\": [\"funding source type\", \"year-end balance\"], 8: \"where condition operators\": [\"=\", \"=\"], 9: \"where condition values\": [\"3975.46\", \"1985.13\"], 10: \"where condition count\": \"2\" ```
**Algorithm 3** ESQL Application Example
``` Input 1: Question: How many provincial-level departments are there? 2: Table Name: cbms_dept ```
Example 1:
```
1: Question: How many municipal-level departments are there? 2: Expected SQL Query Result:

```
1: [-1.5 pt]
2: [-1.5 pt]
3: [-1.5 pt]
4: \"sql\": \"select COUNT(DepartmentCode) from cbms_dept where Department-Level ='municipal\", 5: \"Aggregation Function\": \"COUNT\", 6: \"Query Column\": \"DepartmentCode\", 7: \"Where Condition Columns\": [\"DepartmentLevel\"], 8: \"Where Condition Operators\": [\"=\"], 9: \"Where Condition Values\": [\"municipal\"], 10: \"Where Condition Count\": \"1\"
```

**Algorithm 4** SMI-SQL Application Example

## 4 Experiments

### Experimental Settings

This study conducted extensive experiments on the ESQL and SMI-SQL datasets, injecting \(1\) prompt training exemplar for each test data to guide the model output. Regarding the selection of the number of examples, we chose one exemplar for each input. The reason for not selecting multiple examples is that, in our preliminary experiments, we tried selecting from \(1\) to \(5\) examples and found that choosing one exemplar yielded the best results. Multiple examples led to model learning biases and formatting errors, with five examples exceeding the maximum length limit. It is worth noting that the experiment requires at least one exemplar; for instance, this study uses one exemplar. However, the number of examples needed may vary across different domains and should be determined based on the specific circumstances. During testing, \(1500\) data points were used. The sample sizes for each dataset used in the experiments are shown in Table 2.

The experiments were conducted on a platform based on Linux 5.15.0 Ubuntu 20.04 64-bit operating system and PyTorch 1.13.1 deep learning framework. The hardware environment included an Intel Core i9-10900X CPU, 128 GB RAM, 4 NVIDIA RTX-3090 Ti 24 GB GPUs, and a 4 TB hard drive.