Possible overfitting with "TransCoder_model_1.pth" from Java -> Python

Open
#103 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
java, python

Research direction

Reproduce the report with the pretrained TransCoder_model_1.pth model from the documentation, starting with COUNT_OF_PAIRS_SATISFYING_THE_GIVEN_CONDITION.java and its syntax variations generated by MuJava. Compare the original and modified translations, then determine whether the repeated result-expression error is overfitting; done means establishing the cause and an actionable correction or evaluation finding.

Written by the indexing model from the issue text.

Description

I have been using TransCoder for a few research papers lately and I came across an interesting phenomenon using the pretrained model "TransCoder_model_1.pth" you provide in your docs.

For the program in your dataset COUNT_OF_PAIRS_SATISFYING_THE_GIVEN_CONDITION.java when translated to Python, it passes all test cases. We checked and the translation seems correct. However, when we perform any small syntactical change to the original Java code and try to translate again, the translation mismatches the changed program.

For example, we introduced a change to the following Java code by modifying s.charAt(i) -> s.charAt(++i) at line 5:

static  int f_gold( int a, int b ) {
    java.lang.String s = String.valueOf( b );
    int i;
    for (i = 0; i < s.length(); i++) {
        if (s.charAt( ++i ) != '9') {
            break;
        }
    }
    int result;
    if (i == s.length()) {
        result = a * s.length();
    } else {
        result = a * (s.length() - 1);
    }
    return result;
}

The translated code is as follows:

def f_gold(cls, a, b):
    """ generated source for method f_gold """
    s = String.valueOf(b)
    i = int()
    while i < len(s):
        i += 1
        if s.charAt(i) != '9':
            break
        i += 1
    result = int()
    if i == len(s):
        result = a * len(s)
    else:
        result = a * (1 - len(s))
    return result

Notice that the changed code is rightfully translated, however, result = a * (s.length() - 1); is now wrongfully translated to result = a * (1 - len(s)).

We have generated 89 variations of this Java function using MuJava, and this translation bug appears in every single one of them, except the original program.

Maybe this is an overfitting example. What are your thoughts?

Dominant language
Python
Stars
777
Forks
144
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from facebookresearch/CodeGen

All issues in facebookresearch/CodeGen

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.