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: implement funtions to retrieve metrics and examples #687

Merged
merged 6 commits into from
Mar 14, 2023

Conversation

guenthermi
Copy link
Member

@guenthermi guenthermi commented Mar 7, 2023

Implement functions to retrieve metrics and examples

  • This PR references an open issue
  • I have added a line about this change to CHANGELOG

@github-actions github-actions bot added size/m and removed size/s labels Mar 7, 2023
@guenthermi guenthermi self-assigned this Mar 7, 2023
@guenthermi guenthermi marked this pull request as ready for review March 7, 2023 13:55
@guenthermi guenthermi requested review from gmastrapas, bwanglzu, LMMilliken and matousek-martin and removed request for gmastrapas March 9, 2023 07:43
Copy link
Member

@bwanglzu bwanglzu left a comment

Choose a reason for hiding this comment

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

minor comment

finetuner/run.py Outdated
Comment on lines 112 to 121
def example_results(self) -> Dict:
"""Get the results of example queries from the evaluation data of the
:class:`Run`.

:return: dictionary with results before and after fine-tuning.
"""
self._check_run_status_finished()
return self._client.get_run_examples(
experiment_name=self._experiment_name, run_name=self._name
)
Copy link
Member

Choose a reason for hiding this comment

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

if we can make this function more user friendly, would be even better. For example, 2 colums compare, if it is image/mesh, try to display

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea! However, I think sometimes it is good to get them as dictionaries, if you want to further process them. For the case that you want to display them directly to the console, I implemented two additional functions display_metrics and display_examples. It looks like this:

image

image

Copy link
Contributor

@LMMilliken LMMilliken left a comment

Choose a reason for hiding this comment

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

Two small things

Comment on lines 53 to 55
for i, match in enumerate(results[query]):
if i >= k:
break
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for i, match in enumerate(results[query]):
if i >= k:
break
for i, match in enumerate(results[query])[:k]:

Comment on lines 74 to 75
You can retrieve them with the {func}`~Run.example_results()` function.
Alternatively, you can use the {func}`~Run.display_metrics()` function to display a table of the Top-K results before and after fine-tuning to the console.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe explain what K is in this context and how to set it

Copy link
Member Author

Choose a reason for hiding this comment

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

ok I mention what Top-K means, how to set k is explained in the developer documentation which you get when clicking on the link

### Show evaluation metrics

During the fine-tuning process, the evaluation metrics are displayed in the logs, which you can retrieve via the {func}`~Run.logs()` function.
After running the fine-tuning job has finished, the evaluation metrics can be retrieved from the cloud by calling the {func}`~Run.metrics()` function.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
After running the fine-tuning job has finished, the evaluation metrics can be retrieved from the cloud by calling the {func}`~Run.metrics()` function.
After the fine-tuning job has finished, the evaluation metrics can be retrieved from the cloud by calling the {func}`~Run.metrics()` function.

If you want to compare the top-k retrieval results before and after fine-tuning, you can set the `gather_examples` parameter of the evaluation callback to `True`.
In this case, the evaluation callback will store the top-k results for each query document before and after fine-tuning.
You can retrieve them with the {func}`~Run.example_results()` function.
Alternatively, you can use the {func}`~Run.display_metrics()` function to display a table of the Top-K results before and after fine-tuning to the console.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Alternatively, you can use the {func}`~Run.display_metrics()` function to display a table of the Top-K results before and after fine-tuning to the console.
Alternatively, you can use the {func}`~Run.display_examples()` function to display a table of the Top-K results before and after fine-tuning to the console.

finetuner/run.py Outdated
@@ -99,6 +99,45 @@ def stream_logs(self, interval: int = 5) -> Iterator[str]:
experiment_name=self._experiment_name, run_name=self._name
)

def metrics(self) -> Dict:
Copy link
Member

Choose a reason for hiding this comment

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

return type hint? Dict[str, float]?

Copy link
Member Author

Choose a reason for hiding this comment

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

no its Dicct[str, Dict[str, float]] but yes I can add it

finetuner/run.py Outdated
for stage in metrics:
print_metrics(stage, metrics[stage])

def example_results(self) -> Dict:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def example_results(self) -> Dict:
def example_results(self) -> Dict[str, str]:
```?

@github-actions
Copy link

📝 Docs are deployed on https://ft-feat-support-metrics-and-examples--jina-docs.netlify.app 🎉

Copy link
Contributor

@LMMilliken LMMilliken left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@bwanglzu bwanglzu left a comment

Choose a reason for hiding this comment

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

LGTM!

@guenthermi guenthermi merged commit e649785 into main Mar 14, 2023
@guenthermi guenthermi deleted the feat-support-metrics-and-examples branch March 14, 2023 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants