Get an error while trying to use API for this model.
I tried input text for both "Encryption algorithm AES [MASK_ID]" and "Encryption algorithm AES [MASK]", both return following error:
"error, No mask_token (
Please advise.
error, No mask_token (
error, No mask_token (mask) found on the input
Hi
@XiaotianHe
,
Thank you for your interest in our work!
The mask token is
Uri
< m a s k >
But remove the spaces π
Can you give me a complete sample input?
I tried input text "Encryption algorithm AES [Uri]" and still got the same error.
Here is a sample output:
while (<mask>) {
Best,
Uri
I would like to have a sample input, not output, to retrieve a complete java code from your model. Such as "Encryption algorithm AES [Uri]" or "Encryption algorithm AES
I would like to have a sample input, not output, to retrieve a complete java code for a specified algorithm from your model. Such as "Encryption algorithm AES (mask)". So I can see a complete set of java code to get AES implemented.
Sorry, I meant "a sample input". while (<mask>) {
is a sample input.
But this model was not designed to "retrieve a complete java code" so I'm not sure what do you mean.
For retrieving code snippets and documentation, see our another project DocPrompting: https://github.com/shuyanzhou/docprompting
Best,
Uri
All I got is:
[{"score":0.43174809217453003,"token":29225,"token_str":"true","sequence":"while (true) {"},{"score":0.14779505133628845,"token":131,"token_str":";","sequence":"while (;) {"},{"score":0.10204089432954788,"token":48640,"token_str":";;","sequence":"while (;;) {"},{"score":0.011685648001730442,"token":9226,"token_str":"this","sequence":"while (this) {"},{"score":0.011480224318802357,"token":118,"token_str":"i","sequence":"while (i) {"}]
How would this help me in java coding? I thought your model is supposed to help with java programming.
No :-)
this model is designed for java code similarity.
For java programming, see https://github.com/VHellendoorn/Code-LMs which is available on huggingface as this model: https://huggingface.co/NinedayWang/PolyCoder-2.7B
Best,
Uri
Uri,
I looked into the model NinedayWang/PolyCoder-2.7B, I still could not get a useful java code. Here is my input and output:
Input: Give me a Java code for Encryption algorithm AES-256
Output: [{"generated_text":"Give me a Java code for Encryption algorithm AES-256.\n "}]
Do you know how to get some useful source codes?
Thanks
Xiaotian
That model was trained on code completion, so I expect it to work better if you gave it the beginning of the code, for example the function signature, and then your request as a javadoc.
Can you give me an example?
Thanks for sharing. I read it carefully, but still cannot find a sample input. Can you please simply share a sample input that leads to generating a useful java code?
For Polycoder? Here is a sample input:
def binarySearch(arr, left, right, x):
mid = (left +
I got following result by running your sample input:
[{"generated_text":"def binarySearch(arr, left, right, x):\r\n mid = (left + right"}]
It only adds "right", and does not generate a complete code at all. Is that what I am supposed to see?
By running following input:
def binarySearch(arr, left, right, x):
mid = (left +
I got following output:
[{"generated_text":"def binarySearch(arr, left, right, x): mid = (left + right"}]
By running following input:
def binarySearch(arr, left, right, x):
mid = (left +
I got following output:
[{"generated_text":"def binarySearch(arr, left, right, x): mid = (left + right"}]
By running following input:
def binarySearch(arr, left, right, x):
mid = (left +
I got following output:
[{"generated_text":"def binarySearch(arr, left, right, x): mid = (left + right"}]
Hi @XiagotianHe,
I just ran the PolyCoder model using the exact code here: https://github.com/VHellendoorn/Code-LMs#october-2022---polycoder-is-available-on-huggingface and got following 4 completions:
def binarySearch(arr, left, right, x):
mid = (left + right) // 2
if arr[mid] == x:
return mid
def binarySearch(arr, left, right, x):
mid = (left + right) // 2
if arr[mid] > x:
return binarySearch(arr
def binarySearch(arr, left, right, x):
mid = (left + right) // 2
if arr[mid] < x:
return -1
def binarySearch(arr, left, right, x):
mid = (left + right) / 2
if arr[mid] > x:
return binarySearch(arr
How did you run it? Where is this json that you pasted coming from?
import org.json.JSONObject;
import org.json.JSONArray;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.*;
public class ChatGPT_Code {
private static final String API_ENDPOINT = "https://api-inference.huggingface.co/models/";
private static final int max_length=500;
public static void main(String[] args) throws Exception{
// Generate response from ChatGPT model
generateResponse();
// Print response
//System.out.println(response);
}
public static void generateResponse() throws Exception{
// Create JSON request
//{"error":"Model gpt2-xl is currently loading","estimated_time":20.0}
//try {} catch (Exception) {...}
//Exception in thread "main" java.net.SocketTimeoutException: Read timed out
String model=null;
model="NinedayWang/PolyCoder-0.4B";
Utility u=new Utility();
String inputText="def binarySearch(arr, left, right, x):" +
" mid = (left +";
JSONObject jsonRequest = new JSONObject();
jsonRequest.put("inputs", inputText);
System.out.println(jsonRequest.toString());
//jsonRequest.put("max_length", max_length);
//jsonRequest.put("parameters", new JSONObject().put("max_length", max_length));
// Send request to API endpoint
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost request = new HttpPost(API_ENDPOINT+model);
request.addHeader("Authorization", "Bearer Key");
request.addHeader("Content-Type", "application/json");
request.addHeader("X-Device-Type", "gpu");
StringEntity params = new StringEntity(jsonRequest.toString(), "UTF-8");
request.setEntity(params);
HttpResponse response;
try {
response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
String jsonString = EntityUtils.toString(entity);
System.out.println(jsonString);
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonElement jsonElement = parser.parse(jsonString);
if (jsonElement.isJsonArray()) {
// JSON is an array
JsonArray jsonArray = jsonElement.getAsJsonArray();
for (JsonElement element : jsonArray) {
JsonObject jsonObject = element.getAsJsonObject();
for (String key : jsonObject.keySet()) {
JsonElement element1 = jsonObject.get(key);
String value = element1.getAsString();
System.out.println(key+", "+value);
if (key.equalsIgnoreCase("generated_text") && value.startsWith(inputText)) {
value=value.substring(inputText.length()+1);
//value=value.substring(0, value.lastIndexOf(".")+1);
int index1=value.lastIndexOf(".");
int index2=value.lastIndexOf("!");
int index3=value.lastIndexOf("?");
int index0=-1;
if (index0<index1) index0=index1;
if (index0<index2) index0=index2;
if (index0<index3) index0=index3;
value=value.substring(0, index0+1);
value=u.ReplaceStr1(value, "\n", "<br>");
System.out.println(value);
}
}
}
} else if (jsonElement.isJsonObject()) {
// JSON is an object
JsonObject jsonObject = jsonElement.getAsJsonObject();
for (String key : jsonObject.keySet()) {
JsonElement element = jsonObject.get(key);
String value = element.getAsString();
System.out.println(key+", "+value);
}
} else {
System.out.println("Invalid JSON");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
{"inputs":"def binarySearch(arr, left, right, x): mid = (left +"}
This is not our code and I cannot support it. We just released the model, and we demonstrate that the model works. I hope you understand
This is not our code and we cannot debug it.
We just released the model and demonstrated that the model works. I hope you understand.
How about the input json? Does it look correct?
{"inputs":"def binarySearch(arr, left, right, x): mid = (left +"}
If it wouldn't have looked correct to me I wouldn't have provided it to you :-)
The only difference between this and the input I provided you is a newline character after the function signature.