Skip to content
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

Feat/cog 946 abstract eval dataset #418

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

alekszievr
Copy link
Contributor

@alekszievr alekszievr commented Jan 8, 2025

QA eval dataset as argument, with hotpot and 2wikimultihop as options. Json schema validation for datasets.

Summary by CodeRabbit

  • New Features

    • Enhanced evaluation script to support multiple QA datasets
    • Added dynamic dataset selection through command-line arguments
    • Implemented dataset download and loading mechanisms
  • Improvements

    • Generalized evaluation function to work with different question-answering datasets
    • Improved dataset handling with metadata and validation

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

Walkthrough

The changes in eval_on_hotpot.py introduce a more flexible and generalized approach to evaluating question-answering datasets. The script now supports multiple QA datasets through a new qa_datasets dictionary, which stores metadata for different datasets. A new JSON schema is added to validate dataset structures, and new functions are implemented to download and load datasets dynamically. The main evaluation function is renamed and modified to work with various datasets, and the command-line interface is updated to allow dataset selection.

Changes

File Changes
evals/eval_on_hotpot.py - Added qa_datasets dictionary for dataset metadata
- Added qa_json_schema for dataset validation
- New download_qa_dataset() function
- New load_qa_dataset() function
- Renamed eval_on_hotpotQA() to eval_on_QA_dataset()
- Updated command-line argument to support dataset selection

Sequence Diagram

sequenceDiagram
    participant CLI as Command Line
    participant Eval as Evaluation Script
    participant Download as Dataset Downloader
    participant Load as Dataset Loader
    participant Cognee as Cognee System

    CLI->>Eval: Select dataset
    Eval->>Download: Download dataset
    Download-->>Eval: Dataset file
    Eval->>Load: Load dataset
    Load-->>Eval: Parsed dataset
    Eval->>Cognee: Evaluate with dataset
    Cognee-->>Eval: Evaluation results
Loading

Poem

🐰 A Rabbit's Ode to Dataset Delight 🔍

From HotPot to datasets galore,
Flexibility knocking at the door!
Download, load, with magical ease,
Evaluation dancing on rabbit's knees.
QA worlds now open, wide and free! 🌈


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
evals/eval_on_hotpot.py (2)

47-60: Handle dataset download exceptions and improve user instructions

In the download_qa_dataset function, consider automating the download and extraction of the "2wikimultihop" dataset or provide clearer instructions. Additionally, improve the string formatting for better readability.

Apply this diff to enhance exception handling and string formatting:

 def download_qa_dataset(dataset_name: str, dir: str):
     
     if dataset_name not in qa_datasets:
         raise ValueError(f"{dataset_name} is not a supported dataset.")

     url = qa_datasets[dataset_name]["URL"]

     if dataset_name == "2wikimultihop":
-        raise Exception("Please download 2wikimultihop dataset (data.zip) manually from \
-                            https://www.dropbox.com/scl/fi/heid2pkiswhfaqr5g0piw/data.zip?rlkey=ira57daau8lxfj022xvk1irju&e=1 \
-                            and unzip it.")
+        raise Exception("""Please download the 2wikimultihop dataset (data.zip) manually from
+https://www.dropbox.com/scl/fi/heid2pkiswhfaqr5g0piw/data.zip?rlkey=ira57daau8lxfj022xvk1irju&e=1
+and unzip it into the specified directory.""")

     wget.download(url, out=dir) 

Alternatively, you might consider automating the download and extraction process using requests and zipfile modules.


Line range hint 165-167: Improve help message formatting for clarity

The help message for the --metric argument uses backslashes for line continuation, which may not render correctly. Use implicit string concatenation for better readability.

Apply this diff to adjust the help message:

     parser.add_argument("--metric", type=str, default="correctness_metric",
-                        help="Valid options are Deepeval metrics (e.g. AnswerRelevancyMetric) \
-                              and metrics defined in evals/deepeval_metrics.py, e.g. f1_score_metric")
+                        help=("Valid options are Deepeval metrics (e.g., AnswerRelevancyMetric) "
+                              "and metrics defined in evals/deepeval_metrics.py, e.g., f1_score_metric"))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35892f9 and a67512d.

