Skip to content

Commit dc0a65f

Browse files
committed
Initial commit
0 parents  commit dc0a65f

31 files changed

Lines changed: 3209 additions & 0 deletions

.gitignore

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
49+
# Translations
50+
*.mo
51+
*.pot
52+
53+
# Django stuff:
54+
*.log
55+
.static_storage/
56+
.media/
57+
local_settings.py
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# Environments
85+
.env
86+
.venv
87+
env/
88+
venv/
89+
ENV/
90+
env.bak/
91+
venv.bak/
92+
93+
# Spyder project settings
94+
.spyderproject
95+
.spyproject
96+
97+
# Rope project settings
98+
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This project has adopted the [Microsoft Open Source Code of
2+
Conduct](https://opensource.microsoft.com/codeofconduct/).
3+
For more information see the [Code of Conduct
4+
FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
5+
contact [opencode@microsoft.com](mailto:opencode@microsoft.com)
6+
with any additional questions or comments.

LICENSE.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FigureQA Code
2+
Copyright (c) Microsoft Corporation
3+
All rights reserved.
4+
MIT License
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# FigureQA
2+
3+
Code to generate the FigureQA dataset, see https://datasets.maluuba.com/FigureQA.
4+
5+
## Data Generation
6+
7+
Data generation consists of 3 parts:
8+
9+
1. Generate the source numerical data, styles, and question-answer pairs for the figures.
10+
1. Generate the figure images and bounding box annotatations.
11+
1. Aggregrate the figure images, questions & answers, annotations, and source data.
12+
13+
### Code Map
14+
15+
All data generation source code lives in the `figureqa/generation` subpackage:
16+
17+
- `questions` subpackage contains code to generate questions
18+
19+
- `categorical.py` for questions for bar graphs and pie charts.
20+
- `lines.py` for line plots.
21+
- `utils.py` for balancing and question encoding augmentation.
22+
23+
- `source_data_generation.py` to generate source data, questions, and answers.
24+
25+
- `figure_generation.py` to generate figure images and bounding boxes.
26+
27+
- `json_combiner.py` aggregates the generated data into the documented format. Allows for generating a data split in multiple batches.
28+
29+
- `data_utils.py` has misc. utilities for reconciling data formats, placing legends, etc.
30+
31+
- `figure.py` defines the figure objects in Bokeh.
32+
33+
- `generate_dataset.py` generates a whole dataset end-to-end.
34+
35+
- `show_bounding_boxes.py` generates images with bounding boxes visualized.
36+
37+
Each runnable module (script) can have its command line arguments displayed with `--help`.
38+
39+
There are some additional files used for data generation in these directories:
40+
41+
- `config` contains `.yaml` files that configure visual apsects, source data parameters, color splits, and dataset generation.
42+
43+
- `resources` contains the colors and other misc. resources for data generation.
44+
45+
And `docs` contains additional documentation on annotations, question format, and file formats.
46+
47+
### Prerequisites
48+
49+
1. Install the FigureQA fork of Bokeh from https://www.github.com/Maluuba/bokeh.
50+
1. `pip install -r requirements.txt`.
51+
1. Make sure you have enough space. The whole dataset unzipped is > 6GB, plus you need room for intermediate data.
52+
53+
### Generate a whole dataset
54+
55+
#### Using a single script
56+
57+
This is done with the end-to-end script `generate_dataset.py`. It does the source data synthesis, figure generation, and aggregation.
58+
59+
This script must be run from the root directory, `FigureQA`.
60+
61+
The config for the actual dataset is in `config/figureqa_generation_config.yaml`.
62+
A sample config is provided in `config/sample_figureqa_generation_config.yaml`.
63+
64+
Note that this does not generate the test sets.
65+
66+
#### With individual scripts
67+
68+
1. `cd FigureQA`
69+
1. `python figureqa/generation/source_data_generation.py CONFIG_FILE.yaml SOURCE_DATA.json --<figure_type> <N_figures> ...`
70+
1. `python figureqa/generation/figure_generation.py SOURCE_DATA.json RAW_GENERATED_DIR`
71+
1. `python figureqa/generation/json_combiner.py FINAL_AGGREGATE_DIR RAW_GENERATED_DIR1 RAW_GENERATED_DIR2 ...`
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
vbar_categorical:
2+
y_range: [0, 99]
3+
n_points_range: [2, 10]
4+
x_distn: ["linear"]
5+
shape: ["random", "random", "random", "random", "linear_inc", "linear_dec", "cluster"]
6+
color_sources: ["resources/color_split2.txt"]
7+
8+
hbar_categorical:
9+
y_range: [0, 99]
10+
n_points_range: [2, 10]
11+
x_distn: ["linear"]
12+
shape: ["random", "random", "random", "random", "linear_inc", "linear_dec", "cluster"]
13+
color_sources: ["resources/color_split1.txt"]
14+
15+
line:
16+
x_range: [0, 100]
17+
y_range: [0, 100]
18+
n_points_range: [5, 20]
19+
x_distn: ["linear"]
20+
shape: ["linear", "linear_with_noise", "quadratic"]
21+
n_classes_range: [2, 7]
22+
color_sources: ["resources/color_split2.txt"]
23+
solid_pr: 0.5
24+
25+
dot_line:
26+
x_range: [0, 100]
27+
y_range: [0, 100]
28+
n_points_range: [5, 20]
29+
x_distn: ["linear"]
30+
shape: ["linear", "linear_with_noise", "quadratic"]
31+
n_classes_range: [2, 7]
32+
color_sources: ["resources/color_split1.txt"]
33+
34+
pie:
35+
color_sources: ["resources/color_split2.txt"]
36+
n_classes_range: [2, 7]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
vbar_categorical:
2+
y_range: [0, 99]
3+
n_points_range: [2, 10]
4+
x_distn: ["linear"]
5+
shape: ["random", "random", "random", "random", "linear_inc", "linear_dec", "cluster"]
6+
color_sources: ["resources/color_split1.txt"]
7+
8+
hbar_categorical:
9+
y_range: [0, 99]
10+
n_points_range: [2, 10]
11+
x_distn: ["linear"]
12+
shape: ["random", "random", "random", "random", "linear_inc", "linear_dec", "cluster"]
13+
color_sources: ["resources/color_split2.txt"]
14+
15+
line:
16+
x_range: [0, 100]
17+
y_range: [0, 100]
18+
n_points_range: [5, 20]
19+
x_distn: ["linear"]
20+
shape: ["linear", "linear_with_noise", "quadratic"]
21+
n_classes_range: [2, 7]
22+
color_sources: ["resources/color_split1.txt"]
23+
solid_pr: 0.5
24+
25+
dot_line:
26+
x_range: [0, 100]
27+
y_range: [0, 100]
28+
n_points_range: [5, 20]
29+
x_distn: ["linear"]
30+
shape: ["linear", "linear_with_noise", "quadratic"]
31+
n_classes_range: [2, 7]
32+
color_sources: ["resources/color_split2.txt"]
33+
34+
pie:
35+
color_sources: ["resources/color_split1.txt"]
36+
n_classes_range: [2, 7]

config/common_source_data.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
figure_height_px: 400
2+
figure_width_ratio_range: [1.0, 2.0]
3+
figure_min_width_side_legend: 1.33
4+
draw_gridlines_pr: 0.5
5+
draw_legend_pr: 1.0
6+
legend_inside_pr: 0.5
7+
legend_border_pr: 0.5
8+
legend_label_font_sizes: ['8pt', '9pt', '10pt', '11pt']
9+
legend_horizontal_pr: 0.5
10+
legend_horizontal_max_classes: 3
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
working_directory: figureqa_generation
2+
3+
destination_directory: figureqa_final
4+
5+
common_config_yaml: config/common_source_data.yaml
6+
7+
colors: resources/x11_colors_refined.txt
8+
9+
splits:
10+
- name: figureqa-train1
11+
partitions:
12+
- name: train1_1
13+
data_config_yaml: config/color_scheme1_source_data.yaml
14+
seed: 123
15+
vbar: 20000
16+
hbar: 20000
17+
pie: 20000
18+
line: 0
19+
dot_line: 0
20+
- name: train1_2
21+
data_config_yaml: config/color_scheme1_source_data.yaml
22+
seed: 456
23+
vbar: 0
24+
hbar: 0
25+
pie: 0
26+
line: 20000
27+
dot_line: 20000
28+
29+
- name: figureqa-validation1
30+
partitions:
31+
- name: validation1
32+
data_config_yaml: config/color_scheme1_source_data.yaml
33+
seed: 654
34+
vbar: 4000
35+
hbar: 4000
36+
pie: 4000
37+
line: 4000
38+
dot_line: 4000
39+
40+
- name: figureqa-validation2
41+
partitions:
42+
- name: validation2
43+
data_config_yaml: config/color_scheme2_source_data.yaml
44+
seed: 321
45+
vbar: 4000
46+
hbar: 4000
47+
pie: 4000
48+
line: 4000
49+
dot_line: 4000
50+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
working_directory: sample_generation
2+
3+
destination_directory: sample_final
4+
5+
common_config_yaml: config/common_source_data.yaml
6+
7+
colors: resources/x11_colors_refined.txt
8+
9+
splits:
10+
- name: figureqa-train1
11+
partitions:
12+
- name: train1_1
13+
data_config_yaml: config/color_scheme1_source_data.yaml
14+
seed: 1
15+
vbar: 1
16+
hbar: 1
17+
pie: 1
18+
line: 0
19+
dot_line: 0
20+
- name: train1_2
21+
data_config_yaml: config/color_scheme1_source_data.yaml
22+
seed: 456
23+
vbar: 0
24+
hbar: 0
25+
pie: 0
26+
line: 1
27+
dot_line: 1
28+
29+
- name: figureqa-validation1
30+
partitions:
31+
- name: validation1
32+
data_config_yaml: config/color_scheme1_source_data.yaml
33+
seed: 1001
34+
vbar: 1
35+
hbar: 1
36+
pie: 1
37+
line: 1
38+
dot_line: 1
39+

0 commit comments

Comments
 (0)