Spaces:
Runtime error
Runtime error
File size: 2,385 Bytes
d6585f5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
#
# 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 KILT integration."""
import os
import re
import socket
import unittest
from integrations.utils import clean_files, run_command
def parse_kilt_score(output, metric, digits=4):
pattern = re.compile(r"[0-1]\.[0-9]*")
for line in output.split('\n')[::-1]:
if metric in line:
score = float(pattern.search(line).group(0))
return round(score, digits)
return None
class TestSearchIntegration(unittest.TestCase):
def setUp(self):
self.temp_files = []
self.threads = 16
self.batch_size = 256
# 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_kilt_search(self):
run_file = 'test_run.fever-dev-kilt.jsonl'
self.temp_files.append(run_file)
cmd1 = f'python -m pyserini.search --topics fever-dev-kilt \
--topics-format kilt \
--index wikipedia-kilt-doc \
--output {run_file} \
--output-format kilt \
--threads {self.threads} \
--batch-size {self.batch_size}'
status = os.system(cmd1)
self.assertEqual(status, 0)
cmd2 = f'python -m pyserini.eval.evaluate_kilt_retrieval {run_file} fever-dev-kilt --ks 1,100'
stdout, stderr = run_command(cmd2)
score = parse_kilt_score(stdout, "Rprec")
self.assertAlmostEqual(score, 0.3821, delta=0.0001)
def tearDown(self):
clean_files(self.temp_files)
if __name__ == '__main__':
unittest.main()
|