📒 Files selected for processing (1)
  • evals/eval_on_hotpot.py (5 hunks)
🔇 Additional comments (5)
evals/eval_on_hotpot.py (5)

11-11: Import jsonschema for dataset validation

Good use of the jsonschema library to validate the structure of QA datasets, enhancing data integrity.


21-30: Introduce qa_datasets dictionary for flexible dataset handling

The qa_datasets dictionary effectively stores metadata for multiple QA datasets, allowing for scalable and flexible evaluation across different datasets.


32-44: Define JSON schema for QA dataset validation

Defining qa_json_schema ensures that loaded datasets conform to the expected structure, which helps prevent runtime errors due to malformed data.


95-95: Update dataset name to 'QA' in Cognee system

Changing the dataset_name to 'QA' when adding sentences ensures consistency across different datasets within the Cognee system.


21-30: Verify the accessibility of dataset URLs

The URLs specified in qa_datasets may change or become unavailable. To ensure smooth execution, verify that these URLs are accessible and handle potential download errors gracefully.

Run the following script to check the accessibility of the dataset URLs:

✅ Verification successful

Dataset URLs are accessible and functional

Both dataset URLs are currently accessible:

  • HotpotQA dataset URL is directly accessible
  • 2WikiMultihop dataset URL properly redirects to the downloadable resource
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the accessibility of dataset URLs

# List of dataset URLs
urls=(
    "http://curtis.ml.cmu.edu/datasets/hotpot/hotpot_dev_fullwiki_v1.json"
    "https://www.dropbox.com/scl/fi/heid2pkiswhfaqr5g0piw/data.zip?rlkey=ira57daau8lxfj022xvk1irju&e=1"
)

# Check each URL
for url in "${urls[@]}"; do
    echo "Checking $url"
    status_code=$(curl -o /dev/null -s -w "%{http_code}\n" "$url")
    echo "HTTP Status Code: $status_code"
done

Length of output: 1018

Comment on lines 137 to 138
data_root_dir = get_absolute_path("../.data")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure consistent use of Path objects for file paths

To support path manipulations using the / operator, data_root_dir should be a Path object rather than a string.

Apply this diff to fix the type inconsistency:

-    data_root_dir = get_absolute_path("../.data")
+    data_root_dir = Path(get_absolute_path("../.data"))

Also applies to: 142-143

@@ -109,6 +160,7 @@
if __name__ == "__main__":
parser = argparse.ArgumentParser()

parser.add_argument("--dataset", type=str, choices=list(qa_datasets.keys()), help="Which dataset to evaluate on")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Make the --dataset argument required

The --dataset argument is currently optional, but the code expects it to be provided. If not specified, args.dataset will be None, leading to a KeyError. Make the argument required to prevent this issue.

Apply this diff to enforce the requirement:

 parser = argparse.ArgumentParser()

-    parser.add_argument("--dataset", type=str, choices=list(qa_datasets.keys()), help="Which dataset to evaluate on")
+    parser.add_argument("--dataset", type=str, choices=list(qa_datasets.keys()), required=True, help="Which dataset to evaluate on")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
parser.add_argument("--dataset", type=str, choices=list(qa_datasets.keys()), help="Which dataset to evaluate on")
parser.add_argument("--dataset", type=str, choices=list(qa_datasets.keys()), required=True, help="Which dataset to evaluate on")

Comment on lines 68 to 71
validate(instance=dataset, schema=qa_json_schema)
except ValidationError as e:
print("File is not a valid QA dataset:", e.message)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Raise an exception when dataset validation fails

Currently, if the dataset fails validation, the code prints an error message but continues execution, which could lead to downstream errors. To prevent this, raise an exception after catching the ValidationError.

Apply this diff to handle validation errors appropriately:

     try:
         validate(instance=dataset, schema=qa_json_schema)
     except ValidationError as e:
         print("File is not a valid QA dataset:", e.message)   
+        raise
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
validate(instance=dataset, schema=qa_json_schema)
except ValidationError as e:
print("File is not a valid QA dataset:", e.message)
validate(instance=dataset, schema=qa_json_schema)
except ValidationError as e:
print("File is not a valid QA dataset:", e.message)
raise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant