jondurbin commited on
Commit
6160786
1 Parent(s): f75ae31

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +336 -0
README.md CHANGED
@@ -1,3 +1,339 @@
1
  ---
2
  license: llama2
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: llama2
3
+ datasets:
4
+ - jondurbin/airoboros-2.1
5
  ---
6
+
7
+ ### Overview
8
+
9
+ This is an instruction fine-tuned llama-2 model, using synthetic data generated by [airoboros](https://github.com/jondurbin/airoboros)
10
+
11
+ - Experimental RP style instruction set, with two categories: rp and gtkm
12
+ - rp includes multi-round chats, with emotes, between a varying number of characters, defined by cards
13
+ - gtkm is a way to test a simpler alternative to ghost attention - first, a character card is generated, then several questions are created to ask the model (as the character), using the character system prompt, then everything in synthesized into a dialog (one system prompt, all turns remain in character)
14
+ - Experimental support for longer, more detailed writing prompts, as well as next-chapter generation
15
+ - I used the new `cull-instructions` entrypoint in airoboros to shrink the m2.0 dataset to a smaller subset of high-quality instructions (according to gpt-4)
16
+ - The training data now also includes "stylized_response", in which 1500 sample instructions from various categories were re-generated using character cards as system prompts.
17
+ - this should allow better adherence to style/etc. specified in the system card
18
+ - Thousands of new generations, using some of the updates re: Flesch hints, etc., to get longer/higher quality writing outputs.
19
+ - A small "de-alignment" dataset was also added (not published) to remove some of the censorship in the base models.
20
+
21
+
22
+ *Why do I try to remove censorship?*
23
+
24
+ - laws vary widely based on time and location
25
+ - language model may conflate certain words with laws, e.g. it may think "stealing eggs from a chicken" is illegal
26
+ - these models just produce text, what you do with that text is your resonsibility
27
+ - many people and industries deal with "sensitive" content; imagine if a court stenographer's equipment filtered illegal content - it would be useless
28
+
29
+ ### Prompt format
30
+
31
+ The training code was updated to randomize newline vs space:
32
+ https://github.com/jondurbin/qlora/blob/main/qlora.py#L559C1-L559C1
33
+
34
+
35
+ ```
36
+ A chat. USER: {prompt} ASSISTANT:
37
+ ```
38
+
39
+ or
40
+
41
+ ```
42
+ A chat.
43
+ USER: {prompt}
44
+ ASSISTANT:
45
+ ```
46
+
47
+ So in other words, it's the preamble/system prompt, followed by a single space or newline, then "USER: " (single space after colon) then the prompt (which can have multiple lines, spaces, whatever), then a single space or newline, followed by "ASSISTANT: " (with a single space after the colon).
48
+
49
+ __*I strongly suggest adding stopping criteria/early inference stopping on "USER:", because the training data includes many multi-round chats and could otherwise start simulating a conversation!*__
50
+
51
+ ### Helpful usage tips
52
+
53
+ *The prompts shown here are are just the text that would be included after USER: and before ASSISTANT: in the full prompt format above, the system prompt and USER:/ASSISTANT: have been omited for readability.*
54
+
55
+ #### Context obedient question answering
56
+
57
+ By obedient, I mean the model was trained to ignore what it thinks it knows, and uses the context to answer the question. The model was also tuned to limit the values to the provided context as much as possible to reduce hallucinations.
58
+
59
+ The format for a closed-context prompt is as follows:
60
+ ```
61
+ BEGININPUT
62
+ BEGINCONTEXT
63
+ [key0: value0]
64
+ [key1: value1]
65
+ ... other metdata ...
66
+ ENDCONTEXT
67
+ [insert your text blocks here]
68
+ ENDINPUT
69
+ [add as many other blocks, in the exact same format]
70
+ BEGININSTRUCTION
71
+ [insert your instruction(s). The model was tuned with single questions, paragraph format, lists, etc.]
72
+ ENDINSTRUCTION
73
+ ```
74
+
75
+ It's also helpful to add "Don't make up answers if you don't know." to your instruction block to make sure if the context is completely unrelated it doesn't make something up.
76
+
77
+ *The __only__ prompts that need this closed context formating are closed-context instructions. Normal questions/instructions do not!*
78
+
79
+ I know it's a bit verbose and annoying, but after much trial and error, using these explicit delimiters helps the model understand where to find the responses and how to associate specific sources with it.
80
+ - `BEGININPUT` - denotes a new input block
81
+ - `BEGINCONTEXT` - denotes the block of context (metadata key/value pairs) to associate with the current input block
82
+ - `ENDCONTEXT` - denotes the end of the metadata block for the current input
83
+ - [text] - Insert whatever text you want for the input block, as many paragraphs as can fit in the context.
84
+ - `ENDINPUT` - denotes the end of the current input block
85
+ - [repeat as many input blocks in this format as you want]
86
+ - `BEGININSTRUCTION` - denotes the start of the list (or one) instruction(s) to respond to for all of the input blocks above.
87
+ - [instruction(s)]
88
+ - `ENDINSTRUCTION` - denotes the end of instruction set
89
+
90
+ It sometimes works without `ENDINSTRUCTION`, but by explicitly including that in the prompt, the model better understands that all of the instructions in the block should be responded to.
91
+
92
+ Here's a trivial, but important example to prove the point:
93
+ ```
94
+ BEGININPUT
95
+ BEGINCONTEXT
96
+ date: 2021-01-01
97
+ url: https://web.site/123
98
+ ENDCONTEXT
99
+ In a shocking turn of events, blueberries are now green, but will be sticking with the same name.
100
+ ENDINPUT
101
+ BEGININSTRUCTION
102
+ What color are bluberries? Source?
103
+ ENDINSTRUCTION
104
+ ```
105
+
106
+ And the response:
107
+ ```
108
+ Blueberries are now green.
109
+ Source:
110
+ date: 2021-01-01
111
+ url: https://web.site/123
112
+ ```
113
+
114
+ #### Coding
115
+
116
+ You can ask for fairly complex coding instructions with multiple criteria, e.g.:
117
+
118
+ ```
119
+ Create a python application with the following requirements:
120
+ - Asyncio FastAPI webserver
121
+ - ping endpoint that returns the current date in JSON format
122
+ - file upload endpoint, which calculates the file's sha256 checksum, and checks postgres to deduplicate
123
+ ```
124
+
125
+ Or inline criteria:
126
+
127
+ ```
128
+ Write a multi-threaded TCP server in C that accepts a "GET [key]" input and "SET [key] [value]" input, and uses a binary tree to get and store the input values.
129
+ ```
130
+
131
+ You can also optionally add a single space and "PLAINFORMAT" at the end of your prompt to avoid backticks, explanations, etc. and just print the code, e.g.:
132
+
133
+ ```
134
+ Write a websocket application in node.js. PLAINFORMAT
135
+ ```
136
+
137
+ #### Agent/function calling
138
+
139
+ The dataset includes many examples of function/args generation based on input criteria. This is somewhat similar to the OpenAI function calling, but the output is either JSON or YAML.
140
+
141
+ Example prompt:
142
+ ```
143
+ As an AI assistant, please select the most suitable function and parameters from the list of available functions below, based on the user's input. Provide your response in JSON format.
144
+
145
+ Input: I want to know how many times 'Python' is mentioned in my text file.
146
+
147
+ Available functions:
148
+ file_analytics:
149
+ description: This tool performs various operations on a text file.
150
+ params:
151
+ action: The operation we want to perform on the data, such as "count_occurrences", "find_line", etc.
152
+ filters:
153
+ keyword: The word or phrase we want to search for.
154
+ ```
155
+
156
+ Response:
157
+ ```json
158
+ {
159
+ "function": "file_analytics",
160
+ "params": {
161
+ "action": "count_occurrences",
162
+ "filters": {
163
+ "keyword": "Python"
164
+ }
165
+ }
166
+ }
167
+ ```
168
+
169
+ #### Chain-of-thought
170
+
171
+ You can ask for several possible responses to a given problem, with a ranking and final answer selection.
172
+
173
+ Example prompt:
174
+
175
+ ```
176
+ A group of people decide to play a round-robin tournament where every player plays every other player exactly once. If a total of 45 games were played, how many players participated in the tournament? Offer several potential answers, rank them according to mathematical logic, and pick the most feasible one.
177
+ ```
178
+
179
+ Example response:
180
+ ```
181
+ Solution 1:
182
+ In a round-robin tournament, each player plays every other player exactly once. This means that the total number of games played is equal to the combination of all players taken two at a time (since a game involves two players).
183
+
184
+ The formula for combinations is nC2 = n(n-1)/2, where n is the total number of players. We know that nC2 equals 45 (the total number of games), so we can set up the equation as follows:
185
+
186
+ n(n-1)/2 = 45
187
+
188
+ Solving this equation gives us n=10.
189
+
190
+ Final answer: There were 10 players in the tournament.
191
+
192
+ Solution 2:
193
+ Another way to approach this problem is by using the concept of triangular numbers. Triangular numbers are a sequence of numbers where each number can be represented as a triangle with dots. The nth triangular number is given by the sum of the first n natural numbers.
194
+
195
+ If we consider each game as a dot and each player as a side of the triangle, then the total number of games (45) would correspond to the 9th triangular number because 1+2+3+4+5+6+7+8+9=45. However, since each side of the triangle represents a player, and there's one more player than sides in our model (because the last player has no one left to play against), we need to add one more to get the total number of players.
196
+
197
+ Final answer: There were 10 players in the tournament.
198
+
199
+ Solution 3:
200
+ We could also use trial and error to solve this problem. Starting from a small number of players, we calculate how many games would be played in a round-robin tournament until we reach 45 games. For example, with 2 players, only 1 game is played; with 3 players, 3 games are played; with 4 players, 6 games are played, and so on. Continuing this process, we find that with 10 players, 45 games are played.
201
+
202
+ Final answer: There were 10 players in the tournament.
203
+
204
+ Ranking of solutions from best to worst:
205
+ 1. Solution 1: This solution uses direct mathematical reasoning based on the properties of a round-robin tournament and solves an equation to find the answer.
206
+ 2. Solution 2: This solution uses the concept of triangular numbers which requires additional steps and knowledge beyond the immediate problem context, but still arrives at the correct answer.
207
+ 3. Solution 3: This solution relies on trial and error, which is less efficient and reliable than the other methods, but it eventually gets to the right answer.
208
+
209
+ Best and final answer: There were 10 players in the tournament.
210
+ ```
211
+
212
+ #### reWOO style execution planning
213
+
214
+ The model now supports execution planning for complex instructions that would require making use of several tools. The output is just the plan, you must implement a mechanism to parse the output and actually call the functions!
215
+
216
+ Example prompt:
217
+ ```
218
+ Please construct a systematic plan to generate an optimal response to the user instruction, utilizing a set of provided tools. Each plan will correspond to an evidence value, which will be the output of one of the available functions given an input string
219
+ that could be the user's question, one or more prior evidence values, or a combination of both.
220
+
221
+ Here are the tools available to be called:
222
+ DuckDuckGo[input]: Tool that enables the user to search for information using the DuckDuckGo search engine. This tool is helpful in locating a suitable list of sites that may contain the answer to the user's query. It does not directly answer the question but finds a list of sites that might have the answer.
223
+ TextScraper[input]: Load one or more websites from the input string containing newline delimited links, where input is one or more links, and produces plain text output containing the content of the links.
224
+ HyperlinkExtractor[input]: Extract links from plain text and produces a plain text, newline delimited response of links.
225
+ KnowledgeModel[input]: Question answering language model, particularly useful in answering questions based on an input passage of text. The input must be a text question that references an :evidence[n]: variable, e.g. What color is the cat, given :evidence1:?
226
+
227
+ The output should be in format:
228
+ Plan: [first action to take based on input question]
229
+ :evidence0: = [function to call with input parameter]
230
+ Plan: [next action to take, based on result of :evidence0:]
231
+ :evidence1: = [next function to call and input parameter, which may include reference to previous evidence, e.g. "Given context :evidence0"]
232
+ ...
233
+ Answer: [:evidence[n]: containing the final answer.]
234
+
235
+ Question: Who won the Nobel Prize in Literature in 2020 and what is their most famous work?
236
+ ```
237
+
238
+ Response:
239
+ ```
240
+ Plan: Begin by conducting a web search to find out who won the Nobel Prize in Literature in 2020.
241
+ :evidence0: = DuckDuckGo[Nobel Prize in Literature 2020 winner]
242
+ Plan: Utilize the KnowledgeModel to interpret the search results and find the name of the laureate.
243
+ :evidence1: = KnowledgeModel[Who won the Nobel Prize in Literature in 2020, given :evidence0:?]
244
+ Plan: Conduct another web search to find the most famous work of the identified laureate.
245
+ :evidence2: = DuckDuckGo[Most famous work of :evidence1:]
246
+ Plan: Extract the relevant links from the DuckDuckGo search results for a more focused search.
247
+ :evidence3: = HyperlinkExtractor[:evidence2:]
248
+ Plan: Use the TextScraper tool to extract information from the relevant links.
249
+ :evidence4: = TextScraper[:evidence3:]
250
+ Plan: Finally, utilize the KnowledgeModel to identify and summarize the most famous work of the laureate from the extracted information.
251
+ :evidence5: = KnowledgeModel[What is the most famous work of :evidence1:, given :evidence4:?]
252
+ Answer: :evidence5:
253
+ ```
254
+
255
+ For this to be useful, you'd have to parse the output plan text, and implement/call each of the functions. This is just pseudo-code, completely untested off the top of my head, and obviously would requiring full implementation + hardening:
256
+
257
+ ```python
258
+ import re
259
+ import requests
260
+
261
+ def inject_context(input_text, **context):
262
+ for ref in set(re.findall(r"(:evidence[0-9]+:)", input_text, re.I)):
263
+ input_text = input_text.replace(ref, context.get(ref, ""))
264
+ return input_text
265
+
266
+ def duckduckgo(input_text, **context):
267
+ search_string = inject_context(input_text, **context)
268
+ ... search via duck duck go using search_string
269
+ ... return text content
270
+
271
+ def link_extractor(input_text, **context):
272
+ input_text = inject_context(input_text, **context)
273
+ return "\n".join(list(set(re.findall(r"(https?://[^\s]+?\.?)", input_text, re.I))))
274
+
275
+ def scrape(input_text, **context):
276
+ input_text = inject_context(input_text, **context)
277
+ text = []
278
+ for link in input_text.splitlines():
279
+ text.append(requests.get(link).text)
280
+ return "\n".join(text)
281
+
282
+ def infer(input_text, **context)
283
+ prompt = inject_context(input_text, **context)
284
+ ... call model with prompt, return output
285
+
286
+ def parse_plan(plan):
287
+ method_map = {
288
+ "DuckDuckGo": duckduckgo,
289
+ "HyperlinkExtractor": link_extractor,
290
+ "KnowledgeModel": infer,
291
+ "TextScraper": scrape,
292
+ }
293
+ context = {}
294
+ for line in plan.strip().splitlines():
295
+ if line.startswith("Plan:"):
296
+ print(line)
297
+ continue
298
+ parts = re.match("^(:evidence[0-9]+:)\s*=\s*([^\[]+])(\[.*\])\s$", line, re.I)
299
+ if not parts:
300
+ if line.startswith("Answer: "):
301
+ return context.get(line.split(" ")[-1].strip(), "Answer couldn't be generated...")
302
+ raise RuntimeError("bad format: " + line)
303
+ context[parts.group(1)] = method_map[parts.group(2)](parts.group(3), **context)
304
+ ```
305
+
306
+ ### Contribute
307
+
308
+ If you're interested in new functionality, particularly a new "instructor" type to generate a specific type of training data,
309
+ take a look at the dataset generation tool repo: https://github.com/jondurbin/airoboros and either make a PR or open an issue with details.
310
+
311
+ To help me with the OpenAI/compute costs:
312
+
313
+ - https://bmc.link/jondurbin
314
+ - ETH 0xce914eAFC2fe52FdceE59565Dd92c06f776fcb11
315
+ - BTC bc1qdwuth4vlg8x37ggntlxu5cjfwgmdy5zaa7pswf
316
+
317
+ ### Licence and usage restrictions
318
+
319
+ The airoboros 2.1 models are built on top of llama-2.
320
+
321
+ The llama-2 base model has a custom Meta license:
322
+ - See the [meta-license/LICENSE.txt](meta-license/LICENSE.txt) file attached for the original license provided by Meta.
323
+ - See also [meta-license/USE_POLICY.md](meta-license/USE_POLICY.md) and [meta-license/Responsible-Use-Guide.pdf](meta-license/Responsible-Use-Guide.pdf), also provided by Meta.
324
+
325
+ The fine-tuning data was generated by OpenAI API calls to gpt-4, via [airoboros](https://github.com/jondurbin/airoboros)
326
+
327
+ The ToS for OpenAI API usage has a clause preventing the output from being used to train a model that __competes__ with OpenAI
328
+
329
+ - what does *compete* actually mean here?
330
+ - these small open source models will not produce output anywhere near the quality of gpt-4, or even gpt-3.5, so I can't imagine this could credibly be considered competing in the first place
331
+ - if someone else uses the dataset to do the same, they wouldn't necessarily be violating the ToS because they didn't call the API, so I don't know how that works
332
+ - the training data used in essentially all large language models includes a significant amount of copyrighted or otherwise non-permissive licensing in the first place
333
+ - other work using the self-instruct method, e.g. the original here: https://github.com/yizhongw/self-instruct released the data and model as apache-2
334
+
335
+ I am purposingly leaving this license ambiguous (other than the fact you must comply with the Meta original license for llama-2) because I am not a lawyer and refuse to attempt to interpret all of the terms accordingly.
336
+
337
+ Your best bet is probably to avoid using this commercially due to the OpenAI API usage.
338
+
339
+ Either way, by using this model, you agree to completely indemnify me.