Geraldine commited on
Commit
6df123f
1 Parent(s): 98bc8b8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +84 -3
README.md CHANGED
@@ -1,3 +1,84 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ task_categories:
4
+ - feature-extraction
5
+ language:
6
+ - fr
7
+ - en
8
+ ---
9
+
10
+ This dataset comes from a request on the HAL API (the French national open archive) limited to the UNIV-COTEDAZUR portal instance.
11
+ The request collects the bibliographic records of the SHS articles with abstract published between 2013 and 2023
12
+
13
+ The parameters passed in the url request are :
14
+
15
+ https://api.archives-ouvertes.fr/search/UNIV-COTEDAZUR/?q=docType_s:ART&fq=abstract_s:[%22%22%20TO%20*]&fq=domain_s:*shs*&fq=submittedDateY_i:[2020%20TO%202023]&fl=doiId_s,uri_s,title_s,subTitle_s,authFullName_s,producedDate_s,journalTitle_s,journalPublisher_s,abstract_s,domain_s,openAccess_bool
16
+
17
+ The embeddings column stores the embeddings of the "combined" column values converted in vectors with the sentence-transformers/all-MiniLM-L6-v2 embeddinsg model.
18
+
19
+ ## Metadata extraction
20
+
21
+ ```
22
+ url = ""https://api.archives-ouvertes.fr/search/UNIV-COTEDAZUR/?q=docType_s:ART&fq=abstract_s:[%22%22%20TO%20*]&fq=domain_s:*shs*&fq=publicationDateY_i:[2013%20TO%202023]&fl=doiId_s,uri_s,title_s,subTitle_s,authFullName_s,producedDate_s,journalTitle_s,journalPublisher_s,abstract_s,domain_s,openAccess_bool"
23
+
24
+ # Get the total number of records
25
+ url_for_total_count = f"{url}&wt=json&rows=0"
26
+ response = requests.request("GET", url_for_total_count).text
27
+ data = json.loads(response)
28
+ total_count = data["response"]["numFound"]
29
+ print(total_cout)
30
+ # return 3601
31
+
32
+ # Loop over the records and get metadata
33
+ step = 500
34
+ appended_data = []
35
+ for i in range(1, int(total_count), int(step)):
36
+ url = f"{url}&rows={step}&start={i}&wt=csv"
37
+ df = pd.read_csv(url, encoding="utf-8")
38
+ appended_data.append(df)
39
+ appended_data = pd.concat(appended_data)
40
+
41
+ # dedup
42
+ appended_data = appended_data.drop_duplicates(subset=['uri_s'])
43
+
44
+ appended_data.shape
45
+ # returns 2405
46
+ ```
47
+
48
+ ## Add embeddings (CPU)
49
+
50
+ ### Solution 1 : with HF Inference API
51
+
52
+ ```
53
+ import requests
54
+ import json
55
+ from typing import Optional, List, Dict, Any
56
+
57
+ HF_TOKEN = "<hf_token>"
58
+ model_id = "sentence-transformers/all-MiniLM-L6-v2"
59
+
60
+ embeddings_api_url = f"https://api-inference.huggingface.co/pipeline/feature-extraction/{model_id}"
61
+ headers = {"Authorization": f"Bearer {HF_TOKEN}"}
62
+
63
+ def embeddings_query(text:str) -> List:
64
+ response = requests.post(embeddings_api_url, headers=headers, json={"inputs": text, "options":{"wait_for_model":True}})
65
+ return response.json()
66
+
67
+ df = appended_data.replace(np.nan, '')
68
+ df['embeddings'] = df.combined.apply(lambda x:embeddings_query(x.strip()))
69
+ ```
70
+
71
+ ### Solution 2 : with sentence-transformers library
72
+
73
+ ```
74
+ from sentence_transformers import SentenceTransformer
75
+
76
+ model_id = "sentence-transformers/all-mpnet-base-v2"
77
+ embedder = SentenceTransformer(model_id)
78
+
79
+ def embeddings_query(text:str) -> List:
80
+ return embedder.encode(text,convert_to_tensor=True)
81
+
82
+ df['embeddings'] = df.combined.apply(lambda x:embeddings_query(x.strip().to_list()))
83
+
84
+ ```