Inference
This inference
module uses similarity scores to perform predictions on unseen data. This includes
classification (KnnClassifier
class) and ranking (TopkClassifier
class) using using nearest neigbours.
Similarity scores are expected to be in the form of 2D array with shape n_query
x n_database
.
inference.classifier
KnnClassifier(database_labels, k=1, return_scores=False)
Predict query label as k labels of nearest matches in the database. If there is a tie at a given k, the prediction with the best score is used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
database_labels |
array
|
Array containing the labels of the database. |
required |
k |
int
|
The number of nearest neighbors to consider. |
1
|
return_scores |
bool
|
Indicates whether to return scores along with predictions. |
False
|
__call__(similarity)
Predicts the label for each query based on the k nearest matches in the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
similarity |
A 2D similarity matrix with |
required |
Returns:
Type | Description |
---|---|
If
|
|
If
|
TopkClassifier(database_labels, k=10, return_all=False)
Predict top k query labels given nearest matches in the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
database_labels |
array
|
Array containing the labels of the database. |
required |
k |
int
|
The number of top predictions to return. |
10
|
return_all |
bool
|
Indicates whether to return scores along with predictions. |
False
|
__call__(similarity)
Predicts the top k labels for each query based on the similarity matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
similarity |
A 2D similarity matrix with |
required |
Returns:
Type | Description |
---|---|
If
|
|
If
|