tillwenke commited on
Commit
fa4acc1
1 Parent(s): 1031552

init with scrip for ds generation

Browse files
.gitattributes CHANGED
@@ -53,3 +53,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
 
 
53
  *.jpg filter=lfs diff=lfs merge=lfs -text
54
  *.jpeg filter=lfs diff=lfs merge=lfs -text
55
  *.webp filter=lfs diff=lfs merge=lfs -text
56
+ training11b.json filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ /env
bioasq_ir_pubmed_corpus_subset.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import pandas as pd
4
+ from Bio import Entrez
5
+ from retry import retry
6
+ from tqdm import tqdm
7
+
8
+ # provided your NIH credentials
9
+ Entrez.email = "***"
10
+ Entrez.api_key = "***"
11
+
12
+
13
+ # change output file names here if necessary
14
+ RAW_EVALUATION_DATASET = "training11b.json"
15
+ PATH_TO_PASSAGE_DATASET = "./passages.parquet"
16
+ PATH_TO_EVALUATION_DATASET = "./eval.parquet"
17
+
18
+ # only use questions that have at most MAX_PASSAGES passages to control the size of the dataset
19
+ # set to None to use all passages
20
+ MAX_PASSAGES = None
21
+
22
+
23
+ @retry()
24
+ def get_abstract(passage_id):
25
+ with Entrez.efetch(
26
+ db="pubmed", id=passage_id, rettype="abstract", retmode="text"
27
+ ) as response:
28
+ # get only the abstract - no metadata
29
+ r = response.read()
30
+ r = r.split("\n\n")
31
+ abstract = max(r, key=len)
32
+ return abstract
33
+
34
+
35
+ if __name__ == "__main__":
36
+ # load the training data containing the questions, answers and the ids of relevant passages
37
+ # but lacks the actual passages
38
+ with open(RAW_EVALUATION_DATASET) as f:
39
+ eval_data = json.load(f)["questions"]
40
+
41
+ eval_df = pd.DataFrame(eval_data, columns=["body", "documents", "ideal_answer"])
42
+ eval_df = eval_df.rename(
43
+ columns={
44
+ "body": "question",
45
+ "documents": "relevant_passages",
46
+ "ideal_answer": "answer",
47
+ }
48
+ )
49
+ eval_df.answer = eval_df.answer.apply(lambda x: x[0])
50
+ # get abstract id from url
51
+ eval_df.relevant_passages = eval_df.relevant_passages.apply(
52
+ lambda x: [url.split("/")[-1] for url in x]
53
+ )
54
+ if MAX_PASSAGES:
55
+ eval_df["passage_count"] = eval_df.relevant_passages.apply(lambda x: len(x))
56
+ eval_df = eval_df.drop(columns=["passage_count"])
57
+
58
+ # remove duplicate passage ids
59
+ eval_df.relevant_passages = eval_df.relevant_passages.apply(lambda x: set(x))
60
+ eval_df.relevant_passages = eval_df.relevant_passages.apply(lambda x: list(x))
61
+
62
+ # get all passage ids that are relevant
63
+ passage_ids = set().union(*eval_df.relevant_passages)
64
+ passage_ids = list(passage_ids)
65
+ passages = pd.DataFrame(index=passage_ids)
66
+
67
+ for i, passage_id in enumerate(tqdm(passages.index)):
68
+ passages.loc[passage_id, "passage"] = get_abstract(passage_id)
69
+
70
+ # intermidiate save
71
+ if i % 4000 == 0:
72
+ passages.to_parquet(PATH_TO_PASSAGE_DATASET)
73
+
74
+ # filter out the passages whos pmids (pubmed ids) where not available
75
+ unavailable_passages = passages[passages["passage"] == "1. "]
76
+ passages = passages[passages["passage"] != "1. "]
77
+ passages.to_parquet(PATH_TO_PASSAGE_DATASET)
78
+
79
+ # remove passages from evaluation dataset whose abstract could not be retrieved from pubmed website
80
+ unavailable_ids = unavailable_passages.index.tolist()
81
+ eval_df["relevant_passages"] = eval_df["relevant_passages"].apply(
82
+ lambda x: [i for i in x if i not in unavailable_ids]
83
+ )
84
+ eval_df.to_parquet(PATH_TO_EVALUATION_DATASET)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ biopython
2
+ pandas
3
+ retry
4
+ tqdm
training11b.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6df656862ca860efc355c7805d07ddca700d64ecc3785c519a49afccaaeeac98
3
+ size 37639648