-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into atta_q_safety
- Loading branch information
Showing
523 changed files
with
15,174 additions
and
482 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,42 @@ | ||
from unitxt import evaluate, load_dataset, settings | ||
from unitxt.inference import ( | ||
CrossProviderInferenceEngine, | ||
) | ||
|
||
with settings.context( | ||
disable_hf_datasets_cache=False, | ||
allow_unverified_code=True, | ||
): | ||
test_dataset = load_dataset( | ||
"benchmarks.vision[format=formats.chat_api,loader_limit=30,max_samples_per_subset=30]", | ||
split="test", | ||
) | ||
|
||
# Infer | ||
model = CrossProviderInferenceEngine( | ||
model="llama-3-2-11b-vision-instruct", max_tokens=30, provider="watsonx" | ||
) | ||
""" | ||
We are using a CrossProviderInferenceEngine inference engine that supply api access to provider such as: | ||
watsonx, bam, openai, azure, aws and more. | ||
For the arguments these inference engines can receive, please refer to the classes documentation or read | ||
about the the open ai api arguments the CrossProviderInferenceEngine follows. | ||
""" | ||
|
||
predictions = model(test_dataset) | ||
results = evaluate(predictions=predictions, data=test_dataset) | ||
|
||
print("Global scores:") | ||
print(results.global_scores.summary) | ||
print("Subsets scores:") | ||
print(results.subsets_scores.summary) | ||
|
||
# | subset | score | score_name | num_of_instances | | ||
# |:---------|---------:|:----------------|-------------------:| | ||
# | ALL | 0.429583 | subsets_mean | 150 | | ||
# | doc_vqa | 0.79103 | anls | 30 | | ||
# | info_vqa | 0.464885 | anls | 30 | | ||
# | chart_qa | 0.3 | relaxed_overall | 30 | | ||
# | ai2d | 0.2 | exact_match_mm | 30 | | ||
# | websrc | 0.392 | websrc_squad_f1 | 30 | |
This file contains 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 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,56 @@ | ||
import os | ||
from collections import OrderedDict | ||
|
||
from unitxt.benchmark import Benchmark | ||
from unitxt.catalog import add_to_catalog | ||
from unitxt.settings_utils import get_constants | ||
|
||
constants = get_constants() | ||
|
||
tables_benchmark_dir = os.path.join( | ||
constants.catalog_dir, | ||
"recipes", | ||
"tables_benchmark", | ||
) | ||
|
||
|
||
# Recursive function to build nested benchmarks | ||
def build_nested_benchmark(dir_path, prefix="recipes.tables_benchmark"): | ||
nested_scenarios = OrderedDict() | ||
|
||
for entry in sorted(os.listdir(dir_path)): | ||
entry_path = os.path.join(dir_path, entry) | ||
entry_name = os.fsdecode(entry) | ||
|
||
if os.path.isdir(entry_path): # Handle subdirectories | ||
# Recurse into subdirectory to create a nested benchmark | ||
sub_benchmark = build_nested_benchmark(entry_path, f"{prefix}.{entry_name}") | ||
nested_scenarios[entry_name] = sub_benchmark | ||
else: # Handle individual JSON files | ||
scenario_name = ( | ||
entry_name[: -len(".json")] | ||
if entry_name.endswith(".json") | ||
else entry_name | ||
) | ||
nested_scenarios[scenario_name] = f"{prefix}.{scenario_name}" | ||
|
||
# Create a Benchmark object for the current folder | ||
return Benchmark(nested_scenarios) | ||
|
||
|
||
# Build the top-level benchmark | ||
tables_benchmark_scenarios = build_nested_benchmark(tables_benchmark_dir) | ||
|
||
benchmark = Benchmark( | ||
tables_benchmark_scenarios.subsets, | ||
__description__=( | ||
"TablesBenchmark is an open-source benchmark developed by domain experts to evaluate various table-related tasks and capabilities.\n\n" | ||
".. image:: https://raw.githubusercontent.com/IBM/unitxt/main/assets/catalog/tables_benchmark.png\n" | ||
" :alt: Optional alt text\n" | ||
" :width: 30%\n" | ||
" :align: center\n\n" | ||
"Constructed using state-of-the-art benchmarking methodologies, TablesBenchmark ensures validity, robustness, and efficiency by utilizing unitxt's dynamic and flexible text processing abilities.\n\n" | ||
"It encompasses diverse domains and evaluates a range of capabilities, with additional tasks and domains integrated over time." | ||
), | ||
) | ||
add_to_catalog(benchmark, "benchmarks.tables_benchmark", overwrite=True) |
This file contains 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,25 @@ | ||
from unitxt.benchmark import Benchmark | ||
from unitxt.catalog import add_to_catalog | ||
from unitxt.standard import DatasetRecipe | ||
|
||
benchmark = Benchmark( | ||
subsets={ | ||
"doc_vqa": DatasetRecipe( | ||
card="cards.doc_vqa.lmms_eval", | ||
), | ||
"info_vqa": DatasetRecipe( | ||
card="cards.info_vqa_lmms_eval", | ||
), | ||
"chart_qa": DatasetRecipe( | ||
card="cards.chart_qa_lmms_eval", | ||
), | ||
"ai2d": DatasetRecipe( | ||
card="cards.ai2d", | ||
), | ||
"websrc": DatasetRecipe( | ||
card="cards.websrc", | ||
), | ||
}, | ||
) | ||
|
||
add_to_catalog(benchmark, "benchmarks.vision", overwrite=True) |
This file contains 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 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
Oops, something went wrong.