tech-srl / code2seq

Code for the model presented in the paper: "code2seq: Generating Sequences from Structured Representations of Code"
http://code2seq.org
MIT License
548 stars 165 forks source link

Can't predict anything. It is possible to use model without sending http request? #103

Closed lyriccoder closed 2 years ago

lyriccoder commented 2 years ago

Thank you for sharing your code!

Could you please tell me what you are doing in the procedure where you post an http request to Amazon service (InteractivePredictor)? The request is sent here:

 try:
                predict_lines, pc_info_dict = self.path_extractor.extract_paths(user_input)
            except ValueError:
                continue

I get timeout error every time: Task timed out after 19.02 seconds.

Where can I get that code? I tried to use JExtractor but it returns not a json format

urialon commented 2 years ago

Hi @lyriccoder , Thank you for your interest in our project, and thank you for reporting this!

I will check why the Amazon service is down.

Uri

urialon commented 2 years ago

Hey @lyriccoder , Can you check now, please?

lyriccoder commented 2 years ago

I still have the same issue. Is it possible to implement that service inside the current framework (predict without an http requests)? Maybe I can help?

urialon commented 2 years ago

It is possible, the path extractor is just an AWS lambda running the JavaExtractor on inputs.

There are two services: The one that you are trying to reach is reachable if I query it directly. Can you try running the following command from the terminal (assuming that you have curl and running on linux/macos...)?

curl -X POST https://po3g2dx2qa.execute-api.us-east-1.amazonaws.com/production/extractmethods -d '{"code": "public boolean f(Set<String> set, String value) {  for (String entry : set) {    if (entry.equalsIgnoreCase(value)) {  return true ;    }  }  return false;  }", "decompose":"true"}'

There is another service that performs the end-to-end prediction, this is the one that the website at code2seq.org uses:

curl -X POST https://djz6amor4b.execute-api.us-east-1.amazonaws.com/prod/predict -d '{"code":"public boolean f(Set<String> set, String value) {  for (String entry : set) {    if (entry.equalsIgnoreCase(value)) {  return true ;    }  }  return false;  }   "}'

This one is also available and responding. So I'm not sure why it doesn't work for you.

You could implement an option that runs the JavaExtractor locally and takes its output. This is how it is implemented in code2vec: https://github.com/tech-srl/code2vec/blob/master/extractor.py#L12

Let me know how it goes, Uri

lyriccoder commented 2 years ago

I have implemented the extractor (https://github.com/lyriccoder/code_2seq_tf1.2/pull/2). But now I get the error during model prediction:

full_error.txt

  1. I see that I can run jar:

running java -cp /hdd/code2seq/JavaExtractor/JPredict/target/JavaExtractor-0.0.1-SNAPSHOT.jar JavaExtractor.App --max_path_length 9 --max_path_width 2 --file /tmp/tmp8z8a4udy and I see the file is correct:

public int f() 
    {  
        int a = 0;
        return a;
    }
  1. So, the call of self.path_extractor.extract_paths(code) returns 2 objects, but then pretrained model (downloaded from https://s3.amazonaws.com/code2seq/model/java-large/java-large-model.tar.gz ) cannot predict at all. It fails for any file I pass.

@urialon Could you please tell me whether you can help. I understand, that it takes time. Let me know if you won't answer (you do not have time for it)

urialon commented 2 years ago

Hey, First, I want to see why the existing code doesn't work for you.

Did running

curl -X POST https://po3g2dx2qa.execute-api.us-east-1.amazonaws.com/production/extractmethods -d '{"code": "public boolean f(Set<String> set, String value) {  for (String entry : set) {    if (entry.equalsIgnoreCase(value)) {  return true ;    }  }  return false;  }", "decompose":"true"}'

work for you? If so, I wonder why it works from the terminal and not from the python code.

lyriccoder commented 2 years ago

It works for your code from terminal.

1) Unfortunately, I cannot send any http requests from python (due to limitation of the network), that's why I have to reimplement it without http requests, just for evaluating the model (couple of examples) 2) It didn't work for java code I passed. Seems the service cannot respond if the Java method is too long

urialon commented 2 years ago

What if you called curl from python? that is, instead of requests.post use something like subprocess.Popen(['curl', '-x', 'POST', 'https://po3g2dx2qa...', ...], ...) Would that work?

On Fri, Sep 24, 2021 at 9:20 AM lyriccoder @.***> wrote:

It works for your code from terminal.

  1. Unfortunately, I cannot send any http requests from python (due to limitation of the network), that's why I have to reimplement it without http requests, just for evaluating the model (couple of examples)
  2. It didn't work for java code I passed. Seems the service cannot respond if the Java method is too long

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tech-srl/code2seq/issues/103#issuecomment-926619349, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSOXMD33RYICQDKN2M5WGTUDR3JZANCNFSM5ET27UJQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

lyriccoder commented 2 years ago

Thanks, @urialon. It works. Now i can compare the response and the results of extract_paths with jar.

Thank you for help

lyriccoder commented 2 years ago

I'm closing issue, I am using code2vec model. Thank you for help

urialon commented 2 years ago

Hi @lyriccoder , Just be aware that code2seq is much better than code2vec. It has much better encoder and decoder.

lyriccoder commented 2 years ago

@urialon thank you for information, but I can't use functionality with http requests. And rewriting it will take too much time for me.