restoring original README

This commit is contained in:
Łukasz Olszewski 2024-01-02 17:53:54 +01:00
parent 76590818a3
commit c46dd7e78b

View File

@ -1,90 +1,3 @@
## Warning
This is a personal copy of [huggingface/text-generation-inference](https://github.com/huggingface/text-generation-inference). It contains experimental changes that are not meant for any serious use.
Specifically it adds:
- context free grammar
- logit bias
- negative prompts
All 3 can be combined of course.
### Context free grammar
This adds EBNF grammar as implemented in [Saibo-creator/transformers-CFG](https://github.com/Saibo-creator/transformers-CFG.git). See that repo for grammar examples etc.
This feature adds extra parameters:
- boolean - use_grammar_constraint
- string - grammar
For example one can send the folowing request to generate and receive valid json(with llama2 instruct):
```
{
"inputs": "This is a valid json string for http request:",
"parameters": {
"truncate": 1000,
"max_new_tokens": 300,
"use_grammar_constraint": true,
"grammar": "root ::= object\n\nobject ::= \"{\" ws ( string \":\" ws value (\",\" ws string \":\" ws value)* )? \"}\"\n\nvalue ::= object | array | string | number | (\"true\" | \"false\" | \"null\") ws\n\narray ::= \"[\" ws ( value (\",\" ws value)* )? \"]\" ws\n\nstring ::= \"\\\"\" ( [a-zA-Z0-9] )* \"\\\"\" ws\n\nnumber ::= (\"-\"? ([0-9] | [1-9] [0-9]*)) (\".\" [0-9]+)? ([eE] [-+]? [0-9]+)? ws\n\n\nws ::= ([ \\t\\n] ws)?\n"
}
}
```
### Negative prompts
This is a rather expensive and crude implementation that has to run the model to obtain unconditional token biases during processing so it does slow down generation when this feature is used.
Please see documentation for Huggingface's UnbatchedClassifierFreeGuidanceLogitsProcessor for more info. In summary, guidance scale of 1 does nothing. Anything above 1 increases the strength of the negative prompt, anything below 1 turns it into positive.
This adds the folowing parameters:
- string - negative_inputs
- float - guidance_scale
It can be used with for example(with gpt2):
```
{
"inputs": "Today, a dragon flew over Paris, France,",
"parameters": {
"truncate": 1000,
"negative_inputs": "A very happy event happened,",
"max_new_tokens": 300,
"guidance_scale": 1.5
}
}
```
### Logit bias
One can use this for disallowing completely, or adjusting a probability of certain words in the output.
Additional parameters are:
- list of tuples, each containing a string and a flot number
the string is a word to bias and the number is the float to make it more of less likely. Some models trained with spaces before tokens like gpt2 require an extra space to be included before each word, others like llama2 don't.
An example use is(with llama2 instruct):
```
{
"inputs": "<s>[INST] <<SYS>>\nThese are a series of question/answer pairs.\n<</SYS>>[INST]in zfs, what is the console command to create a snapshot?[/INST]",
"parameters": {
"truncate": 1000,
"max_new_tokens": 300,
"logit_bias":[
[
"console",
-10
],
[
"You",
-2
]
]
}
}
```
<div align="center"> <div align="center">
<a href="https://www.youtube.com/watch?v=jlMAX2Oaht0"> <a href="https://www.youtube.com/watch?v=jlMAX2Oaht0">