-
Notifications
You must be signed in to change notification settings - Fork 25
Adding LLM summary explainer #33
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
Open
zippeurfou
wants to merge
2
commits into
RecList:main
Choose a base branch
from
zippeurfou:llm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,88 @@ | ||
| import guidance | ||
| from typing import Optional | ||
|
|
||
| guidance.llm = guidance.llms.OpenAI("gpt-3.5-turbo") | ||
| PROMPT = """ | ||
| {{#system~}} | ||
| Assume you are a Data Scientist assistant helping Data Science practicioners evaluate their recommender system models. | ||
| You will be given a list of metrics and you should do 2 tasks: | ||
| 1. Help summarize the finding | ||
| 2. Provide advice on what to do that could increase the metrics | ||
| You will report your finding being specific for example referring the actual metric and values while being succinct using bullets points. | ||
| For example you can look at correlations between metrics, outliers or range of the metrics to draw conclusion. | ||
| As a Data Scientist you do not need to report on all the metrics but only on the one providing incremental value to the analysis. | ||
| Therefore, it is key to only output information that provide value maximizing the value while minimizing the verbosity of it. | ||
| Do not hesitate to group multiple metrics into one bullet point if they are going towards the same conclusion. | ||
| It will only make your reasoning stronger. | ||
| You should aim for each bullet point to do no more than one sentence so digesting this information is easy and fast. | ||
| Finally, you do not need to explain what the metrics are as you are already speaking to an expert. | ||
| Do not hesitate to use technical jargon if it helps you to be more concise. | ||
| The metrics follow an array of json with each element having theses keys: | ||
| 1. "name" This is the name of the metric it follows this pattern <metric_name>_<slice_name> where slice name is optional. | ||
| 2. "description" is an optional description entered by the user | ||
| 3. "result" this is where you will get the metric value or additional slice from the metric "name" | ||
| 4. "display_type" Ignore this | ||
|
|
||
| In addition here is a mapping of the metrics name: | ||
| MRR means mean reciprocal rank | ||
| HIT_RATE means hit rate | ||
| MRED means miss rate equality difference | ||
| BEING_LESS_WRONG compute the cosine similarity between the true label and the predictions. | ||
| MR means miss rate which is the opposite of HIT_RATE | ||
| {{#if compare_statistics}} | ||
| You will be given 2 sets of model metrics to compare 2 different models. | ||
| Please focus on the comparison so the Data Scientist can draw conclusion. | ||
| {{/if}} | ||
| {{~/system}} | ||
| {{#user~}} | ||
| Given that I have a model that I named {{model_name}} and this statistics: | ||
| {{statistics}} | ||
| {{#if compare_statistics}} | ||
| In addition, my second model is named {{compare_model_name}} and has this statistics: | ||
| {{compare_statistics}} | ||
| {{/if}} | ||
| Please summarize your findings. | ||
| {{~/user}} | ||
|
|
||
| {{#assistant~}} | ||
| {{gen 'out' temperature=0}} | ||
| {{~/assistant}} | ||
| """ | ||
| PROGRAM = guidance(PROMPT) | ||
|
|
||
|
|
||
| def summarize_statistics( | ||
| model_name: str, | ||
| statistics: list, | ||
| compare_model_name: Optional[str] = None, | ||
| compare_statistics: Optional[list] = None, | ||
| ) -> Optional[str]: | ||
| """This function use OpenAI to summarize or compare 2 models statistics from reclist | ||
|
|
||
| `compare_model_name` and `compare_statistics` are optional and only used if you want to compare 2 models. | ||
| If not used it will provide summary on one model defined by `model_name` `statistics` | ||
|
|
||
|
|
||
| Args: | ||
| model_name (str): Model Name | ||
| statistics (list): List of statistics as defined by reclist | ||
| compare_model_name (Optional[str]): Optional, Model Name to compare | ||
| compare_statistics (Optional[list]): Optional, statistics as defined in reclist to compare | ||
|
|
||
| Returns: | ||
| String that summarize the model statistics or comparison between model and target model | ||
|
|
||
| Raises: | ||
| ValueError: If one of the two is not None while the other is `compare_model_name` or `compare_statistics` | ||
| """ | ||
| if compare_model_name is not None and compare_statistics is None: | ||
| raise ValueError( | ||
| "You have specified a compare_model_name without compare_statistics" | ||
| ) | ||
| if compare_model_name is None and compare_statistics is not None: | ||
| raise ValueError( | ||
| "You have specified compare_statistics without a compare_model_name" | ||
| ) | ||
| summary = PROGRAM(**locals()) | ||
| return summary["out"] | ||
|
|
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 |
|---|---|---|
|
|
@@ -10,5 +10,6 @@ pathos==0.2.8 | |
| networkx==2.6.3 | ||
| python-Levenshtein==0.12.2 | ||
| pyarrow==12.0.1 | ||
| guidance==0.0.64 | ||
| scikit-learn | ||
| rich | ||
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.
There should be a else statement with a warning.