Skip to content
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

Added donloading/loading for CQADupStack dataset to/from cached common location, and changed MAP to prevent pickling #17

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions pv211_utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def load_validation_judgements(self) -> ArqmathJudgements:
self._load_judgements(year2))
if q.query_id in self.load_validation_queries().keys()}

def load_answers(self, answer_class=ArqmathAnswerBase) -> OrderedDict:
def load_answers(self, answer_class=ArqmathAnswerBase, cache_directory="/var/tmp/pv211/") -> OrderedDict:
"""Load answers.

Returns
Expand All @@ -275,10 +275,10 @@ def load_answers(self, answer_class=ArqmathAnswerBase) -> OrderedDict:
return arqmath_loader.load_answers(
text_format=self.text_format,
answer_class=answer_class,
cache_download=f'/var/tmp/pv211/arqmath2020_answers_{self.text_format}.json.gz'
cache_download=(cache_directory + f'arqmath2020_answers_{self.text_format}.json.gz')
)

def load_questions(self, question_class=ArqmathQuestionBase) -> OrderedDict:
def load_questions(self, question_class=ArqmathQuestionBase, cache_directory="/var/tmp/pv211/") -> OrderedDict:
"""Load questions.

Returns
Expand All @@ -290,7 +290,8 @@ def load_questions(self, question_class=ArqmathQuestionBase) -> OrderedDict:
text_format=self.text_format,
answers=self.load_answers(),
question_class=question_class,
cache_download=f'/var/tmp/pv211/arqmath2020_questions_{self.text_format}.json.gz')
cache_download=(cache_directory + f'arqmath2020_questions_{self.text_format}.json.gz')
)


class CranfieldDataset():
Expand Down Expand Up @@ -578,7 +579,7 @@ def load_validation_judgements(self) -> TrecJudgements:
subset="validation"))
if q.query_id in self.load_validation_queries().keys()}

def load_documents(self, document_class=TrecDocumentBase) -> OrderedDict:
def load_documents(self, document_class=TrecDocumentBase, cache_directory="/var/tmp/pv211/") -> OrderedDict:
"""Load documents.

Returns
Expand All @@ -587,7 +588,7 @@ def load_documents(self, document_class=TrecDocumentBase) -> OrderedDict:
Dictionary of (document_id: Document) form.
"""
return trec_loader.load_documents(document_class=document_class,
cache_download='/var/tmp/pv211/trec_documents.json.gz')
cache_download=(cache_directory + 'trec_documents.json.gz'))


class BeirDataset():
Expand Down Expand Up @@ -744,7 +745,8 @@ class CQADupStackDataset():

"""

def __init__(self, download_location: str = "datasets", validation_split_size: float = 0.2) -> None:
def __init__(self, download_location: str = "/var/tmp/pv211/cqa_datasets",
validation_split_size: float = 0.2) -> None:
"""Check if arguments have legal values and construct attributes
for BeirDataset object.

Expand Down
6 changes: 2 additions & 4 deletions pv211_utils/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .entities import JudgementBase
from .leaderboard import LeaderboardBase
from .irsystem import IRSystemBase
from .evaluation_metrics import calc_map
from .evaluation_metrics import mean_average_precision

from IPython.display import display, Markdown

Expand Down Expand Up @@ -94,9 +94,7 @@ def evaluate(self, queries: OrderedDict, submit_result: bool = True) -> None:

"""
time_before = datetime.now()
# result = mean_average_precision(self.system, queries, self.judgements, self.k, self.num_workers)
m = calc_map()
result = m.mean_average_precision(self.system, queries, self.judgements, self.k, self.num_workers)
result = mean_average_precision(self.system, queries, self.judgements, self.k, self.num_workers)
time_after = datetime.now()
map_score = result * 100.0

Expand Down
Loading