Update README.md
Browse files
README.md
CHANGED
|
@@ -50,10 +50,16 @@ I had three benchmarks, the WikiTableQuestions dataset, the TabFact dataset, and
|
|
| 50 |
| mistralai/Mistral-7B-Instruct-v0.3 | 0 | Exact Match: 0.0346 Fuzzy Match: 0.4744 | | | | |
|
| 51 |
| meta-llama/Llama-3.2-1B | 0.0133 | | | | | |
|
| 52 |
|
| 53 |
-
## Usage
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
|
| 56 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
question = "How many Hardware Upgrade changes are still pending?"
|
| 58 |
table_df = pd.DataFrame({
|
| 59 |
"change_id": [
|
|
@@ -87,19 +93,12 @@ table_df = pd.DataFrame({
|
|
| 87 |
"2023-05-30"
|
| 88 |
]
|
| 89 |
})
|
| 90 |
-
```
|
| 91 |
|
| 92 |
-
Or you could define table in json format and then have table = pd.DataFrame(table) in your tokenizer.
|
| 93 |
-
|
| 94 |
-
## Expected Output Format
|
| 95 |
-
You tokenize the inputs and then perform a specific function to get outputs, which are the aggregation operation, answer, and predicted_cells. You can just grab the middle value which is the predicted answer.
|
| 96 |
-
```python
|
| 97 |
# Tokenize both Question and Table together
|
| 98 |
inputs = tokenizer(table=table_df, queries=[question], padding='max_length', return_tensors='pt')
|
| 99 |
|
| 100 |
# Model prediction
|
| 101 |
-
|
| 102 |
-
|
| 103 |
def get_final_answer(model, tokenizer, inputs, table_df):
|
| 104 |
outputs = model(**inputs)
|
| 105 |
|
|
@@ -140,210 +139,119 @@ def get_final_answer(model, tokenizer, inputs, table_df):
|
|
| 140 |
return agg_op, answer, predicted_cells
|
| 141 |
|
| 142 |
_, answer, _ = get_final_answer(model, tokenizer, inputs, table_df)
|
| 143 |
-
print(answer)
|
| 144 |
-
```
|
| 145 |
-
If the question is asking for a count, like how many changes have been completed, the answer would just be one number.
|
| 146 |
-
If it is asking a question about the most common incident status or root cause, the answer would be the root cause or status the model
|
| 147 |
-
predicts.
|
| 148 |
|
|
|
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
## Limitations
|
| 153 |
-
The model does still not come close to a 100% accuracy. Possiblly using a larger model could help. It does seem to only be able to take in a limited size for tables, larger than a whole system. Once again, possibly a larger model could help. Also this needs to take in a question and table in dataframe format, so more preocessing is necessary than just a regular prompt.
|
| 154 |
|
| 155 |
## Prompt Format
|
|
|
|
|
|
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
|
|
|
| 158 |
|
|
|
|
| 159 |
|
|
|
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
| 169 |
-
|
| 170 |
-
- **Developed by:** [More Information Needed]
|
| 171 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 172 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 173 |
-
- **Model type:** [More Information Needed]
|
| 174 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 175 |
-
- **License:** [More Information Needed]
|
| 176 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 177 |
-
|
| 178 |
-
### Model Sources [optional]
|
| 179 |
-
|
| 180 |
-
<!-- Provide the basic links for the model. -->
|
| 181 |
-
|
| 182 |
-
- **Repository:** [More Information Needed]
|
| 183 |
-
- **Paper [optional]:** [More Information Needed]
|
| 184 |
-
- **Demo [optional]:** [More Information Needed]
|
| 185 |
-
|
| 186 |
-
## Uses
|
| 187 |
-
|
| 188 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 189 |
-
|
| 190 |
-
### Direct Use
|
| 191 |
-
|
| 192 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 193 |
-
|
| 194 |
-
[More Information Needed]
|
| 195 |
-
|
| 196 |
-
### Downstream Use [optional]
|
| 197 |
-
|
| 198 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 199 |
-
|
| 200 |
-
[More Information Needed]
|
| 201 |
-
|
| 202 |
-
### Out-of-Scope Use
|
| 203 |
-
|
| 204 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 205 |
-
|
| 206 |
-
[More Information Needed]
|
| 207 |
-
|
| 208 |
-
## Bias, Risks, and Limitations
|
| 209 |
-
|
| 210 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 211 |
-
|
| 212 |
-
[More Information Needed]
|
| 213 |
-
|
| 214 |
-
### Recommendations
|
| 215 |
-
|
| 216 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 217 |
-
|
| 218 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 219 |
-
|
| 220 |
-
## How to Get Started with the Model
|
| 221 |
-
|
| 222 |
-
Use the code below to get started with the model.
|
| 223 |
-
|
| 224 |
-
[More Information Needed]
|
| 225 |
-
|
| 226 |
-
## Training Details
|
| 227 |
-
|
| 228 |
-
### Training Data
|
| 229 |
-
|
| 230 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 231 |
-
|
| 232 |
-
[More Information Needed]
|
| 233 |
-
|
| 234 |
-
### Training Procedure
|
| 235 |
-
|
| 236 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 237 |
-
|
| 238 |
-
#### Preprocessing [optional]
|
| 239 |
-
|
| 240 |
-
[More Information Needed]
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
#### Training Hyperparameters
|
| 244 |
-
|
| 245 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 246 |
-
|
| 247 |
-
#### Speeds, Sizes, Times [optional]
|
| 248 |
-
|
| 249 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 250 |
-
|
| 251 |
-
[More Information Needed]
|
| 252 |
-
|
| 253 |
-
## Evaluation
|
| 254 |
-
|
| 255 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 256 |
-
|
| 257 |
-
### Testing Data, Factors & Metrics
|
| 258 |
-
|
| 259 |
-
#### Testing Data
|
| 260 |
-
|
| 261 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 262 |
-
|
| 263 |
-
[More Information Needed]
|
| 264 |
-
|
| 265 |
-
#### Factors
|
| 266 |
-
|
| 267 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 268 |
-
|
| 269 |
-
[More Information Needed]
|
| 270 |
-
|
| 271 |
-
#### Metrics
|
| 272 |
-
|
| 273 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 274 |
-
|
| 275 |
-
[More Information Needed]
|
| 276 |
-
|
| 277 |
-
### Results
|
| 278 |
-
|
| 279 |
-
[More Information Needed]
|
| 280 |
-
|
| 281 |
-
#### Summary
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
## Model Examination [optional]
|
| 286 |
-
|
| 287 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 288 |
-
|
| 289 |
-
[More Information Needed]
|
| 290 |
-
|
| 291 |
-
## Environmental Impact
|
| 292 |
-
|
| 293 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 294 |
-
|
| 295 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 296 |
-
|
| 297 |
-
- **Hardware Type:** [More Information Needed]
|
| 298 |
-
- **Hours used:** [More Information Needed]
|
| 299 |
-
- **Cloud Provider:** [More Information Needed]
|
| 300 |
-
- **Compute Region:** [More Information Needed]
|
| 301 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 302 |
-
|
| 303 |
-
## Technical Specifications [optional]
|
| 304 |
-
|
| 305 |
-
### Model Architecture and Objective
|
| 306 |
-
|
| 307 |
-
[More Information Needed]
|
| 308 |
-
|
| 309 |
-
### Compute Infrastructure
|
| 310 |
-
|
| 311 |
-
[More Information Needed]
|
| 312 |
-
|
| 313 |
-
#### Hardware
|
| 314 |
-
|
| 315 |
-
[More Information Needed]
|
| 316 |
-
|
| 317 |
-
#### Software
|
| 318 |
|
| 319 |
-
|
|
|
|
| 320 |
|
| 321 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
|
| 323 |
-
|
| 324 |
|
| 325 |
-
|
|
|
|
| 326 |
|
| 327 |
-
|
|
|
|
|
|
|
|
|
|
| 328 |
|
| 329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
|
| 331 |
-
|
| 332 |
|
| 333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
|
| 335 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 336 |
|
| 337 |
-
[
|
| 338 |
|
| 339 |
-
##
|
|
|
|
| 340 |
|
| 341 |
-
[More Information Needed]
|
| 342 |
|
| 343 |
## Model Card Authors [optional]
|
| 344 |
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
## Model Card Contact
|
| 348 |
|
| 349 |
-
[More Information Needed]
|
|
|
|
| 50 |
| mistralai/Mistral-7B-Instruct-v0.3 | 0 | Exact Match: 0.0346 Fuzzy Match: 0.4744 | | | | |
|
| 51 |
| meta-llama/Llama-3.2-1B | 0.0133 | | | | | |
|
| 52 |
|
| 53 |
+
## Usage and Intended Uses
|
| 54 |
+
|
| 55 |
+
This model is designed for question answering over tabular data. It is mostly directed for querying ITSM tables (change, problem, and incident). It is used to answer questions, such as most common issues and
|
| 56 |
+
number of records in varying categories.
|
| 57 |
|
| 58 |
```python
|
| 59 |
+
saved_path = "/scratch/am5uc/models/cache/tapas_finetuned_base_model"
|
| 60 |
+
tokenizer = TapasTokenizer.from_pretrained(saved_path)
|
| 61 |
+
model = TapasForQuestionAnswering.from_pretrained(saved_path)
|
| 62 |
+
|
| 63 |
question = "How many Hardware Upgrade changes are still pending?"
|
| 64 |
table_df = pd.DataFrame({
|
| 65 |
"change_id": [
|
|
|
|
| 93 |
"2023-05-30"
|
| 94 |
]
|
| 95 |
})
|
|
|
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
# Tokenize both Question and Table together
|
| 98 |
inputs = tokenizer(table=table_df, queries=[question], padding='max_length', return_tensors='pt')
|
| 99 |
|
| 100 |
# Model prediction
|
| 101 |
+
# --- Helper function ---
|
|
|
|
| 102 |
def get_final_answer(model, tokenizer, inputs, table_df):
|
| 103 |
outputs = model(**inputs)
|
| 104 |
|
|
|
|
| 139 |
return agg_op, answer, predicted_cells
|
| 140 |
|
| 141 |
_, answer, _ = get_final_answer(model, tokenizer, inputs, table_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
+
print(answer)
|
| 144 |
|
| 145 |
+
```
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
## Prompt Format
|
| 148 |
+
The prompt for the TAPAS model should be a natural language question paired with a structured table that can be passed in in dataframe format. TAPAS does not work with
|
| 149 |
+
just one prompt and generally reqires a question and a table dataframe to work.
|
| 150 |
|
| 151 |
+
```python
|
| 152 |
+
question = "How many Hardware Upgrade changes are still pending?"
|
| 153 |
+
table_df = pd.DataFrame({
|
| 154 |
+
"change_id": [
|
| 155 |
+
"CHG3000",
|
| 156 |
+
"CHG3001",
|
| 157 |
+
"CHG3002",
|
| 158 |
+
"CHG3003"
|
| 159 |
+
],
|
| 160 |
+
"category": [
|
| 161 |
+
"Security Patch",
|
| 162 |
+
"Software Update",
|
| 163 |
+
"Hardware Upgrade",
|
| 164 |
+
"Software Update"
|
| 165 |
+
],
|
| 166 |
+
"status": [
|
| 167 |
+
"Rejected",
|
| 168 |
+
"In Progress",
|
| 169 |
+
"In Progress",
|
| 170 |
+
"Completed"
|
| 171 |
+
],
|
| 172 |
+
"approved_by": [
|
| 173 |
+
"",
|
| 174 |
+
"Manager2",
|
| 175 |
+
"",
|
| 176 |
+
"Admin1"
|
| 177 |
+
],
|
| 178 |
+
"implementation_date": [
|
| 179 |
+
"",
|
| 180 |
+
"",
|
| 181 |
+
"",
|
| 182 |
+
"2023-05-30"
|
| 183 |
+
]
|
| 184 |
+
})
|
| 185 |
|
| 186 |
+
inputs = tokenizer(table=table_df, queries=[question], padding='max_length', return_tensors='pt')
|
| 187 |
|
| 188 |
+
```
|
| 189 |
|
| 190 |
+
Or you could define table in json format and then have table = pd.DataFrame(table) in your tokenizer.
|
| 191 |
|
| 192 |
+
## Expected Output Format
|
| 193 |
+
You tokenize the inputs and then perform a specific function to get outputs, which are the aggregation operation, answer, and predicted_cells. You can just grab the middle value which is the predicted answer.
|
| 194 |
+
```python
|
| 195 |
+
# Tokenize both Question and Table together
|
| 196 |
+
inputs = tokenizer(table=table_df, queries=[question], padding='max_length', return_tensors='pt')
|
| 197 |
|
| 198 |
+
# Model prediction
|
| 199 |
+
##--- Helper function ---
|
| 200 |
+
|
| 201 |
+
def get_final_answer(model, tokenizer, inputs, table_df):
|
| 202 |
+
outputs = model(**inputs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
+
logits = outputs.logits
|
| 205 |
+
logits_agg = outputs.logits_aggregation
|
| 206 |
|
| 207 |
+
predicted_answer_coordinates, predicted_aggregation_indices = tokenizer.convert_logits_to_predictions(
|
| 208 |
+
inputs,
|
| 209 |
+
logits.detach(),
|
| 210 |
+
logits_agg=logits_agg.detach()
|
| 211 |
+
)
|
| 212 |
|
| 213 |
+
aggregation_operators = ["NONE", "SUM", "AVERAGE", "COUNT"]
|
| 214 |
|
| 215 |
+
agg_op_idx = predicted_aggregation_indices[0] if predicted_aggregation_indices else 0
|
| 216 |
+
agg_op = aggregation_operators[agg_op_idx]
|
| 217 |
|
| 218 |
+
predicted_cells = []
|
| 219 |
+
for coord in predicted_answer_coordinates[0]:
|
| 220 |
+
cell_value = table_df.iat[coord[0], coord[1]]
|
| 221 |
+
predicted_cells.append(cell_value)
|
| 222 |
|
| 223 |
+
if agg_op == "COUNT":
|
| 224 |
+
answer = len(predicted_cells)
|
| 225 |
+
elif agg_op == "SUM":
|
| 226 |
+
try:
|
| 227 |
+
answer = sum(float(cell) for cell in predicted_cells)
|
| 228 |
+
except ValueError:
|
| 229 |
+
answer = "Could not SUM non-numeric cells"
|
| 230 |
+
elif agg_op == "AVERAGE":
|
| 231 |
+
try:
|
| 232 |
+
answer = sum(float(cell) for cell in predicted_cells) / len(predicted_cells)
|
| 233 |
+
except ValueError:
|
| 234 |
+
answer = "Could not AVERAGE non-numeric cells"
|
| 235 |
+
else: # NONE
|
| 236 |
+
answer = predicted_cells
|
| 237 |
|
| 238 |
+
return agg_op, answer, predicted_cells
|
| 239 |
|
| 240 |
+
_, answer, _ = get_final_answer(model, tokenizer, inputs, table_df)
|
| 241 |
+
print(answer)
|
| 242 |
+
```
|
| 243 |
+
If the question is asking for a count, like how many changes have been completed, the answer would just be one number.
|
| 244 |
+
If it is asking a question about the most common incident status or root cause, the answer would be the root cause or status the model
|
| 245 |
+
predicts.
|
| 246 |
|
|
|
|
| 247 |
|
| 248 |
+

|
| 249 |
|
| 250 |
+
## Limitations
|
| 251 |
+
The model does still not come close to a 100% accuracy. Possiblly using a larger model could help. It does seem to only be able to take in a limited size for tables, larger than a whole system. Once again, possibly a larger model could help. Also this needs to take in a question and table in dataframe format, so more preocessing is necessary than just a regular prompt.
|
| 252 |
|
|
|
|
| 253 |
|
| 254 |
## Model Card Authors [optional]
|
| 255 |
|
| 256 |
+
Abhinandan Mekap
|
|
|
|
|
|
|
| 257 |
|
|
|