Example
#1
by
mongoose54
- opened
Is there a quick example to use this pretrained model?
see this: https://huggingface.co/spaces/stmnk/pygen
Thanks @stmnk for sharing. I meant an API example (i.e how to use it within Python). Thanks
the link from my previous comment has a rest API call example in the app.py
file (under the "Files and versions" tab):
alternatively, you can use this url: https://huggingface.co/spaces/stmnk/pygen/blob/main/app.py
the list of parameters is around line 160+, in principle, is the same as the arguments accepted by the parent model checkpoint (T5-code): temperature, repetition penalty, tokens in output, etc.
I include below the function definition, with descriptions for all params (for reference):
def docgen_func(function_code, min_length, max_length, top_k, top_p, temp, repetition_penalty):
m, M, k, p, t, r = int(min_length), int(max_length), int(top_k), float(top_p/100), float(temp), float(repetition_penalty)
req_data = {
"inputs": function_code,
"parameters": {
"min_length": m, # (Default: None). Integer to define the minimum length in tokens of the output summary.
"max_length": M, # (Default: None). Integer to define the maximum length in tokens of the output summary.
"top_k": k, # (Default: None). Integer to define the top tokens considered within the sample operation to create new text.
"top_p": p, # (Default: None). Float to define the tokens that are within the sample` operation of text generation.
# Add tokens in the sample for more probable to least probable until the sum of the probabilities is greater than top_p.
"temperature": t, # (Default: 1.0). Float (0.0-100.0). The temperature of the sampling operation.
# 1 means regular sampling, 0 means top_k=1, 100.0 is getting closer to uniform probability.
"repetition_penalty": r, # (Default: None). Float (0.0-100.0). The more a token is used within generation
# the more it is penalized to not be picked in successive generation passes.
"max_time": 80, # (Default: None). Float (0-120.0). The amount of time in seconds that the query should take maximum.
# Network can cause some overhead so it will be a soft limit.
},
"options": {
"use_gpu": False, # (Default: false). Boolean to use GPU instead of CPU for inference (requires Startup plan at least)
"use_cache": True, # (Default: true). Boolean. There is a cache layer on the inference API to speedup requests we have already seen. Most models can use those results as is as models are deterministic (meaning the results will be the same anyway). However if you use a non deterministic model, you can set this parameter to prevent the caching mechanism from being used resulting in a real new query.
"wait_for_model": False, # (Default: false) Boolean. If the model is not ready, wait for it instead of receiving 503. It limits the number of requests required to get your inference done. It is advised to only set this flag to true after receiving a 503 error as it will limit hanging in your application to known places.
}
}
output = query(req_data)