-
Notifications
You must be signed in to change notification settings - Fork 33
Add QuiltVQA dataset & FreeFormQuestionPromptTemplate template
#912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
f7dfe35
add class
nkaenzig b0936b6
minor update to prompt text
nkaenzig 6727011
updated PubMedQA dataset class to use new JSON answer template & adde…
nkaenzig b5a1a26
enable json prompts for pcam
nkaenzig b40888f
add unit tests for JsonMultipleChoicePromptTemplate
nkaenzig 8ecd267
update unit tests for JsonMultipleChoicePromptTemplate
nkaenzig a2297dd
add unit tests for ExtractAnswerFromJson
nkaenzig 031c2ff
remove num_samples
nkaenzig 3434f39
implement missing_limit
nkaenzig 68d0864
Merge remote-tracking branch 'origin/main' into 904-add-json-answer-t…
nkaenzig d05a349
fix unit tests
nkaenzig cfd380a
make prompt template configurable & provide default template
nkaenzig 383d169
fix single word
nkaenzig b7c4511
add FreeFormQuestionPromptTemplate
nkaenzig c666685
resolved merge conflicts
nkaenzig baa14f9
delete dataset again
nkaenzig 846f80d
move pubmedqa to multiple_choice folder
nkaenzig d4d4a31
add QuiltVQA dataset class
nkaenzig 49a1c9f
renamed to test split
nkaenzig c725786
add unit tests & docs
nkaenzig a239a99
move FreeFormQuestionPromptTemplate to raw subfolder
nkaenzig 740f5c0
add example enumeration and remove multiple blank lines
nkaenzig 6ae15ed
mrege main
nkaenzig 8fe601e
enable cot & moved bullet point formatting function into utils
nkaenzig 1f88c07
add enable_cot option to RawMultipleChoicePromptTemplate
nkaenzig 908fb9f
add enable_cot to render function
nkaenzig d611d0d
fix tests
nkaenzig a2ac76c
fixed pyright issues
nkaenzig 4e89f1d
remove <think> tokens from prompts
nkaenzig 6b6e410
rename format_as_bullet_points to format_list_items
nkaenzig 8b1d69c
rename options to items
nkaenzig 2ccf6f0
remove context from qa pairs
nkaenzig 77494f2
fix tests
nkaenzig e75d6e4
remove file commited by accident
nkaenzig 9747fce
use new line to join the example reason & answer
nkaenzig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Quilt_VQA | ||
|
|
||
| Quilt_VQA is a histopathology visual question answering dataset released with Quilt-LLaVA for evaluating multimodal models on realistic pathology questions. It pairs microscopy frames with naturally occurring questions and answers that were mined from expert-narrated videos and refined with GPT-4 plus manual review. | ||
|
|
||
| ## Raw data | ||
|
|
||
| ### Key stats | ||
| | Modality | Task | Domain | Sample Size | Question Format | License | | ||
| |----------|------|--------|-------------|-----------------|---------| | ||
| | Image + Text | Visual Question Answering (free-form) | Histopathology (medical) | 985 evaluation samples | Mix of closed-ended and open-ended questions with short textual answers | CC-BY-NC-ND-3.0 | | ||
|
|
||
| ### Data organization | ||
| - Hugging Face exposes a single `default` configuration with 985 examples stored under a `train` split (eva treats this as the evaluation/test split). | ||
| - Each record provides an `image`, `question`, free-form `answer`, categorical `answer_type` (e.g., closed vs. open response), and a short textual `context` snippet from the source narration. | ||
| - The repository also packages the original Parquet export (`data/train-*.parquet`) alongside helper files (`quilt_vqa.zip`, `quiltvqa_test_w_ans.json`, `quiltvqa_test_wo_ans.jsonl`) that separate the open and closed subsets used by the Quilt benchmark. | ||
|
|
||
| ## Download and preprocessing | ||
|
|
||
| Quilt_VQA is gated. Accept the terms on the [Hugging Face dataset page](https://huggingface.co/datasets/wisdomik/Quilt_VQA) and generate a user access token before triggering automated downloads. | ||
|
|
||
| Once access is granted, set `DOWNLOAD_DATA="true"` (and optionally `DATA_ROOT` for the cache directory) when launching eva with a configuration that references `QuiltVQA`. Provide your Hugging Face token via `HF_TOKEN` so the downloader can authenticate. | ||
|
|
||
| ## Relevant links | ||
|
|
||
| - **Project**: [Quilt-LLaVA](https://quilt-llava.github.io/) | ||
| - **Dataset card (Hugging Face)**: https://huggingface.co/datasets/wisdomik/Quilt_VQA | ||
| - **Companion dataset**: [Quilt-1M](https://quilt1m.github.io/) | ||
| - **Paper**: [Quilt-LLaVA: Visual Instruction Tuning by Extracting Localized Narratives from Open-Source Histopathology Videos](https://arxiv.org/abs/2312.04746) | ||
|
|
||
| ## License information | ||
|
|
||
| Distributed under the [CC-BY-NC-ND 3.0](https://creativecommons.org/licenses/by-nc-nd/3.0/) license. Access is limited to non-commercial research use as outlined in the Hugging Face gated download agreement. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| """Text classification datasets API.""" | ||
|
|
||
| from eva.language.data.datasets.multiple_choice.pubmedqa import PubMedQA | ||
|
|
||
| __all__ = [ | ||
| "PubMedQA", | ||
| ] |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| """Prompt templating API.""" | ||
|
|
||
| from eva.language.prompts.templates.raw.free_form import FreeFormQuestionPromptTemplate | ||
| from eva.language.prompts.templates.raw.multiple_choice import RawMultipleChoicePromptTemplate | ||
|
|
||
| __all__ = ["RawMultipleChoicePromptTemplate"] | ||
| __all__ = ["RawMultipleChoicePromptTemplate", "FreeFormQuestionPromptTemplate"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| """Prompt templates for free-form questions.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import textwrap | ||
| from typing import Sequence | ||
|
|
||
| from jinja2 import Template | ||
| from typing_extensions import override | ||
|
|
||
| from eva.language.prompts.templates import base, typings | ||
| from eva.language.utils.text import format as format_utils | ||
|
|
||
|
|
||
| class FreeFormQuestionPromptTemplate(base.PromptTemplate): | ||
| """Prompt template for free-form questions.""" | ||
|
|
||
| template = textwrap.dedent( | ||
| """\ | ||
| {{ preamble }} | ||
|
|
||
| {% if examples %} | ||
| Below are some examples: | ||
|
|
||
| {% for ex in examples %} | ||
| Example {{ loop.index }}: | ||
| Question: {{ ex.question }} | ||
| Answer: {{ ex.answer }} | ||
| --- | ||
| {% endfor %} | ||
| Now please answer the following question. | ||
| {%- if enable_cot %} | ||
| Think step-by-step before giving your final answer. | ||
| {% endif %} | ||
|
|
||
| {% endif %} | ||
| Question: {{ question }} | ||
| Answer: | ||
| """ | ||
| ) | ||
| """Base template to be rendered via Jinja2.""" | ||
|
|
||
| def __init__(self, enable_cot: bool = False) -> None: | ||
| """Initializes the prompt template. | ||
|
|
||
| Args: | ||
| enable_cot: Whether to explicitly prompt the model to use reasoning/CoT for answering. | ||
| """ | ||
| super().__init__() | ||
| self.enable_cot = enable_cot | ||
|
|
||
| @override | ||
| def render( | ||
| self, | ||
| *, | ||
| question: str, | ||
| context: str | Sequence[str] | None = None, | ||
| examples: Sequence[typings.QuestionAnswerExample] | None = None, | ||
| preamble: str | None = None, | ||
| enable_cot: bool | None = None, | ||
| ) -> str: | ||
| """Render the template with provided values. | ||
|
|
||
| Args: | ||
| question: The question to ask the model. | ||
| context: Supporting context text(s) for the question. | ||
| examples: A sequence of question & answer pairs to include as examples. | ||
| Expected format is a list of dicts with 'question', 'answer', and | ||
| optional 'context' keys. | ||
| preamble: Optional preamble text to include at the top of the prompt. | ||
| enable_cot: Optionally override the instance's CoT setting for this render call. | ||
|
|
||
| Returns: | ||
| The rendered prompt string. | ||
| """ | ||
| if not isinstance(question, str) or not question.strip(): | ||
| raise ValueError("`question` must be a non-empty string.") | ||
|
|
||
| jinja_template = Template(self.template) | ||
| rendered = jinja_template.render( | ||
| question=question.strip(), | ||
| context=format_utils.format_list_items(context) if context else None, | ||
| examples=examples, | ||
| preamble=(preamble or "").strip(), | ||
| enable_cot=self.enable_cot if enable_cot is None else enable_cot, | ||
| ) | ||
|
|
||
| return format_utils.remove_multi_blank_lines(textwrap.dedent(rendered).strip()) + "\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| """Typings for prompt templates.""" | ||
|
|
||
| from typing_extensions import TypedDict | ||
|
|
||
|
|
||
| class QuestionAnswerExample(TypedDict): | ||
| """A question-answer example for few-shot prompting.""" | ||
|
|
||
| question: str | ||
| answer: str |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.