Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* switch to argparse for more standard CLI arguments * new measures: Pearson rank, Spearman, and KL divergence
- Loading branch information
Showing
13 changed files
with
256 additions
and
183 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,24 @@ | ||
name: test | ||
on: [push] | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.6, 3.7, 3.8] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
pip install -r requirements.txt | ||
- name: Test with pytest | ||
run: | | ||
export PYTHONPATH=${PYTHONPATH}:/home/runner/work/capreolus/diffir | ||
pytest | ||
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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
__version__ = "0.1.0" | ||
|
||
from diffir.weight import Weight | ||
from diffir.weight.custom import CustomWeight | ||
from diffir.weight.unsupervised import ExactMatchWeight | ||
from diffir.measure import Measure | ||
from diffir.measure.qrels import QrelMeasure | ||
from diffir.measure.unsupervised import TopkMeasure |
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 |
---|---|---|
@@ -1,26 +1,27 @@ | ||
from profane import ModuleBase, import_all_modules, ConfigOption | ||
class Measure: | ||
def __init__(self, metric="ndcg_20", topk=5): | ||
''' | ||
Measure construction | ||
:param metric: The metric used for selecting queries. | ||
:param topk: How many queries to retrieve | ||
''' | ||
self.metric = metric | ||
self.topk = topk | ||
|
||
|
||
class Measure(ModuleBase): | ||
module_type = "measure" | ||
config_spec = [ | ||
ConfigOption(key="metric", default_value="ndcg_20", description="The metric to use for selecting queries"), | ||
ConfigOption(key="topk", default_value=5, description="How many queries to retrieve"), | ||
] | ||
|
||
# TODO finalize API | ||
def query_differences(self, run1, run2, *args, **kwargs): | ||
''' | ||
:param run1: the first run | ||
:param run2: the second run | ||
:param args: | ||
:param kwargs: | ||
:return: | ||
''' | ||
if run1 and run2: | ||
return self._query_differences(run1, run2, *args, **kwargs) | ||
elif run1 and run2 is None: | ||
qids = sorted(list(run1.keys()))[: self.config["topk"]] | ||
qids = sorted(list(run1.keys()))[: self.topk] | ||
id2diff = {qid: 0 for qid in qids} | ||
return qids, id2diff, "singlerun" | ||
|
||
def _query_differences(self, run1, run2, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
|
||
# TODO this is going to break once we introduce optional modules. need a way for them to fail gracefully. | ||
# or to enumerate/register them without importing the py file? | ||
import_all_modules(__file__, __package__) |
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
Oops, something went wrong.