Upload create_data_retrieval.py
Browse files- create_data_retrieval.py +31 -0
create_data_retrieval.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import pandas as pd
|
3 |
+
from huggingface_hub import create_repo, upload_file
|
4 |
+
from huggingface_hub.utils._errors import HfHubHTTPError
|
5 |
+
|
6 |
+
### Process articles ###
|
7 |
+
articles = pd.read_json("./syntec.json")
|
8 |
+
articles["content"] = articles["content"].str.replace("[En vigueur] ", "")
|
9 |
+
articles["content"] = articles["content"].str.replace("[En vigueur]\n", "")
|
10 |
+
|
11 |
+
### Process queries ###
|
12 |
+
queries = pd.read_excel("./Syntec.xlsx")
|
13 |
+
queries.drop(["Personne", "Réponse"], axis=1, inplace=True)
|
14 |
+
|
15 |
+
### Test ###
|
16 |
+
assert queries["Article"].isin(articles["id"]).all(),\
|
17 |
+
"Some queries's target documents are missing in documents corpus"
|
18 |
+
|
19 |
+
# create HF repo
|
20 |
+
repo_id = "lyon-nlp/mteb-fr-retrieval-syntec-s2p"
|
21 |
+
try:
|
22 |
+
create_repo(repo_id, repo_type="dataset")
|
23 |
+
except HfHubHTTPError as e:
|
24 |
+
print("HF repo already exist")
|
25 |
+
|
26 |
+
# save datasets as json
|
27 |
+
queries.to_json("queries.json", orient="records")
|
28 |
+
articles.to_json("documents.json", orient="records")
|
29 |
+
|
30 |
+
upload_file(path_or_fileobj="queries.json", path_in_repo="queries.json", repo_id=repo_id, repo_type="dataset")
|
31 |
+
upload_file(path_or_fileobj="documents.json", path_in_repo="documents.json", repo_id=repo_id, repo_type="dataset")
|