Matej commited on
Commit
33e76a1
·
verified ·
1 Parent(s): 423f849

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +73 -3
  2. adapter_config.json +37 -0
  3. adapter_model.safetensors +3 -0
README.md CHANGED
@@ -1,3 +1,73 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ base_model:
6
+ - meta-llama/Meta-Llama-3-8B-Instruct
7
+ pipeline_tag: text-generation
8
+ tags:
9
+ - Food
10
+ - NEL
11
+ - NER
12
+ ---
13
+ # 'FoodSEM: Large Language Model Specialized in Food Named-Entity Linking'
14
+
15
+ ## The model is based on Meta-Llama-3-8B-Instruct, which was fine-tuned (using LoRA) for food named entity recognition and linking tasks.
16
+
17
+
18
+ ## How to use it: ##
19
+
20
+ ```python
21
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
22
+ import torch
23
+
24
+
25
+ if __name__ == '__main__':
26
+ base_model = "meta-llama/Meta-Llama-3-8B-Instruct"
27
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
28
+
29
+ bnb_config = BitsAndBytesConfig(
30
+ load_in_4bit=True,
31
+ bnb_4bit_quant_type="nf4",
32
+ bnb_4bit_compute_dtype=torch.float16,
33
+ bnb_4bit_use_double_quant=True,
34
+ )
35
+
36
+ model = AutoModelForCausalLM.from_pretrained(
37
+ base_model,
38
+ quantization_config=bnb_config,
39
+ device_map={"": 0},
40
+ attn_implementation="eager"
41
+ )
42
+
43
+ tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)
44
+
45
+ tokenizer.pad_token = '<|pad|>'
46
+ tokenizer.pad_token_id = 128255
47
+
48
+ #Load LORA weights
49
+ model.load_adapter("Anonymous-pre-publication/FoodSEM-LLM")
50
+ model.config.use_cache = True
51
+ model.eval()
52
+
53
+ system_prompt = ""
54
+ user_prompt = "Please, may we have links to the Hansard taxonomy for these entities provided: soft butter, mango, daiquiri mixer, maple extract, salt, anise flavored liqueur, hemp seeds, yeast mixture, thighs?"
55
+
56
+ messages = [
57
+ {
58
+ "role": "user",
59
+ "content": f"{system_prompt} {user_prompt}".strip()
60
+ }
61
+ ]
62
+
63
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
64
+
65
+ #Here we have a batch of one
66
+ tokenizer_input = [prompt]
67
+
68
+ inputs = tokenizer(tokenizer_input, return_tensors="pt", padding=True, truncation=True, max_length=1024).to(device)
69
+ generated_ids = model.generate(**inputs, max_new_tokens=1024, do_sample=True)
70
+ answers = tokenizer.batch_decode(generated_ids[:, inputs['input_ids'].shape[1]:])
71
+ answers = [x.split('<|eot_id|>')[0].strip() for x in answers]
72
+ print(answers)
73
+ ```
adapter_config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": null,
4
+ "base_model_name_or_path": "meta-llama/Meta-Llama-3-8B-Instruct",
5
+ "bias": "none",
6
+ "eva_config": null,
7
+ "exclude_modules": null,
8
+ "fan_in_fan_out": false,
9
+ "inference_mode": true,
10
+ "init_lora_weights": true,
11
+ "layer_replication": null,
12
+ "layers_pattern": null,
13
+ "layers_to_transform": null,
14
+ "loftq_config": {},
15
+ "lora_alpha": 16,
16
+ "lora_bias": false,
17
+ "lora_dropout": 0.05,
18
+ "megatron_config": null,
19
+ "megatron_core": "megatron.core",
20
+ "modules_to_save": null,
21
+ "peft_type": "LORA",
22
+ "r": 16,
23
+ "rank_pattern": {},
24
+ "revision": null,
25
+ "target_modules": [
26
+ "up_proj",
27
+ "o_proj",
28
+ "down_proj",
29
+ "q_proj",
30
+ "k_proj",
31
+ "gate_proj",
32
+ "v_proj"
33
+ ],
34
+ "task_type": "CAUSAL_LM",
35
+ "use_dora": false,
36
+ "use_rslora": false
37
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d5fac1738a0f0b9000a85e1ed652fe17a2e1539f7144195dfaa0f1910e4a217a
3
+ size 167832240