Zack Li commited on
Commit
8af8108
1 Parent(s): 8482c24

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +174 -197
README.md CHANGED
@@ -1,201 +1,178 @@
1
  ---
2
- library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
4
  ---
5
-
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
10
-
11
-
12
- ## Model Details
13
-
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
  ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
200
-
201
-
 
1
  ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ tags:
6
+ - gemma
7
+ - function calling
8
+ - on-device language model
9
+ - android
10
+ - conversational
11
+ inference: false
12
  ---
13
+ # Octopus V1: On-device language model for function calling of software APIs
14
+ <p align="center">
15
+ - <a href="https://www.nexa4ai.com/" target="_blank">Nexa AI Product</a>
16
+ - <a href="https://nexaai.github.io/octopus" target="_blank">ArXiv</a>
17
+ </p>
18
+
19
+ <p align="center" width="100%">
20
+ <a><img src="Octopus-logo.jpeg" alt="nexa-octopus" style="width: 40%; min-width: 300px; display: block; margin: auto;"></a>
21
+ </p>
22
+
23
+ ## Introducing Octopus-V1
24
+ Octopus-V1, a series of advanced open-source language models with parameters ranging from 2B to 7B, represents Nexa AI's breakthrough in AI-driven software API interactions. Developed through meticulous fine-tuning using a specialized dataset from 30k+ RapidHub APIs, Octopus-V1 excels in understanding API structures and syntax. The models leverage conditional masking techniques to ensure precise, format-compliant API calls without compromising inference speed. A novel benchmark introduced alongside Octopus-V1 assesses its superior performance against GPT-4 in software API usage, signifying a leap forward in automating software development and API integration.
25
+
26
+ 📱 **Support 30k+ APIs from RapidAPI Hub**: Octopus leverages an extensive dataset derived from over 30,000 popular APIs on RapidAPI Hub. This rich dataset ensures broad coverage and understanding of diverse software API interactions, enhancing the model's utility across various applications.
27
+
28
+ 🐙 **Accuracy**: Fine-tuning on models with 2B, 3B, and 7B parameters yields Octopus, which surpasses GPT-4 in API call accuracy. The introduction of a conditional mask further refines its precision, making Octopus highly reliable for software API interactions.
29
+
30
+ 🎯 **Conditional Masking**: A novel conditional masking technique is employed to ensure outputs adhere to the desired formats and reduce errors. This approach not only maintains fast inference speeds but also substantially increases the model's accuracy in generating function calls and parameters.
31
+
32
+ Here is a full list of fined-tuned models in the Octopus series:
33
+ - [Octopus-v1 Gemma-7B](https://huggingface.co/NexaAIDev/Octopus-v1)
34
+ - [Octopus-v1 llama-7B](https://huggingface.co/NexaAIDev/Octopus-v1-llama-7b)
35
+ - [Octopus-v1 stable-code-3B](https://huggingface.co/NexaAIDev/Octopus-v1-stable-code-3b)
36
+ - [Octopus-v1 Gemma-2B](https://huggingface.co/NexaAIDev/Octopus-v1-gemma-2b)
37
+
38
+ ## Example Use Cases
39
+
40
+ You can run the model on a GPU using the following code.
41
+ ```python
42
+ import torch
43
+ from transformers import AutoTokenizer, AutoModelForCausalLM
44
+ import torch.nn.functional as F
45
+ prompt = """You are an assistant, and you need to call find appropriate functions according to the query of the users. Firstly, find the relevant functions, then get the function arguments by understanding the user's query. The following functions are available for you to fetch further data to answer user questions:
46
+ Function:
47
+ def basketapi_league_seasons(tournamentId):
48
+ '''
49
+ Get access to historical and current seasons for a specific basketball league using the tournament ID.
50
+ Args:
51
+ tournamentId (number): The argument tournamentId is a number that represents the identifier of a tournament in the context of the function.
52
+ '''
53
+ def os_sports_goal_distributions(unique_tournament_id,season_id,team_id):
54
+ '''
55
+ Get goal distributions by team, tournament ID, and season ID for in-depth sports performance analysis.
56
+ Args:
57
+ unique_tournament_id (number): The unique_tournament_id argument is a number representing the unique identifier for a tournament.
58
+ season_id (number): The argument season_id is a number that represents the identifier of the season for the search query string.
59
+ team_id (number): The team_id argument represents the teams identification number.
60
+ '''
61
+ def transfermarket_get_table(id,seasonID,domain,homeAway):
62
+ '''
63
+ Get tables by competition and season from transfermarket platform for comprehensive and detailed competition and season-related data.
64
+ Args:
65
+ id (string): The function argument "id" is a string representing an identifier.
66
+ seasonID (string): The seasonID argument is a string that represents the identifier for a specific season.
67
+ domain (string): The domain argument is a string that represents a search query.
68
+ homeAway (string): The homeAway argument is a string that represents the home or away status for a sports event.
69
+ '''
70
+ def no_relevant_function():
71
+ '''
72
+ Call this when no other provided function can be called to answer the user query.
73
+ '''
74
+ def soccersapi_stage_id(t,id):
75
+ '''
76
+ Get stage ID for a soccer match or event, access specific details like schedules, teams, and relevant data.
77
+ Args:
78
+ t (string): The argument "t" of type string represents the search query string.
79
+ id (number): This function argument is an identifier represented by a number, typically used to uniquely reference a specific entity within the system.
80
+ '''
81
+ Request the complete season data for a recently established basketball league using the tournament ID 309, aiming to analyze its inaugural seasons.
82
+ Response:
83
+ """
84
+ class NexaGenerator:
85
+ def __init__(self, model_id: AutoModelForCausalLM, tokenizer_id: AutoTokenizer):
86
+ self.model = AutoModelForCausalLM.from_pretrained(
87
+ model_id, torch_dtype=torch.bfloat16, device_map="auto"
88
+ )
89
+ self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_id)
90
+ self.eos_token_id = self.tokenizer.eos_token_id
91
+ self.token2id = self.tokenizer.get_vocab()
92
+ def deterministic_generate_next_token(
93
+ self,
94
+ input_ids: torch.Tensor, # shape: (1, seq_len), no support for batch yet
95
+ add_conditional_mask: bool = False,
96
+ usable_token_ids: torch.tensor = None, # element is token id
97
+ ) -> torch.tensor:
98
+ if add_conditional_mask:
99
+ assert usable_token_ids is not None, "usable_token_ids is required"
100
+ next_logits = self.model(input_ids)["logits"][:, -1:]
101
+ if add_conditional_mask:
102
+ mask = torch.full_like(next_logits, float("-inf"))
103
+ mask.scatter_(
104
+ 2,
105
+ usable_token_ids.unsqueeze(0).unsqueeze(0),
106
+ next_logits.gather(2, usable_token_ids.unsqueeze(0).unsqueeze(0)),
107
+ )
108
+ next_token_id = torch.argmax(mask, dim=-1)
109
+ else:
110
+ next_token_id = torch.argmax(next_logits, dim=-1)
111
+ return next_token_id
112
+ nexa_generator = NexaGenerator(model_id="NexaAIDev/Octopus-v1", tokenizer_id="NexaAIDev/Octopus-v1")
113
+ def get_response(prompt):
114
+ input_ids = nexa_generator.tokenizer(prompt, return_tensors="pt")["input_ids"].to("cuda")
115
+ for _ in range(200):
116
+ next_token_id = nexa_generator.deterministic_generate_next_token(
117
+ input_ids=input_ids,
118
+ add_conditional_mask=False,
119
+ usable_token_ids=None,
120
+ )
121
+ input_ids = torch.cat([input_ids, next_token_id], dim=-1)
122
+ if next_token_id[0].item() == nexa_generator.eos_token_id:
123
+ break
124
+ generated_text = nexa_generator.tokenizer.batch_decode(input_ids)
125
+ return generated_text[0]
126
+ print(get_response(prompt))
127
+ ```
128
 
129
  ## Evaluation
130
+ <div style="width: 100%;">
131
+ <div style="text-align: left;">
132
+ Comparison of accuracy between the GPT-3.5 and GPT-4 models, alongside our pretrained models in the Octopus series.
133
+ </div>
134
+ <div style="text-align: center;">
135
+ <img src="accuracy_no_mask.jpg" alt="Accuracy without Conditional Mask" style="width: 80%; min-width: 300px; margin-bottom: 20px;">
136
+ </div>
137
+ <div style="text-align: left;">
138
+ Comparison of accuracy following the introduction of a conditional mask in the Octopus series models.
139
+ </div>
140
+ <div style="text-align: center;">
141
+ <img src="accuracy_with_mask.jpg" alt="Accuracy with Conditional Mask" style="width: 80%; min-width: 300px;">
142
+ </div>
143
+ </div>
144
+
145
+ ## License
146
+ This model was trained on commercially viable data and is under the [Nexa AI community disclaimer](https://www.nexa4ai.com/disclaimer).
147
+
148
+
149
+ ## References
150
+ We thank the Meta llama2 team, Google Gemma team, Stability AI's Stable Code team for their amazing models!
151
+ ```
152
+ @misc{gemma-2023-open-models,
153
+ author = {{Gemma Team, Google DeepMind}},
154
+ title = {Gemma: Open Models Based on Gemini Research and Technology},
155
+ url = {https://goo.gle/GemmaReport},
156
+ year = {2023},
157
+ }
158
+ @article{touvron2023llama,
159
+ title={Llama 2: Open foundation and fine-tuned chat models},
160
+ author={Touvron, Hugo and Martin, Louis and Stone, Kevin and Albert, Peter and Almahairi, Amjad and Babaei, Yasmine and Bashlykov, Nikolay and Batra, Soumya and Bhargava, Prajjwal and Bhosale, Shruti and others},
161
+ journal={arXiv preprint arXiv:2307.09288},
162
+ year={2023}
163
+ }
164
+ @misc{stable-code-3b,
165
+ author = {Pinnaparaju, Nikhil and Adithyan, Reshinth and Phung, Duy and Tow, Jonathan and Baicoianu, James and Cooper, Nathan},
166
+ title = {Stable Code 3B},
167
+ url = {https://huggingface.co/stabilityai/stable-code-3b},
168
+ year = {2023}
169
+ }
170
+ ```
171
+
172
+ ## Citation
173
+ ```
174
+ @misc{TODO}
175
+ ```
176
+
177
+ ## Contact
178
+ Please [contact us]([email protected]) to reach out for any issues and comments!