daniel-dona commited on
Commit
f2bdf39
·
1 Parent(s): 03423aa
Files changed (3) hide show
  1. README.md +3 -3
  2. app.py +1 -1
  3. src/SemanticSearch.py +8 -4
README.md CHANGED
@@ -11,10 +11,10 @@ pinned: false
11
  license: mit
12
  short_description: Demo of inference and SPARQL execution
13
  preload_from_hub:
14
- - daniel-dona/sparql-model-era-lora-128-qwen3-0.6b
15
- - daniel-dona/sparql-model-era-lora-128-qwen3-1.7b
16
  - daniel-dona/sparql-model-era-lora-128-qwen3-4b
17
- - daniel-dona/sparql-model-era-lora-128-qwen3-0.6b-grpo1
18
  ---
19
 
20
  Deployment demo for ERA finetuned model for SPARQL generation
 
11
  license: mit
12
  short_description: Demo of inference and SPARQL execution
13
  preload_from_hub:
14
+ #- daniel-dona/sparql-model-era-lora-128-qwen3-0.6b
15
+ #- daniel-dona/sparql-model-era-lora-128-qwen3-1.7b
16
  - daniel-dona/sparql-model-era-lora-128-qwen3-4b
17
+ #- daniel-dona/sparql-model-era-lora-128-qwen3-0.6b-grpo1
18
  ---
19
 
20
  Deployment demo for ERA finetuned model for SPARQL generation
app.py CHANGED
@@ -147,7 +147,7 @@ def generate_sparql(message, model_name, model_temperature, semantic_results, mo
147
 
148
  if semantic_results is not None:
149
 
150
- prompt = prompt_sparql_semantic.replace("%nlq", message).replace("%semantic", semantic_results)
151
 
152
  else:
153
 
 
147
 
148
  if semantic_results is not None:
149
 
150
+ prompt = prompt_sparql_semantic.replace("%nlq", message).replace("%semantic", json.dumps(semantic_results))
151
 
152
  else:
153
 
src/SemanticSearch.py CHANGED
@@ -7,6 +7,8 @@ import requests
7
  import itertools
8
  import torch
9
 
 
 
10
  import chromadb
11
 
12
  from SPARQLWrapper import SPARQLWrapper, JSON
@@ -24,7 +26,7 @@ WHERE {
24
  ?ne_uri a ?class_uri.
25
  ?ne_uri ne:prefLabel|ne:altLabel|rdfs:label ?ne_label .
26
  ?class_uri ne:prefLabel|ne:altLabel|rdfs:label ?class_label .
27
- ?ne_uri era:inCountry <http://publications.europa.eu/resource/authority/country/ESP> .
28
 
29
  #FILTER(STRSTARTS(STR(?ne_uri), "http://data.europa.eu/949/"))
30
  #FILTER(lang(?ne_label) = "en" || lang(?ne_label) = "")
@@ -199,17 +201,19 @@ class SemanticSearch:
199
 
200
  self.collection = client.get_collection(name=self.collection_name)
201
 
202
-
203
- def extract(self, nlq: str, n_results:int=25, str_match:bool=True, rerank:bool=True):
204
 
205
  embedding = self.get_text_embeddings_local([nlq])[0].tolist()
206
 
207
  results = self.collection.query(
208
  query_embeddings=[embedding],
209
- n_results=n_results,
210
  include=["documents", "distances", "metadatas", "uris"]
211
  )
212
 
 
 
213
  if rerank:
214
 
215
  documents = [f"'{item.lower()}' ({cls['class_label']})" for item, cls in zip(results["documents"][0], results["metadatas"][0])]
 
7
  import itertools
8
  import torch
9
 
10
+ import spaces
11
+
12
  import chromadb
13
 
14
  from SPARQLWrapper import SPARQLWrapper, JSON
 
26
  ?ne_uri a ?class_uri.
27
  ?ne_uri ne:prefLabel|ne:altLabel|rdfs:label ?ne_label .
28
  ?class_uri ne:prefLabel|ne:altLabel|rdfs:label ?class_label .
29
+ #?ne_uri era:inCountry <http://publications.europa.eu/resource/authority/country/ESP> .
30
 
31
  #FILTER(STRSTARTS(STR(?ne_uri), "http://data.europa.eu/949/"))
32
  #FILTER(lang(?ne_label) = "en" || lang(?ne_label) = "")
 
201
 
202
  self.collection = client.get_collection(name=self.collection_name)
203
 
204
+ @spaces.GPU
205
+ def extract(self, nlq: str, n_results:int=10, n_candidates:int=100, str_match:bool=True, rerank:bool=True):
206
 
207
  embedding = self.get_text_embeddings_local([nlq])[0].tolist()
208
 
209
  results = self.collection.query(
210
  query_embeddings=[embedding],
211
+ n_results=n_candidates,
212
  include=["documents", "distances", "metadatas", "uris"]
213
  )
214
 
215
+ print(results)
216
+
217
  if rerank:
218
 
219
  documents = [f"'{item.lower()}' ({cls['class_label']})" for item, cls in zip(results["documents"][0], results["metadatas"][0])]