Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,88 @@
|
|
1 |
-
---
|
2 |
-
license: mit
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
---
|
4 |
+
# Usage
|
5 |
+
```python
|
6 |
+
import pandas as pd
|
7 |
+
from datasets import load_dataset
|
8 |
+
from transformers import M2M100ForConditionalGeneration
|
9 |
+
model = M2M100ForConditionalGeneration.from_pretrained("vaishali/HiTQA-M2M")
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained("vaishali/HiTQA-M2M", src_lang="hi", tgt_lang="hi")
|
11 |
+
forced_bos_id = forced_bos_token_id = tokenizer.get_lang_id("hi")
|
12 |
+
|
13 |
+
|
14 |
+
# linearize table
|
15 |
+
def process_header(headers: List):
|
16 |
+
return "<कलाम> " + " | ".join(headers)
|
17 |
+
|
18 |
+
def process_row(row: List, row_index: int):
|
19 |
+
hi2enDigits = {'०': '0', '१': '1', '२': '2', '३': '3', '४': '4', '५': '5', '६': '6', '७': '7', '८': '8',
|
20 |
+
'९': '9', '.': '.'}
|
21 |
+
en2hiDigits = {v:k for k, v in hi2enDigits.items()}
|
22 |
+
row_str = ""
|
23 |
+
row_cell_values = []
|
24 |
+
for cell_value in row:
|
25 |
+
if isinstance(cell_value, int) or isinstance(cell_value, float):
|
26 |
+
cell_value = convert_engDigit_to_hindi(str(cell_value))
|
27 |
+
row_cell_values.append(str(cell_value))
|
28 |
+
else:
|
29 |
+
row_cell_values.append(cell_value)
|
30 |
+
row_str += " | ".join([row_cell_values for cell_value in row])
|
31 |
+
hi_row_index = []
|
32 |
+
for c in str(row_index):
|
33 |
+
hi_row_index.append(en2hiDigits[c])
|
34 |
+
return "<रो " + "".join(hi_row_index) + "> " + row_str
|
35 |
+
|
36 |
+
def process_table(table_content: Dict):
|
37 |
+
table_str = process_header(table_content["header"]) + " "
|
38 |
+
for i, row_example in enumerate(table_content["rows"]):
|
39 |
+
table_str += process_row(row_example, row_index=i + 1) + " "
|
40 |
+
return table_str.strip()
|
41 |
+
|
42 |
+
# load the dataset
|
43 |
+
hinditableQA = load_dataset("vaishali/hindiTabQA")
|
44 |
+
|
45 |
+
for sample in hinditableQA['train']:
|
46 |
+
question = sample['question']
|
47 |
+
input_table = pd.read_json(sample['table'], orient='split')
|
48 |
+
answer = pd.read_json(sample['answer'], orient='split')
|
49 |
+
|
50 |
+
# create the input sequence: query + linearized input table
|
51 |
+
table_content = {"header": list(input_table.columns)[1:], "rows": [list(row.values)[1:] for i, row in input_table.iterrows()]}
|
52 |
+
linearized_inp_table = process_table(table_content)
|
53 |
+
linearized_output_table = process_table({"name": None, "header": [self.translate_column(col) for col in list(answer.columns)],
|
54 |
+
"rows": [list(row.values) for i, row in answer.iterrows()]})
|
55 |
+
source = query + " " + linearized_inp_table
|
56 |
+
target = linearized_output_table
|
57 |
+
input = tokenizer(source,
|
58 |
+
return_tensors="pt",
|
59 |
+
padding="max_length",
|
60 |
+
truncation="longest_first",
|
61 |
+
max_length=1024,
|
62 |
+
add_special_tokens=True)
|
63 |
+
|
64 |
+
out = model.generate(input["input_ids"].to("cuda"), num_beams=5, return_dict_in_generate=True,
|
65 |
+
output_scores=True, max_length=1024)
|
66 |
+
```
|
67 |
+
# BibTeX entry and citation info
|
68 |
+
```
|
69 |
+
@inproceedings{pal-etal-2024-table,
|
70 |
+
title = "Table Question Answering for Low-resourced {I}ndic Languages",
|
71 |
+
author = "Pal, Vaishali and
|
72 |
+
Kanoulas, Evangelos and
|
73 |
+
Yates, Andrew and
|
74 |
+
de Rijke, Maarten",
|
75 |
+
editor = "Al-Onaizan, Yaser and
|
76 |
+
Bansal, Mohit and
|
77 |
+
Chen, Yun-Nung",
|
78 |
+
booktitle = "Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing",
|
79 |
+
month = nov,
|
80 |
+
year = "2024",
|
81 |
+
address = "Miami, Florida, USA",
|
82 |
+
publisher = "Association for Computational Linguistics",
|
83 |
+
url = "https://aclanthology.org/2024.emnlp-main.5",
|
84 |
+
pages = "75--92",
|
85 |
+
abstract = "TableQA is the task of answering questions over tables of structured information, returning individual cells or tables as output. TableQA research has focused primarily on high-resource languages, leaving medium- and low-resource languages with little progress due to scarcity of annotated data and neural models. We address this gap by introducing a fully automatic large-scale tableQA data generation process for low-resource languages with limited budget. We incorporate our data generation method on two Indic languages, Bengali and Hindi, which have no tableQA datasets or models. TableQA models trained on our large-scale datasets outperform state-of-the-art LLMs. We further study the trained models on different aspects, including mathematical reasoning capabilities and zero-shot cross-lingual transfer. Our work is the first on low-resource tableQA focusing on scalable data generation and evaluation procedures. Our proposed data generation method can be applied to any low-resource language with a web presence. We release datasets, models, and code (https://github.com/kolk/Low-Resource-TableQA-Indic-languages).",
|
86 |
+
}
|
87 |
+
|
88 |
+
```
|