forked from castorini/anserini
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TASB and TCT-V2 integration test (Issue#638) (castorini#658)
* add tct_colbert-v2 integration test * add distilbert_tasb integration test Co-authored-by: Lin Jack <[email protected]> Co-authored-by: justram <[email protected]>
- Loading branch information
1 parent
bc9276e
commit e42cdfe
Showing
2 changed files
with
213 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# | ||
# Pyserini: Reproducible IR research with sparse and dense representations | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
"""Integration tests for TASB model using on-the-fly query encoding.""" | ||
|
||
import os | ||
import socket | ||
import unittest | ||
|
||
from integrations.utils import clean_files, run_command, parse_score | ||
from pyserini.dsearch import QueryEncoder | ||
from pyserini.search import get_topics | ||
|
||
|
||
class TestSearchIntegration(unittest.TestCase): | ||
def setUp(self): | ||
self.temp_files = [] | ||
self.threads = 12 | ||
self.batch_size = 36 | ||
|
||
# Hard-code larger values for internal servers | ||
if socket.gethostname().startswith('damiano') or socket.gethostname().startswith('orca'): | ||
self.threads = 36 | ||
self.batch_size = 144 | ||
|
||
def test_msmarco_passage_distilbert_kd_tas_b_bf_otf(self): | ||
output_file = 'test_run.msmarco-passage.distilbert-dot-tas_b-b256.bf.tsv' | ||
self.temp_files.append(output_file) | ||
cmd1 = f'python -m pyserini.dsearch --topics msmarco-passage-dev-subset \ | ||
--index msmarco-passage-distilbert-dot-tas_b-b256-bf \ | ||
--encoder sebastian-hofstaetter/distilbert-dot-tas_b-b256-msmarco \ | ||
--batch-size {self.batch_size} \ | ||
--threads {self.threads} \ | ||
--output {output_file} \ | ||
--output-format msmarco' | ||
cmd2 = f'python -m pyserini.eval.msmarco_passage_eval msmarco-passage-dev-subset {output_file}' | ||
status = os.system(cmd1) | ||
stdout, stderr = run_command(cmd2) | ||
score = parse_score(stdout, "MRR @10") | ||
self.assertEqual(status, 0) | ||
self.assertEqual(stderr, '') | ||
self.assertAlmostEqual(score, 0.3444, delta=0.0001) | ||
|
||
def test_msmarco_passage_distilbert_kd_tas_b_encoded_queries(self): | ||
encoder = QueryEncoder.load_encoded_queries('distilbert_tas_b-msmarco-passage-dev-subset') | ||
topics = get_topics('msmarco-passage-dev-subset') | ||
for t in topics: | ||
self.assertTrue(topics[t]['title'] in encoder.embedding) | ||
|
||
def tearDown(self): | ||
clean_files(self.temp_files) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,145 @@ | ||
# | ||
# Pyserini: Reproducible IR research with sparse and dense representations | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
"""Integration tests for TCT-ColBERT model using on-the-fly query encoding.""" | ||
|
||
import os | ||
import socket | ||
import unittest | ||
|
||
from integrations.utils import clean_files, run_command, parse_score | ||
from pyserini.dsearch import QueryEncoder | ||
from pyserini.search import get_topics | ||
|
||
|
||
class TestSearchIntegration(unittest.TestCase): | ||
def setUp(self): | ||
self.temp_files = [] | ||
self.threads = 12 | ||
self.batch_size = 36 | ||
|
||
# Hard-code larger values for internal servers | ||
if socket.gethostname().startswith('damiano') or socket.gethostname().startswith('orca'): | ||
self.threads = 36 | ||
self.batch_size = 144 | ||
|
||
def test_msmarco_passage_tct_colbert_v2_bf_otf(self): | ||
output_file = 'test_run.msmarco-passage.tct_colbert-v2.bf-otf.tsv' | ||
self.temp_files.append(output_file) | ||
cmd1 = f'python -m pyserini.dsearch --topics msmarco-passage-dev-subset \ | ||
--index msmarco-passage-tct_colbert-v2-bf \ | ||
--encoder castorini/tct_colbert-v2-msmarco \ | ||
--batch-size {self.batch_size} \ | ||
--threads {self.threads} \ | ||
--output {output_file} \ | ||
--output-format msmarco' | ||
cmd2 = f'python -m pyserini.eval.msmarco_passage_eval msmarco-passage-dev-subset {output_file}' | ||
status = os.system(cmd1) | ||
stdout, stderr = run_command(cmd2) | ||
score = parse_score(stdout, "MRR @10") | ||
self.assertEqual(status, 0) | ||
self.assertAlmostEqual(score, 0.3439, places=4) | ||
|
||
def test_msmarco_passage_tct_colbert_v2_hn_otf(self): | ||
output_file = 'test_run.msmarco-passage.tct_colbert-v2-hn.bf-otf.tsv' | ||
self.temp_files.append(output_file) | ||
cmd1 = f'python -m pyserini.dsearch --topics msmarco-passage-dev-subset \ | ||
--index msmarco-passage-tct_colbert-v2-hn-bf \ | ||
--encoder castorini/tct_colbert-v2-hn-msmarco \ | ||
--output {output_file} \ | ||
--output-format msmarco ' | ||
cmd2 = f'python -m pyserini.eval.msmarco_passage_eval msmarco-passage-dev-subset {output_file}' | ||
status = os.system(cmd1) | ||
stdout, stderr = run_command(cmd2) | ||
score = parse_score(stdout, "MRR @10") | ||
self.assertEqual(status, 0) | ||
self.assertAlmostEqual(score, 0.3542, places=4) | ||
|
||
def test_msmarco_passage_tct_colbert_v2_hnp_otf(self): | ||
output_file = 'test_run.msmarco-passage.tct_colbert-v2-hnp.bf-otf.tsv' | ||
self.temp_files.append(output_file) | ||
cmd1 = f'python -m pyserini.dsearch --topics msmarco-passage-dev-subset \ | ||
--index msmarco-passage-tct_colbert-v2-hnp-bf \ | ||
--encoder castorini/tct_colbert-v2-hnp-msmarco \ | ||
--output {output_file} \ | ||
--output-format msmarco ' | ||
cmd2 = f'python -m pyserini.eval.msmarco_passage_eval msmarco-passage-dev-subset {output_file}' | ||
status = os.system(cmd1) | ||
stdout, stderr = run_command(cmd2) | ||
score = parse_score(stdout, "MRR @10") | ||
self.assertEqual(status, 0) | ||
self.assertAlmostEqual(score, 0.3584, places=4) | ||
|
||
def test_msmarco_passage_tct_colbert_v2_hnp_bf_bm25_hybrid_otf(self): | ||
output_file = 'test_run.msmarco-passage.tct_colbert-v2-hnp.bf-otf.bm25.tsv' | ||
self.temp_files.append(output_file) | ||
cmd1 = f'python -m pyserini.hsearch dense --index msmarco-passage-tct_colbert-v2-hnp-bf \ | ||
--encoder castorini/tct_colbert-v2-hnp-msmarco \ | ||
sparse --index msmarco-passage \ | ||
fusion --alpha 0.12 \ | ||
run --topics msmarco-passage-dev-subset \ | ||
--output {output_file} \ | ||
--batch-size {self.batch_size} --threads {self.threads} \ | ||
--output-format msmarco' | ||
cmd2 = f'python -m pyserini.eval.msmarco_passage_eval msmarco-passage-dev-subset {output_file}' | ||
status = os.system(cmd1) | ||
stdout, stderr = run_command(cmd2) | ||
score = parse_score(stdout, "MRR @10") | ||
self.assertEqual(status, 0) | ||
self.assertAlmostEqual(score, 0.3683, places=4) | ||
|
||
def test_msmarco_passage_tct_colbert_v2_hnp_bf_d2q_hybrid_otf(self): | ||
output_file = 'test_run.msmarco-passage.tct_colbert-v2-hnp.bf-otf.doc2queryT5.tsv' | ||
self.temp_files.append(output_file) | ||
cmd1 = f'python -m pyserini.hsearch dense --index msmarco-passage-tct_colbert-v2-hnp-bf \ | ||
--encoder castorini/tct_colbert-v2-hnp-msmarco \ | ||
sparse --index msmarco-passage-expanded \ | ||
fusion --alpha 0.22 \ | ||
run --topics msmarco-passage-dev-subset \ | ||
--output {output_file} \ | ||
--batch-size {self.batch_size} --threads {self.threads} \ | ||
--output-format msmarco' | ||
cmd2 = f'python -m pyserini.eval.msmarco_passage_eval msmarco-passage-dev-subset {output_file}' | ||
status = os.system(cmd1) | ||
stdout, stderr = run_command(cmd2) | ||
score = parse_score(stdout, "MRR @10") | ||
self.assertEqual(status, 0) | ||
self.assertAlmostEqual(score, 0.3730, places=4) | ||
|
||
def test_msmarco_passage_tct_colbert_v2_encoded_queries(self): | ||
encoder = QueryEncoder.load_encoded_queries('tct_colbert-v2-msmarco-passage-dev-subset') | ||
topics = get_topics('msmarco-passage-dev-subset') | ||
for t in topics: | ||
self.assertTrue(topics[t]['title'] in encoder.embedding) | ||
|
||
def test_msmarco_passage_tct_colbert_v2_hn_encoded_queries(self): | ||
encoder = QueryEncoder.load_encoded_queries('tct_colbert-v2-hn-msmarco-passage-dev-subset') | ||
topics = get_topics('msmarco-passage-dev-subset') | ||
for t in topics: | ||
self.assertTrue(topics[t]['title'] in encoder.embedding) | ||
|
||
def test_msmarco_passage_tct_colbert_v2_hnp_encoded_queries(self): | ||
encoder = QueryEncoder.load_encoded_queries('tct_colbert-v2-hnp-msmarco-passage-dev-subset') | ||
topics = get_topics('msmarco-passage-dev-subset') | ||
for t in topics: | ||
self.assertTrue(topics[t]['title'] in encoder.embedding) | ||
|
||
def tearDown(self): | ||
clean_files(self.temp_files) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |