-
Notifications
You must be signed in to change notification settings - Fork 285
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
chore: move fixtures, expose them via load func #353
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f5e63c4
chore: move fixtures, expose them via load func
mikeldking 535e834
update readme
mikeldking 10386d5
use a dictionary in favor of a tuple
mikeldking 64721e3
remove fixture nomenclature
mikeldking 18f1fed
add readme
mikeldking dce3323
black format tutorials
mikeldking 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 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from .datasets import Dataset, EmbeddingColumnNames, Schema | ||
from .datasets import Dataset, EmbeddingColumnNames, Schema, load_datasets | ||
from .session.session import close_app, launch_app |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .dataset import Dataset | ||
from .fixtures import load_datasets | ||
from .schema import EmbeddingColumnNames, Schema | ||
|
||
__all__ = ["Dataset", "Schema", "EmbeddingColumnNames"] | ||
__all__ = ["Dataset", "Schema", "EmbeddingColumnNames", "load_datasets"] |
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import logging | ||
import os | ||
from dataclasses import dataclass, replace | ||
from typing import Tuple | ||
from typing import Dict, Tuple | ||
|
||
from pandas import read_parquet | ||
|
||
from phoenix.datasets import Dataset, EmbeddingColumnNames, Schema | ||
from .dataset import Dataset | ||
from .schema import EmbeddingColumnNames, Schema | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -189,23 +190,24 @@ class Fixture: | |
NAME_TO_FIXTURE = {fixture.name: fixture for fixture in FIXTURES} | ||
|
||
|
||
def download_fixture_if_missing(fixture_name: str) -> None: | ||
def download_fixture_if_missing(fixture_name: str) -> Tuple[Dataset, Dataset]: | ||
""" | ||
Downloads primary and reference datasets for a fixture if they are not found | ||
locally. | ||
""" | ||
fixture = _get_fixture_by_name(fixture_name=fixture_name) | ||
primary_dataset_name, reference_dataset_name = get_dataset_names_from_fixture_name(fixture_name) | ||
_download_and_persist_dataset_if_missing( | ||
primary_dataset = _download_and_persist_dataset_if_missing( | ||
dataset_name=primary_dataset_name, | ||
dataset_url=fixture.primary_dataset_url, | ||
schema=fixture.primary_schema, | ||
) | ||
_download_and_persist_dataset_if_missing( | ||
reference_dataset = _download_and_persist_dataset_if_missing( | ||
dataset_name=reference_dataset_name, | ||
dataset_url=fixture.reference_dataset_url, | ||
schema=fixture.reference_schema, | ||
) | ||
return primary_dataset, reference_dataset | ||
|
||
|
||
def get_dataset_names_from_fixture_name(fixture_name: str) -> Tuple[str, str]: | ||
|
@@ -223,27 +225,62 @@ def _get_fixture_by_name(fixture_name: str) -> Fixture: | |
if the input fixture name does not match any known fixture names. | ||
""" | ||
if fixture_name not in NAME_TO_FIXTURE: | ||
raise ValueError(f'"{fixture_name}" is not a valid fixture name.') | ||
valid_fixture_names = ", ".join(NAME_TO_FIXTURE.keys()) | ||
raise ValueError(f'"{fixture_name}" is invalid. Valid names are: {valid_fixture_names}') | ||
return NAME_TO_FIXTURE[fixture_name] | ||
|
||
|
||
def _download_and_persist_dataset_if_missing( | ||
dataset_name: str, dataset_url: str, schema: Schema | ||
) -> None: | ||
) -> Dataset: | ||
""" | ||
Downloads a dataset from the given URL if it is not found locally. | ||
""" | ||
try: | ||
Dataset.from_name(dataset_name) | ||
return | ||
return Dataset.from_name(dataset_name) | ||
except FileNotFoundError: | ||
pass | ||
|
||
logger.info(f'Downloading dataset: "{dataset_name}"') | ||
Dataset( | ||
dataset = Dataset( | ||
dataframe=read_parquet(dataset_url), | ||
schema=schema, | ||
name=dataset_name, | ||
persist_to_disc=True, | ||
) | ||
logger.info("Download complete.") | ||
return dataset | ||
|
||
|
||
@dataclass(frozen=True) | ||
class DatasetDict(Dict[str, Dataset]): | ||
"""A dictionary of datasets, split out by dataset type (primary, reference).""" | ||
|
||
primary: Dataset | ||
reference: Dataset | ||
|
||
|
||
def load_datasets(use_case: str) -> DatasetDict: | ||
""" | ||
Loads the primary and reference datasets for a given use-case. | ||
|
||
Parameters | ||
---------- | ||
use_case: str | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @axiomofjoy switched to use_case |
||
Name of the phoenix supported use case | ||
Valid values include: | ||
- "sentiment_classification_language_drift" | ||
- "fashion_mnist" | ||
- "ner_token_drift" | ||
- "credit_card_fraud" | ||
- "click_through_rate" | ||
|
||
|
||
Returns | ||
_______ | ||
datasets: DatasetDict | ||
A dictionary of datasets, split out by dataset type (primary, reference). | ||
|
||
""" | ||
primary_dataset, reference_dataset = download_fixture_if_missing(use_case) | ||
return DatasetDict(primary=primary_dataset, reference=reference_dataset) |
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,78 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# <center>Quickstart Guide</center>\n", | ||
"## <center>Gain insights into your model via Phoenix</center>\n", | ||
"\n", | ||
"Phoenix first and foremost is an application that can run alongside your notebook environment. It takes in up to two sets of data and surfaces up drift, performance, and data quality insights.\n" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### 📚 Install `arize-phoenix` " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%pip install -q arize-phoenix" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Using a built-in dataset to view the application\n", | ||
"\n", | ||
"To get familiar with the application itself, the easiest way to get started is to use one of phoenix's example datasets." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import phoenix as px\n", | ||
"\n", | ||
"# Get the fixture datasets via a specific use case. Some valid values are \"fashion_mnist\", \"sentiment_classification_language_drift\", and \"credit_card_fraud\"\n", | ||
"datasets = px.load_datasets(\"sentiment_classification_language_drift\")\n", | ||
"session = px.launch_app(datasets.primary, datasets.reference)\n", | ||
"session.view()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "phoenix", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.3" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mimic hugging face "split"