-
Notifications
You must be signed in to change notification settings - Fork 7
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
Compilation #33
Merged
Merged
Compilation #33
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
014d08a
examples of compile operations
cmacdonald 6f9ae27
fix fusion cutoff - hat tip to Sean
cmacdonald 8459f05
add for both prfs
cmacdonald 655f060
add a unit test for compilation
cmacdonald d513f6b
address review feedback
cmacdonald 8e5adbc
and this one
cmacdonald 7fa0c63
syntax fix
cmacdonald 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
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
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
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
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
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,55 @@ | ||
import unittest | ||
import tempfile | ||
import unittest | ||
import numpy as np | ||
import pandas as pd | ||
import pyterrier_dr | ||
from pyterrier_dr import FlexIndex | ||
|
||
class TestFlexIndex(unittest.TestCase): | ||
|
||
def _generate_data(self, count=2000, dim=100): | ||
def random_unit_vec(): | ||
v = np.random.rand(dim).astype(np.float32) | ||
return v / np.linalg.norm(v) | ||
return [ | ||
{'docno': str(i), 'doc_vec': random_unit_vec()} | ||
for i in range(count) | ||
] | ||
|
||
def test_compilation_with_rank_and_averageprf(self): | ||
self._test_compilation_with_rank_and_prf(pyterrier_dr.AveragePrf) | ||
|
||
def test_compilation_with_rank_and_vectorprf(self): | ||
self._test_compilation_with_rank_and_prf(pyterrier_dr.VectorPrf) | ||
|
||
def _test_compilation_with_rank_and_prf(self, prf_clz): | ||
|
||
with tempfile.TemporaryDirectory() as destdir: | ||
index = FlexIndex(destdir+'/index') | ||
dataset = self._generate_data(count=2000) | ||
index.index(dataset) | ||
|
||
retr = index.retriever() | ||
queries = pd.DataFrame([ | ||
{'qid': '0', 'query_vec': dataset[0]['doc_vec']}, | ||
{'qid': '1', 'query_vec': dataset[1]['doc_vec']}, | ||
]) | ||
|
||
pipe1 = retr >> prf_clz(k=3) >> retr | ||
pipe1_opt = pipe1.compile() | ||
self.assertEqual(3, pipe1_opt[0].num_results) | ||
self.assertEqual(1000, pipe1_opt[-1].num_results) | ||
#NB: pipe1 wouldnt actually work for PRF, as doc_vecs are not present. however compilation is valid | ||
|
||
pipe2 = retr >> index.vec_loader() >> pyterrier_dr.AveragePrf(k=3) >> (retr % 2) | ||
pipe2_opt = pipe2.compile() | ||
self.assertEqual(3, pipe2_opt[0].num_results) | ||
self.assertEqual(2, pipe2_opt[-1].num_results) | ||
|
||
res2 = pipe2(queries) | ||
res2_opt = pipe2_opt(queries) | ||
|
||
pd.testing.assert_frame_equal(res2, res2_opt) | ||
|
||
|
Oops, something went wrong.
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.
I'm not certain that some of the ANN retrievers should get the fuse, since some implementations change the results can change based on
num_results
.