devanshamin commited on
Commit
208b123
·
verified ·
1 Parent(s): 03fb4d3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +87 -20
README.md CHANGED
@@ -9,6 +9,7 @@ tags:
9
  model-index:
10
  - name: Qwen2-1.5B-Instruct-Function-Calling-v1
11
  results: []
 
12
  ---
13
 
14
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
@@ -16,21 +17,85 @@ should probably proofread and complete it, then remove this comment. -->
16
 
17
  # Qwen2-1.5B-Instruct-Function-Calling-v1
18
 
19
- This model is a fine-tuned version of [Qwen/Qwen2-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2-1.5B-Instruct) on an unknown dataset.
20
- It achieves the following results on the evaluation set:
21
- - Loss: 0.2248
22
-
23
- ## Model description
24
-
25
- More information needed
26
-
27
- ## Intended uses & limitations
28
-
29
- More information needed
30
-
31
- ## Training and evaluation data
32
-
33
- More information needed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  ## Training procedure
36
 
@@ -64,8 +129,10 @@ The following hyperparameters were used during training:
64
 
65
  ### Framework versions
66
 
67
- - PEFT 0.11.1
68
- - Transformers 4.42.3
69
- - Pytorch 2.3.1+cu121
70
- - Datasets 2.20.0
71
- - Tokenizers 0.19.1
 
 
 
9
  model-index:
10
  - name: Qwen2-1.5B-Instruct-Function-Calling-v1
11
  results: []
12
+ pipeline_tag: text-generation
13
  ---
14
 
15
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
 
17
 
18
  # Qwen2-1.5B-Instruct-Function-Calling-v1
19
 
20
+ This model is a fine-tuned version of [Qwen/Qwen2-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2-1.5B-Instruct) on [devanshamin/gem-viggo-function-calling](https://huggingface.co/datasets/devanshamin/gem-viggo-function-calling) dataset.
21
+
22
+ ## Basic Usage
23
+
24
+ ```python
25
+ import torch
26
+ from transformers import AutoModelForCausalLM, AutoTokenizer
27
+
28
+ # Load the model and the tokenizer
29
+ model_id = "Qwen2-1.5B-Instruct-Function-Calling-v1"
30
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float32, device_map="auto")
31
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
32
+
33
+ def inference(prompt: str) -> str:
34
+ model_inputs = tokenizer([prompt], return_tensors="pt").to(device)
35
+ generated_ids = model.generate(model_inputs.input_ids, max_new_tokens=512)
36
+ generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
37
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
38
+ return response
39
+
40
+ prompt = "What is the meaning of life?"
41
+ messages = [
42
+ {"role": "system", "content": "You are a helpful assistant."},
43
+ {"role": "user", "content": prompt}
44
+ ]
45
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
46
+ response = inference(prompt)
47
+ print(response)
48
+ ```
49
+
50
+ ## Tool Usage
51
+
52
+ ### Basic
53
+
54
+ ```python
55
+
56
+ ```
57
+
58
+ ### Advanced
59
+ ```python
60
+ import re
61
+ from enum import Enum
62
+
63
+ from pydantic import BaseModel, Field # pip install pydantic
64
+ from instructor.function_calls import openai_schema # pip install instructor
65
+
66
+ def get_prompt(tool: str, user_input: str) -> str:
67
+ system = "You are a helpful assistant with access to the following tools. Use them if required - \n```json\n{}\n```"
68
+ messages = [
69
+ {"role": "system", "content": system.format(tool)},
70
+ {"role": "user", "content": 'Extract the information from the following - \n{}'.format(user_input)}
71
+ ]
72
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
73
+ return prompt
74
+
75
+ # Define functions using pydantic classes
76
+ class PaperCategory(str, Enum):
77
+ TYPE_1_DIABETES = 'Type 1 Diabetes'
78
+ TYPE_2_DIABETES = 'Type 2 Diabetes'
79
+
80
+ class Classification(BaseModel):
81
+ label: PaperCategory = Field(..., description='Provide the most likely category')
82
+ reason: str = Field(..., description='Give a detailed explanation with quotes from the abstract explaining why the paper is related to the chosen label.')
83
+
84
+ function_definition = openai_schema(Classification).openai_schema
85
+ tool = dict(type='function', function=function_definition)
86
+ input_text = "1,25-dihydroxyvitamin D(3) (1,25(OH)(2)D(3)), the biologically active form of vitamin D, is widely recognized as a modulator of the immune system as well as a regulator of mineral metabolism. The objective of this study was to determine the effects of vitamin D status and treatment with 1,25(OH)(2)D(3) on diabetes onset in non-obese diabetic (NOD) mice, a murine model of human type I diabetes. We have found that vitamin D-deficiency increases the incidence of diabetes in female mice from 46% (n=13) to 88% (n=8) and from 0% (n=10) to 44% (n=9) in male mice as of 200 days of age when compared to vitamin D-sufficient animals. Addition of 50 ng of 1,25(OH)(2)D(3)/day to the diet prevented disease onset as of 200 days and caused a significant rise in serum calcium levels, regardless of gender or vitamin D status. Our results indicate that vitamin D status is a determining factor of disease susceptibility and oral administration of 1,25(OH)(2)D(3) prevents diabetes onset in NOD mice through 200 days of age."
87
+ prompt = get_prompt(json.dumps(tool), input_text)
88
+ output = inference(prompt)
89
+ print(output)
90
+ # ```json
91
+ # {"name": "Classification", "arguments": {"label": "Type 1 Diabetes", "reason": "The study investigated the effect of vitamin D status and treatment with 1,25(OH)(2)D(3) on diabetes onset in non-obese diabetic (NOD) mice. It also concluded that vitamin D deficiency leads to an increase in diabetes incidence and that the addition of 1,25(OH)(2)D(3) can prevent diabetes onset in NOD mice."}}
92
+ # ```
93
+ # Extract JSON string using regex
94
+ output = re.search(r'```json\s*(\{.*?\})\s*```', output).group(1)
95
+ output = Classification(**json.loads(_output)['arguments'])
96
+ print(output)
97
+ # Classification(label=<PaperCategory.TYPE_1_DIABETES: 'Type 1 Diabetes'>, reason='The study investigated the effect of vitamin D status and treatment with 1,25(OH)(2)D(3) on diabetes onset in non-obese diabetic (NOD) mice. It also concluded that vitamin D deficiency leads to an increase in diabetes incidence and that the addition of 1,25(OH)(2)D(3) can prevent diabetes onset in NOD mice.')
98
+ ```
99
 
100
  ## Training procedure
101
 
 
129
 
130
  ### Framework versions
131
 
132
+ ```text
133
+ peft==0.11.1
134
+ transformers==4.42.3
135
+ torch==2.3.1+cu121
136
+ datasets==2.20.0
137
+ tokenizers==0.19.1
138
+ ```