Commit 9b0ca61c authored by Jerome Wuerf's avatar Jerome Wuerf
Browse files

Add reranking startegy parpameter of mu

parent da2a25ba
......@@ -141,11 +141,11 @@ class MaximalMarginalRelevanceReranking(Reranking):
def __init__(self, premises_per_conclusions_per_topics: dict,
run_name: str,
conclusions_lambda: float = 0.5,
premises_lambda: float = 0.5):
lambdac: float = 0.5,
lambdap: float = 0.5):
super().__init__(premises_per_conclusions_per_topics, 'mmr', run_name)
self.conclusion_lambda = conclusions_lambda
self.premises_lambda = premises_lambda
self.lambdac = lambdac
self.lambdap = lambdap
def rerank(self) -> None:
......@@ -166,24 +166,30 @@ class MaximalMarginalRelevanceReranking(Reranking):
"""
for _, premises_per_conclusions in tqdm(self.premises_per_conclusions_per_topics.items()):
conclusions = [element['conclusion'] for element in premises_per_conclusions.values()]
mmr_generic(conclusions, self.conclusion_lambda)
mmr_generic(conclusions, self.lambdac)
for premises_per_conclusion in tqdm(premises_per_conclusions.values()):
mmr_generic(premises_per_conclusion['premises'], self.premises_lambda)
mmr_generic(premises_per_conclusion['premises'], self.lambdap)
class StructuralDistanceReranking(Reranking):
def __init__(self, premises_per_conclusions_per_topics: dict,
run_name: str,
topics):
topics,
mup,
muc):
super().__init__(premises_per_conclusions_per_topics, 'sd', run_name)
self.topics = topics
self.mup = mup
self.muc = muc
def rerank(self) -> None:
def reranking_strategy_conclusions(x):
return x['conclusion'][self.reranking_key] * 0.1 + x['conclusion']['_score'] / 2 * 0.9
return x['conclusion'][
self.reranking_key] * (
1 - self.muc) + x['conclusion']['_score'] / 2 * self.muc
def reranking_strategy_premises(x):
return x[self.reranking_key] * 0.25 + x['_score'] / 2 * 0.75
return x[self.reranking_key] * (1 - self.mup) + x['_score'] / 2 * self.mup
super()._rerank(
super()._generic_score_calculation(structural_distance),
......@@ -194,16 +200,22 @@ class StructuralDistanceReranking(Reranking):
class WordMoverDistanceReranking(Reranking):
def __init__(self, premises_per_conclusions_per_topics: dict,
run_name: str,
topics):
topics,
mup,
muc):
super().__init__(premises_per_conclusions_per_topics, 'wmd', run_name)
self.topics = topics
self.mup = mup
self.muc = muc
def rerank(self) -> None:
def reranking_strategy_conclusions(x):
return x['conclusion'][self.reranking_key] * 0.1 + x['conclusion']['_score'] / 2 * 0.9
return x['conclusion'][
self.reranking_key] * (
1 - self.muc) + x['conclusion']['_score'] / 2 * self.muc
def reranking_strategy_premises(x):
return x[self.reranking_key] * 0.25 + x['_score'] / 2 * 0.75
return x[self.reranking_key] * (1 - self.mup) + x['_score'] / 2 * self.mup
super()._rerank(
self._generic_score_calculation(word_mover_distance),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment