ahmed-masry commited on
Commit
5c2a21e
·
verified ·
1 Parent(s): 7718a87

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +73 -3
README.md CHANGED
@@ -1,3 +1,73 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: gpl-3.0
3
+ language:
4
+ - en
5
+ ---
6
+ # TL;DR
7
+ **ChartInstruct: Instruction Tuning for Chart Comprehension and Reasoning**
8
+
9
+ Venue: **ACL 2024 (Findings)**
10
+ Paper Link: https://arxiv.org/abs/2403.09028
11
+
12
+ The abstract of the paper states that:
13
+ > Charts provide visual representations of data and are widely used for analyzing information, addressing queries, and conveying insights to others. Various chart-related downstream tasks have emerged recently, such as question-answering and summarization. A common strategy to solve these tasks is to fine-tune various models originally trained on vision tasks language. However, such task-specific models are not capable of solving a wide range of chart-related tasks, constraining their real-world applicability. To overcome these challenges, we introduce ChartInstruct: a novel chart-specific vision-language Instruction following dataset comprising 191K instructions generated with 71K charts. We then present two distinct systems for instruction tuning on such datasets: (1) an end-to-end model that connects a vision encoder for chart understanding with a LLM; and (2) a pipeline model that employs a two-step approach to extract chart data tables and input them into the LLM. In experiments on four downstream tasks, we first show the effectiveness of our model--achieving a new set of state-of-the-art results. Further evaluation shows that our instruction-tuning approach supports a wide array of real-world chart comprehension and reasoning scenarios, thereby expanding the scope and applicability of our models to new kinds of tasks.
14
+ # Web Demo
15
+ If you wish to quickly try our model, you can access our public web demo hosted on the Hugging Face Spaces platform with a friendly interface!
16
+
17
+ [ChartInstruct-Llama2 Web Demo](https://huggingface.co/spaces/ahmed-masry/UniChart-Base) |
18
+
19
+ # Inference
20
+ You can easily use our models for inference with the huggingface library!
21
+ You just need to do the following:
22
+ 1. Chage the _imag_path_ to your chart example image path on your system
23
+ 2. Write the _input_text_.
24
+
25
+ ```
26
+ from PIL import Image
27
+ import requests
28
+ from transformers import AutoProcessor, LlavaForConditionalGeneration
29
+ import torch
30
+
31
+ torch.hub.download_url_to_file('https://raw.githubusercontent.com/vis-nlp/ChartQA/main/ChartQA%20Dataset/val/png/multi_col_1229.png', 'chart_example_1.png')
32
+
33
+ image_path = "/content/chart_example_1.png"
34
+ input_text = "Question: What is the share of respondants who prefer Whatsapp in the 18-29 age group?"
35
+ input_prompt = f"<image>\n Question: {input_text} Answer: "
36
+
37
+
38
+ model = LlavaForConditionalGeneration.from_pretrained("ahmed-masry/ChartInstruct-LLama2", torch_dtype=torch.float16)
39
+ processor = AutoProcessor.from_pretrained("ahmed-masry/ChartInstruct-LLama2")
40
+
41
+
42
+ image = Image.open(image_path).convert('RGB')
43
+
44
+ inputs = processor(text=prompt, images=image, return_tensors="pt")
45
+ inputs = {k: v.to(device) for k, v in inputs.items()}
46
+
47
+ # change type if pixel_values in inputs to fp16.
48
+ inputs['pixel_values'] = inputs['pixel_values'].to(torch.float16)
49
+ prompt_length = inputs['input_ids'].shape[1]
50
+
51
+ # Generate
52
+ generate_ids = model.generate(**inputs, max_new_tokens=512)
53
+ output_text = processor.batch_decode(generate_ids[:, prompt_length:], skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
54
+ print(output_text)
55
+
56
+ ```
57
+
58
+ # Contact
59
+ If you have any questions about this work, please contact **[Ahmed Masry](https://ahmedmasryku.github.io/)** using the following email addresses: **[email protected]** or **[email protected]**.
60
+
61
+ # Reference
62
+ Please cite our paper if you use our model in your research.
63
+
64
+ ```
65
+ @misc{masry2024chartinstruct,
66
+ title={ChartInstruct: Instruction Tuning for Chart Comprehension and Reasoning},
67
+ author={Ahmed Masry and Mehrad Shahmohammadi and Md Rizwan Parvez and Enamul Hoque and Shafiq Joty},
68
+ year={2024},
69
+ eprint={2403.09028},
70
+ archivePrefix={arXiv},
71
+ primaryClass={id='cs.CL' full_name='Computation and Language' is_active=True alt_name='cmp-lg' in_archive='cs' is_general=False description='Covers natural language processing. Roughly includes material in ACM Subject Class I.2.7. Note that work on artificial languages (programming languages, logics, formal systems) that does not explicitly address natural-language issues broadly construed (natural-language processing, computational linguistics, speech, text retrieval, etc.) is not appropriate for this area.'}
72
+ }
73
+ ```