feat: Evaluation Module Prototype#172
Conversation
…lder and init file
lukeroantreeONS
left a comment
There was a problem hiding this comment.
This is a great looking feature, looking forward to being able to use it.
I've added a few comments / change requests to make this initial version easier to build on in future, but overall it's fantastic and a nice piece of work.
|
|
||
| Input DataFrames: | ||
| Ground-truth input (`ground_truths`) must include: | ||
| - qid (str): Unique query identifier. |
There was a problem hiding this comment.
As discussed, I think we can drop qid as a required column for the user to provide, and can optionally export with the dataframe index referenced if it's useful to indicate particular rows to the user at some point.
| - label (str): Ground-truth label. | ||
|
|
||
| Search evaluation output (`results_df`) is expected to include: | ||
| - query_id (str): Query identifier (from `qid`). |
There was a problem hiding this comment.
Up to you whether to remove, construct from dataframe index, or just export with the index directly.
| @@ -0,0 +1,114 @@ | |||
| """Metrics.py provides a set of evaluation metrics for multiclass, single-label classification tasks. | |||
There was a problem hiding this comment.
I think this module could be more flexible, and could be extended more easily without breaking changes, if instead of these metrics being functions they were objects inheriting from a base class that has an
.evaluate() method returning a Metric object with (initially) a .value attribute.
This would provide scope to develop the Metric object further at a later date to (for example) add a .coverage attribute for % of unique KB labels included in the evaluation dataset, .confidence attribute to indicate statistical significance of reported metric value, etc.
| Ground-truth input (`ground_truths`) must include: | ||
| - qid (str): Unique query identifier. | ||
| - text (str): Query text. | ||
| - label (str): Ground-truth label. |
There was a problem hiding this comment.
As you clarified in the PR body, this initial version will be limited to multi-class, single label evaluation. However, a probable requirement for later iterations will be to have (optional) multi-class, multiple-label evaluation, so ideally our implementation for this initial version will lay some groundwork towards that to minimise breaking changes in future.
E.g. if we were to change this to label (str | List[str]), with a note that the option to provide a list is not yet in use and if a list is passed only the first element will be considered.
Alternatively - we could mark this evaluation module with a warning on import, and throughout our documentation for the first version, that this module should be considered as a 'preview' feature, and breaking changes within it will not be restricted to major version updates.
I'm happy with either of these options, let me know what your preference would be.
| class EvaluationError(ClassifaiError): | ||
| code: str = "evaluation_error" | ||
|
|
||
|
|
There was a problem hiding this comment.
(question, not change request)
Would it be more flexible if we were to have the functionality in this file exist within some kind of Evaluation class (not fussy on the name if you prefer another), which allows some configuration to be controlled by the user?
e.g.
my_eval = Evaluation(
ground_truth=some_df,
batch_size=100,
save_output=False
)I would picture a possible workflow with this approach looking like;
eval_sic = Evaluation(
ground_truth=sic_df,
batch_size=100,
save_output=False
)
eval_soc = Evaluation(
ground_truth=soc_df,
batch_size=100,
save_output=False
)
eval_sic.evaluate( # required to generate metric objects as class attributes for use by other methods
vector_stores=...,
metrics=...,
)
eval_sic.generate_report(
output_file=...,
report_misclassifications=False,
...
)
eval_sic.visualise(
style=...,
savefile=False
)
...
✨ Summary
These changes add a new evaluation module that can quantitatively evaluate the performance of
VectorStoresagainst a user-provided ground truth dataset using package-provided classification metrics.The current implementation views the evaluation as a 'multi-class-single-label' problem, with each evaluation metric assessing only the top candidate result output from the VectorStore search method. Additional metrics could be considered such as 'hit@k' where we assess if the correct label is in the top K results of a VectorStore search, to give users more options on how to evaluate VectorStores.
The main entry point for the new code; the evaluation function, importable from the Evaluation module, has several parameters:
['qid', 'text', 'label'], where text is the query, and label is the ground truth correct label,The evaluation function performs several actions:
vectorstorewith the provided eval data queries.vectorstoresearch results using provided ground truth labelsvectorstoresoutput_fileargument is provided with a valid .csv string.Final thought:
📜 Changes Introduced
✅ Checklist
Passes all pre-commit checks.
🔍 How to Test
The tester should obtain some data that has queries and gold standard labels for a give vectorstore, loading the queries into a pandas dataframe with
['qid', 'text', 'label']columns. All columns should be loaded with string types.Next they should instantiate the corresponding VectorStore(s) they wish to evaluate against the ground truth dataset.
Passing these items are arguments to the new evaluate function as in the code below, and specifying a list of metric names, the user can run the script to see the evaluation function,
Additionally test the functionality that allows users to pass callable to the
vectorstoresargument of the eval function. To do this the user could write a zero-arg function that returns an instantiatedvectorstoreobject and pass the function pointer as an argument (not the call the to function). See below for the normal process of instantiation versus the samevectorstorewrapped as a callable.Finally try out some edge cases such as:
classification_suitestring to the metrics, which triggers all current metrics to run