Adding codebleu as code similarity metric (#116)#116
Closed
matthieumeeus wants to merge 1 commit into
Closed
Conversation
|
@matthieumeeus has exported this pull request. If you are a Meta employee, you can view the originating Diff in D96365690. |
matthieumeeus
pushed a commit
to matthieumeeus/PrivacyGuard
that referenced
this pull request
Mar 24, 2026
Summary: Adding CodeBLEU distance metric from https://arxiv.org/pdf/2009.10297 to PrivacyGuard, completing the code memorization measurement pipeline. We borrow substantial functionality from the CodeBLEU package made available on pypi (version V0.6.0) (https://pypi.org/project/codebleu/0.6.0/) and adopt it to our framework. This diff introduces: - `CodeBleuAttack`: A new BaseAttack that prepares target and generated code for CodeBLEU similarity analysis. Parses code into tokens, ASTs (via tree-sitter), and normalized data flow graphs (DFGs). Supports multiple languages (Python, Java, JavaScript, Go, Ruby, Rust, C, C++, C#, PHP) with per-language keyword weighting. Caches parsers and keywords for efficiency. - `CodeBleuNode`: A new BaseAnalysisNode that computes CodeBLEU similarity between code pairs produced by CodeBleuAttack. Implements the composite metric from Ren et al. 2020 as a weighted sum of four components: (i) ngram_match: Standard BLEU score measuring n-gram overlap; (ii) weighted_ngram_match: BLEU with reduced weight (0.2) for non-keyword tokens; (iii) syntax_match: Fraction of target AST subtrees found in generated AST; (iv) dataflow_match: Fraction of target DFG edges found in generated code. - `CodeBleuNodeOutput`: A BaseAnalysisOutput dataclass with fields for num_samples, per_sample_code_bleu, avg_code_bleu, and optional avg_code_bleu_by_language. - `CodeBleuAnalysisInput`: A BaseAnalysisInput class that validates required columns (tokens, ASTs, DFGs) produced by the attack. Differential Revision: D96365690
e936f58 to
9d9e33f
Compare
matthieumeeus
pushed a commit
to matthieumeeus/PrivacyGuard
that referenced
this pull request
Mar 24, 2026
Summary: Adding CodeBLEU distance metric from https://arxiv.org/pdf/2009.10297 to PrivacyGuard, completing the code memorization measurement pipeline. We borrow substantial functionality from the CodeBLEU package made available on pypi (version V0.6.0) (https://pypi.org/project/codebleu/0.6.0/) and adopt it to our framework. This diff introduces: - `CodeBleuAttack`: A new BaseAttack that prepares target and generated code for CodeBLEU similarity analysis. Parses code into tokens, ASTs (via tree-sitter), and normalized data flow graphs (DFGs). Supports multiple languages (Python, Java, JavaScript, Go, Ruby, Rust, C, C++, C#, PHP) with per-language keyword weighting. Caches parsers and keywords for efficiency. - `CodeBleuNode`: A new BaseAnalysisNode that computes CodeBLEU similarity between code pairs produced by CodeBleuAttack. Implements the composite metric from Ren et al. 2020 as a weighted sum of four components: (i) ngram_match: Standard BLEU score measuring n-gram overlap; (ii) weighted_ngram_match: BLEU with reduced weight (0.2) for non-keyword tokens; (iii) syntax_match: Fraction of target AST subtrees found in generated AST; (iv) dataflow_match: Fraction of target DFG edges found in generated code. - `CodeBleuNodeOutput`: A BaseAnalysisOutput dataclass with fields for num_samples, per_sample_code_bleu, avg_code_bleu, and optional avg_code_bleu_by_language. - `CodeBleuAnalysisInput`: A BaseAnalysisInput class that validates required columns (tokens, ASTs, DFGs) produced by the attack. Differential Revision: D96365690
9d9e33f to
f2fbd38
Compare
matthieumeeus
pushed a commit
to matthieumeeus/PrivacyGuard
that referenced
this pull request
Mar 24, 2026
Summary: Pull Request resolved: facebookresearch#116 Adding CodeBLEU distance metric from https://arxiv.org/pdf/2009.10297 to PrivacyGuard, completing the code memorization measurement pipeline. We borrow substantial functionality from the CodeBLEU package made available on pypi (version V0.6.0) (https://pypi.org/project/codebleu/0.6.0/) and adopt it to our framework. This diff introduces: - `CodeBleuAttack`: A new BaseAttack that prepares target and generated code for CodeBLEU similarity analysis. Parses code into tokens, ASTs (via tree-sitter), and normalized data flow graphs (DFGs). Supports multiple languages (Python, Java, JavaScript, Go, Ruby, Rust, C, C++, C#, PHP) with per-language keyword weighting. Caches parsers and keywords for efficiency. - `CodeBleuNode`: A new BaseAnalysisNode that computes CodeBLEU similarity between code pairs produced by CodeBleuAttack. Implements the composite metric from Ren et al. 2020 as a weighted sum of four components: (i) ngram_match: Standard BLEU score measuring n-gram overlap; (ii) weighted_ngram_match: BLEU with reduced weight (0.2) for non-keyword tokens; (iii) syntax_match: Fraction of target AST subtrees found in generated AST; (iv) dataflow_match: Fraction of target DFG edges found in generated code. - `CodeBleuNodeOutput`: A BaseAnalysisOutput dataclass with fields for num_samples, per_sample_code_bleu, avg_code_bleu, and optional avg_code_bleu_by_language. - `CodeBleuAnalysisInput`: A BaseAnalysisInput class that validates required columns (tokens, ASTs, DFGs) produced by the attack. Differential Revision: D96365690
f2fbd38 to
5721647
Compare
matthieumeeus
pushed a commit
to matthieumeeus/PrivacyGuard
that referenced
this pull request
Mar 25, 2026
Summary: Adding CodeBLEU distance metric from https://arxiv.org/pdf/2009.10297 to PrivacyGuard, completing the code memorization measurement pipeline. We borrow substantial functionality from the CodeBLEU package made available on pypi (version V0.6.0) (https://pypi.org/project/codebleu/0.6.0/) and adopt it to our framework. This diff introduces: - `CodeBleuAttack`: A new BaseAttack that prepares target and generated code for CodeBLEU similarity analysis. Parses code into tokens, ASTs (via tree-sitter), and normalized data flow graphs (DFGs). Supports multiple languages (Python, Java, JavaScript, Go, Ruby, Rust, C, C++, C#, PHP) with per-language keyword weighting. Caches parsers and keywords for efficiency. - `CodeBleuNode`: A new BaseAnalysisNode that computes CodeBLEU similarity between code pairs produced by CodeBleuAttack. Implements the composite metric from Ren et al. 2020 as a weighted sum of four components: (i) ngram_match: Standard BLEU score measuring n-gram overlap; (ii) weighted_ngram_match: BLEU with reduced weight (0.2) for non-keyword tokens; (iii) syntax_match: Fraction of target AST subtrees found in generated AST; (iv) dataflow_match: Fraction of target DFG edges found in generated code. - `CodeBleuNodeOutput`: A BaseAnalysisOutput dataclass with fields for num_samples, per_sample_code_bleu, avg_code_bleu, and optional avg_code_bleu_by_language. - `CodeBleuAnalysisInput`: A BaseAnalysisInput class that validates required columns (tokens, ASTs, DFGs) produced by the attack. Differential Revision: D96365690
b22705a to
da8b706
Compare
matthieumeeus
pushed a commit
to matthieumeeus/PrivacyGuard
that referenced
this pull request
Mar 25, 2026
Summary: Adding CodeBLEU distance metric from https://arxiv.org/pdf/2009.10297 to PrivacyGuard, completing the code memorization measurement pipeline. We borrow substantial functionality from the CodeBLEU package made available on pypi (version V0.6.0) (https://pypi.org/project/codebleu/0.6.0/) and adopt it to our framework. This diff introduces: - `CodeBleuAttack`: A new BaseAttack that prepares target and generated code for CodeBLEU similarity analysis. Parses code into tokens, ASTs (via tree-sitter), and normalized data flow graphs (DFGs). Supports multiple languages (Python, Java, JavaScript, Go, Ruby, Rust, C, C++, C#, PHP) with per-language keyword weighting. Caches parsers and keywords for efficiency. - `CodeBleuNode`: A new BaseAnalysisNode that computes CodeBLEU similarity between code pairs produced by CodeBleuAttack. Implements the composite metric from Ren et al. 2020 as a weighted sum of four components: (i) ngram_match: Standard BLEU score measuring n-gram overlap; (ii) weighted_ngram_match: BLEU with reduced weight (0.2) for non-keyword tokens; (iii) syntax_match: Fraction of target AST subtrees found in generated AST; (iv) dataflow_match: Fraction of target DFG edges found in generated code. - `CodeBleuNodeOutput`: A BaseAnalysisOutput dataclass with fields for num_samples, per_sample_code_bleu, avg_code_bleu, and optional avg_code_bleu_by_language. - `CodeBleuAnalysisInput`: A BaseAnalysisInput class that validates required columns (tokens, ASTs, DFGs) produced by the attack. Differential Revision: D96365690
matthieumeeus
pushed a commit
to matthieumeeus/PrivacyGuard
that referenced
this pull request
Mar 25, 2026
Summary: Adding CodeBLEU distance metric from https://arxiv.org/pdf/2009.10297 to PrivacyGuard, completing the code memorization measurement pipeline. We borrow substantial functionality from the CodeBLEU package made available on pypi (version V0.6.0) (https://pypi.org/project/codebleu/0.6.0/) and adopt it to our framework. This diff introduces: - `CodeBleuAttack`: A new BaseAttack that prepares target and generated code for CodeBLEU similarity analysis. Parses code into tokens, ASTs (via tree-sitter), and normalized data flow graphs (DFGs). Supports multiple languages (Python, Java, JavaScript, Go, Ruby, Rust, C, C++, C#, PHP) with per-language keyword weighting. Caches parsers and keywords for efficiency. - `CodeBleuNode`: A new BaseAnalysisNode that computes CodeBLEU similarity between code pairs produced by CodeBleuAttack. Implements the composite metric from Ren et al. 2020 as a weighted sum of four components: (i) ngram_match: Standard BLEU score measuring n-gram overlap; (ii) weighted_ngram_match: BLEU with reduced weight (0.2) for non-keyword tokens; (iii) syntax_match: Fraction of target AST subtrees found in generated AST; (iv) dataflow_match: Fraction of target DFG edges found in generated code. - `CodeBleuNodeOutput`: A BaseAnalysisOutput dataclass with fields for num_samples, per_sample_code_bleu, avg_code_bleu, and optional avg_code_bleu_by_language. - `CodeBleuAnalysisInput`: A BaseAnalysisInput class that validates required columns (tokens, ASTs, DFGs) produced by the attack. Differential Revision: D96365690
da8b706 to
98b9bdb
Compare
Summary: Adding CodeBLEU distance metric from https://arxiv.org/pdf/2009.10297 to PrivacyGuard, completing the code memorization measurement pipeline. We borrow substantial functionality from the CodeBLEU package made available on pypi (version V0.6.0) (https://pypi.org/project/codebleu/0.6.0/) and adopt it to our framework. This diff introduces: - `CodeBleuAttack`: A new BaseAttack that prepares target and generated code for CodeBLEU similarity analysis. Parses code into tokens, ASTs (via tree-sitter), and normalized data flow graphs (DFGs). Supports multiple languages (Python, Java, JavaScript, Go, Ruby, Rust, C, C++, C#, PHP) with per-language keyword weighting. Caches parsers and keywords for efficiency. - `CodeBleuNode`: A new BaseAnalysisNode that computes CodeBLEU similarity between code pairs produced by CodeBleuAttack. Implements the composite metric from Ren et al. 2020 as a weighted sum of four components: (i) ngram_match: Standard BLEU score measuring n-gram overlap; (ii) weighted_ngram_match: BLEU with reduced weight (0.2) for non-keyword tokens; (iii) syntax_match: Fraction of target AST subtrees found in generated AST; (iv) dataflow_match: Fraction of target DFG edges found in generated code. - `CodeBleuNodeOutput`: A BaseAnalysisOutput dataclass with fields for num_samples, per_sample_code_bleu, avg_code_bleu, and optional avg_code_bleu_by_language. - `CodeBleuAnalysisInput`: A BaseAnalysisInput class that validates required columns (tokens, ASTs, DFGs) produced by the attack. Differential Revision: D96365690
98b9bdb to
a2df9e7
Compare
|
This pull request has been merged in e4fdc0e. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Adding CodeBLEU distance metric from https://arxiv.org/pdf/2009.10297 to PrivacyGuard, completing the code memorization measurement pipeline. We borrow substantial functionality from the CodeBLEU package made available on pypi (version V0.6.0) (https://pypi.org/project/codebleu/0.6.0/) and adopt it to our framework.
This diff introduces:
CodeBleuAttack: A new BaseAttack that prepares target and generated code for CodeBLEU similarity analysis. Parses code into tokens, ASTs (via tree-sitter), and normalized data flow graphs (DFGs). Supports multiple languages (Python, Java, JavaScript, Go, Ruby, Rust, C, C++, C#, PHP) with per-language keyword weighting. Caches parsers and keywords for efficiency.CodeBleuNode: A new BaseAnalysisNode that computes CodeBLEU similarity between code pairs produced by CodeBleuAttack. Implements the composite metric from Ren et al. 2020 as a weighted sum of four components: (i) ngram_match: Standard BLEU score measuring n-gram overlap; (ii) weighted_ngram_match: BLEU with reduced weight (0.2) for non-keyword tokens; (iii) syntax_match: Fraction of target AST subtrees found in generated AST; (iv) dataflow_match: Fraction of target DFG edges found in generated code.CodeBleuNodeOutput: A BaseAnalysisOutput dataclass with fields for num_samples, per_sample_code_bleu, avg_code_bleu, and optional avg_code_bleu_by_language.CodeBleuAnalysisInput: A BaseAnalysisInput class that validates required columns (tokens, ASTs, DFGs) produced by the attack.Differential Revision: D96365690