tech-srl / code2seq

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

I am getting TimeError while using code2seq to predict long method #119

Open konL opened 2 years ago

konL commented 2 years ago

Hi! Thank you for your work! I used the command

python code2seq.py --load models/java-large-model/model_iter52.release --predict

to predict a new name for a single method, and it works well a for shorter method. But for a longer method I get a TimeError, I have looked at the code and found that it is mainly related to the extract_paths I think this is related to http requests, but I don't understand why it is related to method length. How should I solve this problem? My error messages:

Modify the file: "Input.java" and press any key when ready, or "q" / "exit" to exit

Traceback (most recent call last):
  File "code2seq.py", line 47, in <module>
    predictor.predict()
  File "C:\project\code2vec\code2seq\interactive_predict.py", line 35, in predict
    predict_lines, pc_info_dict = self.path_extractor.extract_paths(user_input)
  File "C:\project\code2vec\code2seq\extractor.py", line 26, in extract_paths
    raise TimeoutError(response.text)
TimeoutError: {"errorMessage":"2022-04-28T07:36:18.957Z b760b69b-e698-40b5-8202-40f767a36039 Task timed out after 19.14 seconds"}

Thank you!

konL commented 2 years ago

And is it possible to predict the names of identifiers at other granularities?(field, variable....)Thank you!

urialon commented 2 years ago

Hi @konL , Thank you for your interest in our work!

The extract_paths API is exactly the same as the JavaExtractor, which is included in the codebase, but wrapped in a class that makes it a Lambda function in AWS. This way, manual examination (interactive mode) could be performed faster and easier.

In too long examples, the extract_paths API just times out. You can either create a test set from your long examples using the preprocess.sh script, and evaluate (run the model in --test mode, as explained here) these examples on your machine. If you wish to keep this "interactive" behavior, you can wrap the JavaExtractor with a local server that accepts POST requests, but it will require a little more work.

see also: https://github.com/tech-srl/code2seq/issues/85

Best Uri