A fine-tuned version of
BSC-LT/salamandra-7b-instruct-tools for converting natural language queries into structured JSON for R&D project semantic search.
This model was developed as part of the
IMPULS project (AINA Challenge 2024), a collaboration between
SIRIS Academic and
Generalitat de Catalunya to build a multilingual semantic search system for Catalonia's R&D ecosystem (RIS3-MCAT platform).
1{
2 "doc_type": "projects",
3 "filters": {
4 "programme": "Horizon 2020",
5 "year": ">=2020"
6 },
7 "organisations": [],
8 "semantic_query": "intel·ligència artificial salut",
9 "query_rewrite": "Projectes sobre IA en salut del programa H2020 des de 2020",
10 "meta": {
11 "lang": "CA"
12 }
13}
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_id = "SIRIS-Lab/impuls-salamandra-7b-query-parser"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 torch_dtype=torch.float16,
10 device_map="auto"
11)
12
13# System prompt (simplified version)
14system_prompt = """Convert natural language queries into structured JSON for R&D project search.
15Output only valid JSON with the required schema."""
16
17query = "projectes d'hidrogen finançats per H2020 des de 2020"
18
19messages = [
20 {"role": "system", "content": system_prompt},
21 {"role": "user", "content": query}
22]
23
24input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
25inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
26
27with torch.no_grad():
28 outputs = model.generate(
29 **inputs,
30 max_new_tokens=512,
31 temperature=0.1,
32 do_sample=True
33 )
34
35response = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
36print(response)
1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2import torch
3
4quantization_config = BitsAndBytesConfig(
5 load_in_4bit=True,
6 bnb_4bit_compute_dtype=torch.float16,
7 bnb_4bit_quant_type="nf4"
8)
9
10model = AutoModelForCausalLM.from_pretrained(
11 "SIRIS-Lab/impuls-salamandra-7b-query-parser",
12 quantization_config=quantization_config,
13 device_map="auto"
14)
15# Reduces memory from ~14GB to ~3.5GB
1{
2 "doc_type": "projects",
3 "filters": {
4 "programme": "string | null",
5 "funding_level": "string | null",
6 "year": "string | null",
7 "location": "string | null",
8 "location_level": "region | province | country | null"
9 },
10 "organisations": [
11 {
12 "type": "university | research_center | hospital | company | null",
13 "name": "string | null",
14 "location": "string | null",
15 "location_level": "string | null"
16 }
17 ],
18 "semantic_query": "string | null",
19 "query_rewrite": "string",
20 "meta": {
21 "lang": "CA | ES | EN",
22 "notes": "string | null"
23 }
24}
1@misc{impuls-salamandra-2024,
2 author = {SIRIS Academic},
3 title = {IMPULS-Salamandra-7B-Query-Parser: Multilingual Query Parsing for R&D Semantic Search},
4 year = {2024},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/SIRIS-Lab/impuls-salamandra-7b-query-parser}}
7}
This model is released under the
Apache 2.0 License, consistent with the base Salamandra model.