├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── NOTICE
├── README.md
├── THIRD_PARTY_LICENSES
├── data
├── mbxp
│ ├── LICENSE
│ ├── examples
│ │ ├── mbcpp_samples.jsonl
│ │ ├── mbcsp_samples.jsonl
│ │ ├── mbgp_samples.jsonl
│ │ ├── mbjp_samples.jsonl
│ │ ├── mbjsp_samples.jsonl
│ │ ├── mbkp_samples.jsonl
│ │ ├── mbphp_samples.jsonl
│ │ ├── mbplp_samples.jsonl
│ │ ├── mbpp_samples.jsonl
│ │ ├── mbrbp_samples.jsonl
│ │ ├── mbscp_samples.jsonl
│ │ ├── mbswp_samples.jsonl
│ │ └── mbtsp_samples.jsonl
│ ├── fewshot_prompts
│ │ ├── cpp_fewshot.cpp
│ │ ├── csharp_fewshot.cs
│ │ ├── go_fewshot.go
│ │ ├── java_fewshot_v1.java
│ │ ├── javascript_fewshot_v1.js
│ │ ├── kotlin_fewshot_v1.kt
│ │ ├── perl_fewshot.perl
│ │ ├── php_fewshot_v1.php
│ │ ├── python_fewshot_v1.py
│ │ ├── ruby_fewshot_v1.rb
│ │ ├── scala_fewshot.scala
│ │ ├── swift_fewshot.swift
│ │ └── typescript_fewshot.ts
│ ├── mbcpp_release_v1.2.jsonl
│ ├── mbcsp_release_v1.2.jsonl
│ ├── mbgp_release_v1.1.jsonl
│ ├── mbjp_release_v1.2.jsonl
│ ├── mbjsp_release_v1.2.jsonl
│ ├── mbkp_release_v1.2.jsonl
│ ├── mbphp_release_v1.2.jsonl
│ ├── mbplp_release_v1.jsonl
│ ├── mbpp_release_v1.jsonl
│ ├── mbrbp_release_v1.2.jsonl
│ ├── mbscp_release_v1.jsonl
│ ├── mbswp_release_v1.jsonl
│ ├── mbtsp_release_v1.2.jsonl
│ ├── metadata.json
│ └── metadata_examples.json
├── multilingual_humaneval
│ ├── HumanEval.jsonl
│ ├── HumanEval_csharp_v1.jsonl
│ ├── HumanEval_go_v1.jsonl
│ ├── HumanEval_java_v1.1.jsonl
│ ├── HumanEval_javascript_v1.1.jsonl
│ ├── HumanEval_kotlin_v1.1.jsonl
│ ├── HumanEval_perl_v1.1.jsonl
│ ├── HumanEval_php_v1.1.jsonl
│ ├── HumanEval_ruby_v1.1.jsonl
│ ├── HumanEval_scala_v1.1.jsonl
│ ├── HumanEval_swift_v1.1.jsonl
│ ├── HumanEval_typescript_v1.jsonl
│ ├── LICENSE
│ └── metadata.json
└── multilingual_mathqa
│ ├── LICENSE
│ ├── README.md
│ ├── examples
│ ├── java_samples.jsonl
│ ├── javascript_samples.jsonl
│ └── python_samples.jsonl
│ ├── fewshot_prompting
│ ├── mathqa_java_v1.java
│ ├── mathqa_javascript_v1.js
│ └── mathqa_python_v1.py
│ ├── mathqa-test-java_v1.jsonl
│ ├── mathqa-test-javascript_v1.jsonl
│ ├── mathqa-test-python_v1.jsonl
│ └── metadata.json
├── graphics
├── mbxp_java_conversion.png
└── paper_summary.png
├── language_setup
├── amazon_linux_ami.sh
└── ubuntu.sh
├── mxeval
├── __init__.py
├── data.py
├── evaluate_functional_correctness.py
├── evaluation.py
└── execution.py
├── requirements.txt
├── resources
└── eval_csproj.zip
└── setup.py
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 | *.egg-info/*
3 | .DS_Store
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Changelog
2 |
3 | ## v1.1
4 | * Bugfix:
5 | Fix unit test cases for 47 problems’ test assertions for C#/TypeScript/Go, which represents ~5% of all problems:
6 | Root cause of the issue is a possibility for the input parameters to the canonical solutions get mutated as a side-affect which cause the captured input to mismatch.
7 | We fix this issue by saving another copy of the function input before passing it for execution.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | MBXP+: Multi-lingual Execution-Based Evaluation
2 |
3 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Execution-based evaluation of code in 10+ languages
2 |
3 | This repository contains code to perform execution-based multi-lingual evaluation of code generation capabilities and the corresponding data, namely, a multi-lingual benchmark MBXP, multi-lingual MathQA and multi-lingual HumanEval. Results and findings can be found in the paper "Multi-lingual Evaluation of Code Generation Models" (https://arxiv.org/abs/2210.14868).
4 |
5 |
6 | ## Paper summary
7 |
8 | Our paper describes the language conversion framework, the synthetic solution generation, and many other types of evaluation beyond the traditional function completion evaluation such as translation, code insertion, summarization, and robustness evaluation.
9 |
10 | 
11 |
12 |
13 | ## Language conversion of execution-based function completion datasets
14 |
15 | Below we demonstrate the language conversion (component A above) for the conversion from Python to Java (abridged example for brevity).
16 |
17 | 
18 |
19 |
20 | # Installation
21 |
22 | Check out and install this repository:
23 | ```
24 | git clone https://github.com/amazon-science/mxeval.git
25 | pip install -e mxeval
26 | ```
27 |
28 |
29 |
30 | ## Dependencies
31 | We provide scripts to help set up programming language dependencies that are used to execute and evaluate using datasets in MBXP.
32 |
33 | ### Amazon Linux AMI
34 | ```
35 | bash language_setup/amazon_linux_ami.sh
36 | ```
37 | ### Ubuntu
38 | ```
39 | bash language_setup/ubuntu.sh
40 | ```
41 |
42 | # Usage
43 |
44 | **This program exists to run untrusted model-generated code. Users are strongly
45 | encouraged not to do so outside of a robust security sandbox. See the comment in
46 | `execution.py` for more information and instructions.**
47 |
48 | Each sample is formatted into a single line:
49 | ```
50 | {"task_id": "Corresponding task ID", "completion": "Completion only without the prompt",
51 | "language": "programming language name"}
52 | ```
53 | We provide `data/mbxp/examples/mbxp_samples.jsonl` to illustrate the format.
54 |
55 | Here is nearly functional example code (you just have to provide
56 | `generate_one_completion` to make it work) that saves generated completions to
57 | `samples.jsonl`.
58 | ```
59 | from mxeval.data import write_jsonl, read_problems
60 |
61 | problems = read_problems()
62 |
63 | num_samples_per_task = 200
64 | samples = [
65 | dict(task_id=task_id, language=problems[task_id]["language"], completion=generate_one_completion(problems[task_id]["prompt"]))
66 | for task_id in problems
67 | for _ in range(num_samples_per_task)
68 | ]
69 | write_jsonl("samples.jsonl", samples)
70 | ```
71 |
72 | To evaluate the samples for, e.g., Java MBJP evaluation, run
73 | ```
74 | evaluate_functional_correctness data/mbxp/examples/mbjp_samples.jsonl --problem_file data/mbxp/mbjp_release_v1.jsonl
75 | ```
76 | or to run all languages
77 | ```
78 | for lang in mbcpp mbcsp mbgp mbjp mbjsp mbkp mbphp mbplp mbpp mbrbp mbscp mbswp mbtsp;
79 | do evaluate_functional_correctness --problem_file data/mbxp/${lang}_release_v1.jsonl data/mbxp/examples/${lang}_samples.jsonl;
80 | done
81 | ```
82 | You can check the programming-language dependency installation by running the above example for each MBXP dataset. You should obtain the following results for the mbxp_samples.jsonl files provided:
83 |
84 |
85 | | Dataset | pass@1 |
86 | |---------|--------|
87 | | MBCPP | 79.60% |
88 | | MBCSP | 63.63% |
89 | | MBGP | 39.19% |
90 | | MBJP | 85.30% |
91 | | MBJSP | 78.67% |
92 | | MBKP | 63.77% |
93 | | MBPHP | 72.77% |
94 | | MBPLP | 38.41% |
95 | | MBPP | 82.24% |
96 | | MBRBP | 58.90% |
97 | | MBSCP | 42.96% |
98 | | MBSWP | 29.40% |
99 | | MBTSP | 87.29% |
100 |
101 |
102 |
103 | Note: Because there is no unbiased way of estimating pass@k when there are fewer
104 | samples than k, the script does not evaluate pass@k for these cases. To
105 | evaluate with other k values, pass `--k `. For
106 | other options, see
107 | ```
108 | $ evaluate_functional_correctness --help
109 | ```
110 | However, we recommend that you use the default values for the rest.
111 |
112 | ### Example usage with non-default values
113 | ```
114 | evaluate_functional_correctness data/mbxp/samples/mbjp_samples.jsonl --problem_file data/mbxp/mbjp_release_v1.jsonl --n_workers 63 --k 1,5,10,100
115 | ```
116 |
117 | ### Known Issues
118 |
119 | While evaluation uses very little memory, you might see the following error
120 | message when the system is running out of RAM. Since this may cause some
121 | correct programs to fail, we recommend that you free some memory and try again.
122 | ```
123 | malloc: can't allocate region
124 | ```
125 |
126 | Some system might require longer compilation timeout. If you see that the execution fails due to compilation timeout reason, this number should be increased accordingly.
127 |
128 | ### Canonical solutions release
129 |
130 | We have released canonical solutions for certain popular langauges (v1.2). The detailed numbers of the solutions for each langauge are listed below.
131 |
132 | | Dataset | # solutions | # problems |
133 | |---------|-------------|------------|
134 | | MBCPP | 773 | 848 |
135 | | MBCSP | 725 | 968 |
136 | | MBJP | 874 | 966 |
137 | | MBJSP | 938 | 966 |
138 | | MBKP | 796 | 966 |
139 | | MBPHP | 950 | 966 |
140 | | MBPP | 960 | 974 |
141 | | MBRBP | 784 | 966 |
142 | | MBTSP | 967 | 968 |
143 |
144 |
145 | ### Future release
146 | We plan to release synthetic canonical solutions as well as processed datasets for other evaluation tasks such as code-insertion, code-translation, etc.
147 |
148 |
149 |
150 |
151 | ### Credits
152 | We adapted OpenAI's human-eval package (https://github.com/openai/human-eval) for the multi-lingual case. We thank OpenAI for their pioneering effort in this field including the release of the original HumanEval dataset, which we convert to the multi-lingual versions. We also thank Google for their release of the original MBPP Python dataset (https://github.com/google-research/google-research/tree/master/mbpp), which we adapt and convert to other programming languages.
153 |
154 | ### Citation
155 |
156 | Please cite using the following bibtex entry:
157 |
158 | ```
159 | @article{mbxp_athiwaratkun2022,
160 | title = {Multi-lingual Evaluation of Code Generation Models},
161 | author = {Athiwaratkun, Ben and
162 | Gouda, Sanjay Krishna and
163 | Wang, Zijian and
164 | Li, Xiaopeng and
165 | Tian, Yuchen and
166 | Tan, Ming
167 | and Ahmad, Wasi Uddin and
168 | Wang, Shiqi and
169 | Sun, Qing and
170 | Shang, Mingyue and
171 | Gonugondla, Sujan Kumar and
172 | Ding, Hantian and
173 | Kumar, Varun and
174 | Fulton, Nathan and
175 | Farahani, Arash and
176 | Jain, Siddhartha and
177 | Giaquinto, Robert and
178 | Qian, Haifeng and
179 | Ramanathan, Murali Krishna and
180 | Nallapati, Ramesh and
181 | Ray, Baishakhi and
182 | Bhatia, Parminder and
183 | Sengupta, Sudipta and
184 | Roth, Dan and
185 | Xiang, Bing},
186 | doi = {10.48550/ARXIV.2210.14868},
187 | url = {https://arxiv.org/abs/2210.14868},
188 | keywords = {Machine Learning (cs.LG), Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
189 | publisher = {arXiv},
190 | year = {2022},
191 | copyright = {Creative Commons Attribution 4.0 International}
192 | }
193 |
194 | ```
195 |
--------------------------------------------------------------------------------
/THIRD_PARTY_LICENSES:
--------------------------------------------------------------------------------
1 | The Multi-lingual Execution-Based Evaluation repository includes the following third-party software/licensing:
2 |
3 | ** (1) in mxeval/, we release Multi-lingual Execution-Based Evaluation we adapt the HumanEval code repository into a multi-lingual version which supports evaluation of all our datasets. The original code and dataset are from https://github.com/openai/human-eval.
4 | (2) In data/multilingual_humaneval, we release Multi-lingual HumanEval where we adapt the HumanEval dataset by OpenAI into multiple datasets in different programming languages. The original code and dataset are from https://github.com/openai/human-eval/tree/master/data.
5 |
6 | The MIT License
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 |
26 |
27 | ----------------
28 |
29 |
30 | ** In data/mbxp, we release MBXP we adapt the MBPP dataset by Google into multiple datasets in different programming languages. The original datasets are from https://github.com/google-research/google-research/tree/master/mbpp and https://huggingface.co/datasets/mbpp.
31 |
32 |
33 | Attribution 4.0 International
34 |
35 | =======================================================================
36 |
37 | Creative Commons Corporation ("Creative Commons") is not a law firm and
38 | does not provide legal services or legal advice. Distribution of
39 | Creative Commons public licenses does not create a lawyer-client or
40 | other relationship. Creative Commons makes its licenses and related
41 | information available on an "as-is" basis. Creative Commons gives no
42 | warranties regarding its licenses, any material licensed under their
43 | terms and conditions, or any related information. Creative Commons
44 | disclaims all liability for damages resulting from their use to the
45 | fullest extent possible.
46 |
47 | Using Creative Commons Public Licenses
48 |
49 | Creative Commons public licenses provide a standard set of terms and
50 | conditions that creators and other rights holders may use to share
51 | original works of authorship and other material subject to copyright
52 | and certain other rights specified in the public license below. The
53 | following considerations are for informational purposes only, are not
54 | exhaustive, and do not form part of our licenses.
55 |
56 | Considerations for licensors: Our public licenses are
57 | intended for use by those authorized to give the public
58 | permission to use material in ways otherwise restricted by
59 | copyright and certain other rights. Our licenses are
60 | irrevocable. Licensors should read and understand the terms
61 | and conditions of the license they choose before applying it.
62 | Licensors should also secure all rights necessary before
63 | applying our licenses so that the public can reuse the
64 | material as expected. Licensors should clearly mark any
65 | material not subject to the license. This includes other CC-
66 | licensed material, or material used under an exception or
67 | limitation to copyright. More considerations for licensors:
68 | wiki.creativecommons.org/Considerations_for_licensors
69 |
70 | Considerations for the public: By using one of our public
71 | licenses, a licensor grants the public permission to use the
72 | licensed material under specified terms and conditions. If
73 | the licensor's permission is not necessary for any reason--for
74 | example, because of any applicable exception or limitation to
75 | copyright--then that use is not regulated by the license. Our
76 | licenses grant only permissions under copyright and certain
77 | other rights that a licensor has authority to grant. Use of
78 | the licensed material may still be restricted for other
79 | reasons, including because others have copyright or other
80 | rights in the material. A licensor may make special requests,
81 | such as asking that all changes be marked or described.
82 | Although not required by our licenses, you are encouraged to
83 | respect those requests where reasonable. More_considerations
84 | for the public:
85 | wiki.creativecommons.org/Considerations_for_licensees
86 |
87 | =======================================================================
88 |
89 | Creative Commons Attribution 4.0 International Public License
90 |
91 | By exercising the Licensed Rights (defined below), You accept and agree
92 | to be bound by the terms and conditions of this Creative Commons
93 | Attribution 4.0 International Public License ("Public License"). To the
94 | extent this Public License may be interpreted as a contract, You are
95 | granted the Licensed Rights in consideration of Your acceptance of
96 | these terms and conditions, and the Licensor grants You such rights in
97 | consideration of benefits the Licensor receives from making the
98 | Licensed Material available under these terms and conditions.
99 |
100 |
101 | Section 1 -- Definitions.
102 |
103 | a. Adapted Material means material subject to Copyright and Similar
104 | Rights that is derived from or based upon the Licensed Material
105 | and in which the Licensed Material is translated, altered,
106 | arranged, transformed, or otherwise modified in a manner requiring
107 | permission under the Copyright and Similar Rights held by the
108 | Licensor. For purposes of this Public License, where the Licensed
109 | Material is a musical work, performance, or sound recording,
110 | Adapted Material is always produced where the Licensed Material is
111 | synched in timed relation with a moving image.
112 |
113 | b. Adapter's License means the license You apply to Your Copyright
114 | and Similar Rights in Your contributions to Adapted Material in
115 | accordance with the terms and conditions of this Public License.
116 |
117 | c. Copyright and Similar Rights means copyright and/or similar rights
118 | closely related to copyright including, without limitation,
119 | performance, broadcast, sound recording, and Sui Generis Database
120 | Rights, without regard to how the rights are labeled or
121 | categorized. For purposes of this Public License, the rights
122 | specified in Section 2(b)(1)-(2) are not Copyright and Similar
123 | Rights.
124 |
125 | d. Effective Technological Measures means those measures that, in the
126 | absence of proper authority, may not be circumvented under laws
127 | fulfilling obligations under Article 11 of the WIPO Copyright
128 | Treaty adopted on December 20, 1996, and/or similar international
129 | agreements.
130 |
131 | e. Exceptions and Limitations means fair use, fair dealing, and/or
132 | any other exception or limitation to Copyright and Similar Rights
133 | that applies to Your use of the Licensed Material.
134 |
135 | f. Licensed Material means the artistic or literary work, database,
136 | or other material to which the Licensor applied this Public
137 | License.
138 |
139 | g. Licensed Rights means the rights granted to You subject to the
140 | terms and conditions of this Public License, which are limited to
141 | all Copyright and Similar Rights that apply to Your use of the
142 | Licensed Material and that the Licensor has authority to license.
143 |
144 | h. Licensor means the individual(s) or entity(ies) granting rights
145 | under this Public License.
146 |
147 | i. Share means to provide material to the public by any means or
148 | process that requires permission under the Licensed Rights, such
149 | as reproduction, public display, public performance, distribution,
150 | dissemination, communication, or importation, and to make material
151 | available to the public including in ways that members of the
152 | public may access the material from a place and at a time
153 | individually chosen by them.
154 |
155 | j. Sui Generis Database Rights means rights other than copyright
156 | resulting from Directive 96/9/EC of the European Parliament and of
157 | the Council of 11 March 1996 on the legal protection of databases,
158 | as amended and/or succeeded, as well as other essentially
159 | equivalent rights anywhere in the world.
160 |
161 | k. You means the individual or entity exercising the Licensed Rights
162 | under this Public License. Your has a corresponding meaning.
163 |
164 |
165 | Section 2 -- Scope.
166 |
167 | a. License grant.
168 |
169 | 1. Subject to the terms and conditions of this Public License,
170 | the Licensor hereby grants You a worldwide, royalty-free,
171 | non-sublicensable, non-exclusive, irrevocable license to
172 | exercise the Licensed Rights in the Licensed Material to:
173 |
174 | a. reproduce and Share the Licensed Material, in whole or
175 | in part; and
176 |
177 | b. produce, reproduce, and Share Adapted Material.
178 |
179 | 2. Exceptions and Limitations. For the avoidance of doubt, where
180 | Exceptions and Limitations apply to Your use, this Public
181 | License does not apply, and You do not need to comply with
182 | its terms and conditions.
183 |
184 | 3. Term. The term of this Public License is specified in Section
185 | 6(a).
186 |
187 | 4. Media and formats; technical modifications allowed. The
188 | Licensor authorizes You to exercise the Licensed Rights in
189 | all media and formats whether now known or hereafter created,
190 | and to make technical modifications necessary to do so. The
191 | Licensor waives and/or agrees not to assert any right or
192 | authority to forbid You from making technical modifications
193 | necessary to exercise the Licensed Rights, including
194 | technical modifications necessary to circumvent Effective
195 | Technological Measures. For purposes of this Public License,
196 | simply making modifications authorized by this Section 2(a)
197 | (4) never produces Adapted Material.
198 |
199 | 5. Downstream recipients.
200 |
201 | a. Offer from the Licensor -- Licensed Material. Every
202 | recipient of the Licensed Material automatically
203 | receives an offer from the Licensor to exercise the
204 | Licensed Rights under the terms and conditions of this
205 | Public License.
206 |
207 | b. No downstream restrictions. You may not offer or impose
208 | any additional or different terms or conditions on, or
209 | apply any Effective Technological Measures to, the
210 | Licensed Material if doing so restricts exercise of the
211 | Licensed Rights by any recipient of the Licensed
212 | Material.
213 |
214 | 6. No endorsement. Nothing in this Public License constitutes or
215 | may be construed as permission to assert or imply that You
216 | are, or that Your use of the Licensed Material is, connected
217 | with, or sponsored, endorsed, or granted official status by,
218 | the Licensor or others designated to receive attribution as
219 | provided in Section 3(a)(1)(A)(i).
220 |
221 | b. Other rights.
222 |
223 | 1. Moral rights, such as the right of integrity, are not
224 | licensed under this Public License, nor are publicity,
225 | privacy, and/or other similar personality rights; however, to
226 | the extent possible, the Licensor waives and/or agrees not to
227 | assert any such rights held by the Licensor to the limited
228 | extent necessary to allow You to exercise the Licensed
229 | Rights, but not otherwise.
230 |
231 | 2. Patent and trademark rights are not licensed under this
232 | Public License.
233 |
234 | 3. To the extent possible, the Licensor waives any right to
235 | collect royalties from You for the exercise of the Licensed
236 | Rights, whether directly or through a collecting society
237 | under any voluntary or waivable statutory or compulsory
238 | licensing scheme. In all other cases the Licensor expressly
239 | reserves any right to collect such royalties.
240 |
241 |
242 | Section 3 -- License Conditions.
243 |
244 | Your exercise of the Licensed Rights is expressly made subject to the
245 | following conditions.
246 |
247 | a. Attribution.
248 |
249 | 1. If You Share the Licensed Material (including in modified
250 | form), You must:
251 |
252 | a. retain the following if it is supplied by the Licensor
253 | with the Licensed Material:
254 |
255 | i. identification of the creator(s) of the Licensed
256 | Material and any others designated to receive
257 | attribution, in any reasonable manner requested by
258 | the Licensor (including by pseudonym if
259 | designated);
260 |
261 | ii. a copyright notice;
262 |
263 | iii. a notice that refers to this Public License;
264 |
265 | iv. a notice that refers to the disclaimer of
266 | warranties;
267 |
268 | v. a URI or hyperlink to the Licensed Material to the
269 | extent reasonably practicable;
270 |
271 | b. indicate if You modified the Licensed Material and
272 | retain an indication of any previous modifications; and
273 |
274 | c. indicate the Licensed Material is licensed under this
275 | Public License, and include the text of, or the URI or
276 | hyperlink to, this Public License.
277 |
278 | 2. You may satisfy the conditions in Section 3(a)(1) in any
279 | reasonable manner based on the medium, means, and context in
280 | which You Share the Licensed Material. For example, it may be
281 | reasonable to satisfy the conditions by providing a URI or
282 | hyperlink to a resource that includes the required
283 | information.
284 |
285 | 3. If requested by the Licensor, You must remove any of the
286 | information required by Section 3(a)(1)(A) to the extent
287 | reasonably practicable.
288 |
289 | 4. If You Share Adapted Material You produce, the Adapter's
290 | License You apply must not prevent recipients of the Adapted
291 | Material from complying with this Public License.
292 |
293 |
294 | Section 4 -- Sui Generis Database Rights.
295 |
296 | Where the Licensed Rights include Sui Generis Database Rights that
297 | apply to Your use of the Licensed Material:
298 |
299 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right
300 | to extract, reuse, reproduce, and Share all or a substantial
301 | portion of the contents of the database;
302 |
303 | b. if You include all or a substantial portion of the database
304 | contents in a database in which You have Sui Generis Database
305 | Rights, then the database in which You have Sui Generis Database
306 | Rights (but not its individual contents) is Adapted Material; and
307 |
308 | c. You must comply with the conditions in Section 3(a) if You Share
309 | all or a substantial portion of the contents of the database.
310 |
311 | For the avoidance of doubt, this Section 4 supplements and does not
312 | replace Your obligations under this Public License where the Licensed
313 | Rights include other Copyright and Similar Rights.
314 |
315 |
316 | Section 5 -- Disclaimer of Warranties and Limitation of Liability.
317 |
318 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
319 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
320 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
321 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
322 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
323 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
324 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
325 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
326 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
327 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
328 |
329 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
330 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
331 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
332 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
333 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
334 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
335 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
336 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
337 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
338 |
339 | c. The disclaimer of warranties and limitation of liability provided
340 | above shall be interpreted in a manner that, to the extent
341 | possible, most closely approximates an absolute disclaimer and
342 | waiver of all liability.
343 |
344 |
345 | Section 6 -- Term and Termination.
346 |
347 | a. This Public License applies for the term of the Copyright and
348 | Similar Rights licensed here. However, if You fail to comply with
349 | this Public License, then Your rights under this Public License
350 | terminate automatically.
351 |
352 | b. Where Your right to use the Licensed Material has terminated under
353 | Section 6(a), it reinstates:
354 |
355 | 1. automatically as of the date the violation is cured, provided
356 | it is cured within 30 days of Your discovery of the
357 | violation; or
358 |
359 | 2. upon express reinstatement by the Licensor.
360 |
361 | For the avoidance of doubt, this Section 6(b) does not affect any
362 | right the Licensor may have to seek remedies for Your violations
363 | of this Public License.
364 |
365 | c. For the avoidance of doubt, the Licensor may also offer the
366 | Licensed Material under separate terms or conditions or stop
367 | distributing the Licensed Material at any time; however, doing so
368 | will not terminate this Public License.
369 |
370 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
371 | License.
372 |
373 |
374 | Section 7 -- Other Terms and Conditions.
375 |
376 | a. The Licensor shall not be bound by any additional or different
377 | terms or conditions communicated by You unless expressly agreed.
378 |
379 | b. Any arrangements, understandings, or agreements regarding the
380 | Licensed Material not stated herein are separate from and
381 | independent of the terms and conditions of this Public License.
382 |
383 |
384 | Section 8 -- Interpretation.
385 |
386 | a. For the avoidance of doubt, this Public License does not, and
387 | shall not be interpreted to, reduce, limit, restrict, or impose
388 | conditions on any use of the Licensed Material that could lawfully
389 | be made without permission under this Public License.
390 |
391 | b. To the extent possible, if any provision of this Public License is
392 | deemed unenforceable, it shall be automatically reformed to the
393 | minimum extent necessary to make it enforceable. If the provision
394 | cannot be reformed, it shall be severed from this Public License
395 | without affecting the enforceability of the remaining terms and
396 | conditions.
397 |
398 | c. No term or condition of this Public License will be waived and no
399 | failure to comply consented to unless expressly agreed to by the
400 | Licensor.
401 |
402 | d. Nothing in this Public License constitutes or may be interpreted
403 | as a limitation upon, or waiver of, any privileges and immunities
404 | that apply to the Licensor or You, including from the legal
405 | processes of any jurisdiction or authority.
406 |
407 |
408 | =======================================================================
409 |
410 | Creative Commons is not a party to its public
411 | licenses. Notwithstanding, Creative Commons may elect to apply one of
412 | its public licenses to material it publishes and in those instances
413 | will be considered the “Licensor.” The text of the Creative Commons
414 | public licenses is dedicated to the public domain under the CC0 Public
415 | Domain Dedication. Except for the limited purpose of indicating that
416 | material is shared under a Creative Commons public license or as
417 | otherwise permitted by the Creative Commons policies published at
418 | creativecommons.org/policies, Creative Commons does not authorize the
419 | use of the trademark "Creative Commons" or any other trademark or logo
420 | of Creative Commons without its prior written consent including,
421 | without limitation, in connection with any unauthorized modifications
422 | to any of its public licenses or any other arrangements,
423 | understandings, or agreements concerning use of licensed material. For
424 | the avoidance of doubt, this paragraph does not form part of the
425 | public licenses.
426 |
427 | Creative Commons may be contacted at creativecommons.org.
428 |
429 | ----------------
430 |
431 |
432 | ** In data/multilingual_mathqa, we release Multi-lingual MathQA where we adapt the MathQA-Python dataset by Google into multiple datasets in different programming languages. The original code and dataset are from https://github.com/google/trax/blob/master/trax/examples/MathQA_Python_generation_notebook.ipynb
433 |
434 |
435 | Apache License
436 | Version 2.0, January 2004
437 | http://www.apache.org/licenses/
438 |
439 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
440 |
441 | 1. Definitions.
442 |
443 | "License" shall mean the terms and conditions for use, reproduction,
444 | and distribution as defined by Sections 1 through 9 of this document.
445 |
446 | "Licensor" shall mean the copyright owner or entity authorized by
447 | the copyright owner that is granting the License.
448 |
449 | "Legal Entity" shall mean the union of the acting entity and all
450 | other entities that control, are controlled by, or are under common
451 | control with that entity. For the purposes of this definition,
452 | "control" means (i) the power, direct or indirect, to cause the
453 | direction or management of such entity, whether by contract or
454 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
455 | outstanding shares, or (iii) beneficial ownership of such entity.
456 |
457 | "You" (or "Your") shall mean an individual or Legal Entity
458 | exercising permissions granted by this License.
459 |
460 | "Source" form shall mean the preferred form for making modifications,
461 | including but not limited to software source code, documentation
462 | source, and configuration files.
463 |
464 | "Object" form shall mean any form resulting from mechanical
465 | transformation or translation of a Source form, including but
466 | not limited to compiled object code, generated documentation,
467 | and conversions to other media types.
468 |
469 | "Work" shall mean the work of authorship, whether in Source or
470 | Object form, made available under the License, as indicated by a
471 | copyright notice that is included in or attached to the work
472 | (an example is provided in the Appendix below).
473 |
474 | "Derivative Works" shall mean any work, whether in Source or Object
475 | form, that is based on (or derived from) the Work and for which the
476 | editorial revisions, annotations, elaborations, or other modifications
477 | represent, as a whole, an original work of authorship. For the purposes
478 | of this License, Derivative Works shall not include works that remain
479 | separable from, or merely link (or bind by name) to the interfaces of,
480 | the Work and Derivative Works thereof.
481 |
482 | "Contribution" shall mean any work of authorship, including
483 | the original version of the Work and any modifications or additions
484 | to that Work or Derivative Works thereof, that is intentionally
485 | submitted to Licensor for inclusion in the Work by the copyright owner
486 | or by an individual or Legal Entity authorized to submit on behalf of
487 | the copyright owner. For the purposes of this definition, "submitted"
488 | means any form of electronic, verbal, or written communication sent
489 | to the Licensor or its representatives, including but not limited to
490 | communication on electronic mailing lists, source code control systems,
491 | and issue tracking systems that are managed by, or on behalf of, the
492 | Licensor for the purpose of discussing and improving the Work, but
493 | excluding communication that is conspicuously marked or otherwise
494 | designated in writing by the copyright owner as "Not a Contribution."
495 |
496 | "Contributor" shall mean Licensor and any individual or Legal Entity
497 | on behalf of whom a Contribution has been received by Licensor and
498 | subsequently incorporated within the Work.
499 |
500 | 2. Grant of Copyright License. Subject to the terms and conditions of
501 | this License, each Contributor hereby grants to You a perpetual,
502 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
503 | copyright license to reproduce, prepare Derivative Works of,
504 | publicly display, publicly perform, sublicense, and distribute the
505 | Work and such Derivative Works in Source or Object form.
506 |
507 | 3. Grant of Patent License. Subject to the terms and conditions of
508 | this License, each Contributor hereby grants to You a perpetual,
509 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
510 | (except as stated in this section) patent license to make, have made,
511 | use, offer to sell, sell, import, and otherwise transfer the Work,
512 | where such license applies only to those patent claims licensable
513 | by such Contributor that are necessarily infringed by their
514 | Contribution(s) alone or by combination of their Contribution(s)
515 | with the Work to which such Contribution(s) was submitted. If You
516 | institute patent litigation against any entity (including a
517 | cross-claim or counterclaim in a lawsuit) alleging that the Work
518 | or a Contribution incorporated within the Work constitutes direct
519 | or contributory patent infringement, then any patent licenses
520 | granted to You under this License for that Work shall terminate
521 | as of the date such litigation is filed.
522 |
523 | 4. Redistribution. You may reproduce and distribute copies of the
524 | Work or Derivative Works thereof in any medium, with or without
525 | modifications, and in Source or Object form, provided that You
526 | meet the following conditions:
527 |
528 | (a) You must give any other recipients of the Work or
529 | Derivative Works a copy of this License; and
530 |
531 | (b) You must cause any modified files to carry prominent notices
532 | stating that You changed the files; and
533 |
534 | (c) You must retain, in the Source form of any Derivative Works
535 | that You distribute, all copyright, patent, trademark, and
536 | attribution notices from the Source form of the Work,
537 | excluding those notices that do not pertain to any part of
538 | the Derivative Works; and
539 |
540 | (d) If the Work includes a "NOTICE" text file as part of its
541 | distribution, then any Derivative Works that You distribute must
542 | include a readable copy of the attribution notices contained
543 | within such NOTICE file, excluding those notices that do not
544 | pertain to any part of the Derivative Works, in at least one
545 | of the following places: within a NOTICE text file distributed
546 | as part of the Derivative Works; within the Source form or
547 | documentation, if provided along with the Derivative Works; or,
548 | within a display generated by the Derivative Works, if and
549 | wherever such third-party notices normally appear. The contents
550 | of the NOTICE file are for informational purposes only and
551 | do not modify the License. You may add Your own attribution
552 | notices within Derivative Works that You distribute, alongside
553 | or as an addendum to the NOTICE text from the Work, provided
554 | that such additional attribution notices cannot be construed
555 | as modifying the License.
556 |
557 | You may add Your own copyright statement to Your modifications and
558 | may provide additional or different license terms and conditions
559 | for use, reproduction, or distribution of Your modifications, or
560 | for any such Derivative Works as a whole, provided Your use,
561 | reproduction, and distribution of the Work otherwise complies with
562 | the conditions stated in this License.
563 |
564 | 5. Submission of Contributions. Unless You explicitly state otherwise,
565 | any Contribution intentionally submitted for inclusion in the Work
566 | by You to the Licensor shall be under the terms and conditions of
567 | this License, without any additional terms or conditions.
568 | Notwithstanding the above, nothing herein shall supersede or modify
569 | the terms of any separate license agreement you may have executed
570 | with Licensor regarding such Contributions.
571 |
572 | 6. Trademarks. This License does not grant permission to use the trade
573 | names, trademarks, service marks, or product names of the Licensor,
574 | except as required for reasonable and customary use in describing the
575 | origin of the Work and reproducing the content of the NOTICE file.
576 |
577 | 7. Disclaimer of Warranty. Unless required by applicable law or
578 | agreed to in writing, Licensor provides the Work (and each
579 | Contributor provides its Contributions) on an "AS IS" BASIS,
580 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
581 | implied, including, without limitation, any warranties or conditions
582 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
583 | PARTICULAR PURPOSE. You are solely responsible for determining the
584 | appropriateness of using or redistributing the Work and assume any
585 | risks associated with Your exercise of permissions under this License.
586 |
587 | 8. Limitation of Liability. In no event and under no legal theory,
588 | whether in tort (including negligence), contract, or otherwise,
589 | unless required by applicable law (such as deliberate and grossly
590 | negligent acts) or agreed to in writing, shall any Contributor be
591 | liable to You for damages, including any direct, indirect, special,
592 | incidental, or consequential damages of any character arising as a
593 | result of this License or out of the use or inability to use the
594 | Work (including but not limited to damages for loss of goodwill,
595 | work stoppage, computer failure or malfunction, or any and all
596 | other commercial damages or losses), even if such Contributor
597 | has been advised of the possibility of such damages.
598 |
599 | 9. Accepting Warranty or Additional Liability. While redistributing
600 | the Work or Derivative Works thereof, You may choose to offer,
601 | and charge a fee for, acceptance of support, warranty, indemnity,
602 | or other liability obligations and/or rights consistent with this
603 | License. However, in accepting such obligations, You may act only
604 | on Your own behalf and on Your sole responsibility, not on behalf
605 | of any other Contributor, and only if You agree to indemnify,
606 | defend, and hold each Contributor harmless for any liability
607 | incurred by, or claims asserted against, such Contributor by reason
608 | of your accepting any such warranty or additional liability.
609 |
610 | END OF TERMS AND CONDITIONS
611 |
612 | APPENDIX: How to apply the Apache License to your work.
613 |
614 | To apply the Apache License to your work, attach the following
615 | boilerplate notice, with the fields enclosed by brackets "[]"
616 | replaced with your own identifying information. (Don't include
617 | the brackets!) The text should be enclosed in the appropriate
618 | comment syntax for the file format. We also recommend that a
619 | file or class name and description of purpose be included on the
620 | same "printed page" as the copyright notice for easier
621 | identification within third-party archives.
622 |
623 | Copyright [yyyy] [name of copyright owner]
624 |
625 | Licensed under the Apache License, Version 2.0 (the "License");
626 | you may not use this file except in compliance with the License.
627 | You may obtain a copy of the License at
628 |
629 | http://www.apache.org/licenses/LICENSE-2.0
630 |
631 | Unless required by applicable law or agreed to in writing, software
632 | distributed under the License is distributed on an "AS IS" BASIS,
633 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
634 | See the License for the specific language governing permissions and
635 | limitations under the License.
636 |
--------------------------------------------------------------------------------
/data/mbxp/LICENSE:
--------------------------------------------------------------------------------
1 | Attribution 4.0 International
2 |
3 | =======================================================================
4 |
5 | Creative Commons Corporation ("Creative Commons") is not a law firm and
6 | does not provide legal services or legal advice. Distribution of
7 | Creative Commons public licenses does not create a lawyer-client or
8 | other relationship. Creative Commons makes its licenses and related
9 | information available on an "as-is" basis. Creative Commons gives no
10 | warranties regarding its licenses, any material licensed under their
11 | terms and conditions, or any related information. Creative Commons
12 | disclaims all liability for damages resulting from their use to the
13 | fullest extent possible.
14 |
15 | Using Creative Commons Public Licenses
16 |
17 | Creative Commons public licenses provide a standard set of terms and
18 | conditions that creators and other rights holders may use to share
19 | original works of authorship and other material subject to copyright
20 | and certain other rights specified in the public license below. The
21 | following considerations are for informational purposes only, are not
22 | exhaustive, and do not form part of our licenses.
23 |
24 | Considerations for licensors: Our public licenses are
25 | intended for use by those authorized to give the public
26 | permission to use material in ways otherwise restricted by
27 | copyright and certain other rights. Our licenses are
28 | irrevocable. Licensors should read and understand the terms
29 | and conditions of the license they choose before applying it.
30 | Licensors should also secure all rights necessary before
31 | applying our licenses so that the public can reuse the
32 | material as expected. Licensors should clearly mark any
33 | material not subject to the license. This includes other CC-
34 | licensed material, or material used under an exception or
35 | limitation to copyright. More considerations for licensors:
36 | wiki.creativecommons.org/Considerations_for_licensors
37 |
38 | Considerations for the public: By using one of our public
39 | licenses, a licensor grants the public permission to use the
40 | licensed material under specified terms and conditions. If
41 | the licensor's permission is not necessary for any reason--for
42 | example, because of any applicable exception or limitation to
43 | copyright--then that use is not regulated by the license. Our
44 | licenses grant only permissions under copyright and certain
45 | other rights that a licensor has authority to grant. Use of
46 | the licensed material may still be restricted for other
47 | reasons, including because others have copyright or other
48 | rights in the material. A licensor may make special requests,
49 | such as asking that all changes be marked or described.
50 | Although not required by our licenses, you are encouraged to
51 | respect those requests where reasonable. More_considerations
52 | for the public:
53 | wiki.creativecommons.org/Considerations_for_licensees
54 |
55 | =======================================================================
56 |
57 | Creative Commons Attribution 4.0 International Public License
58 |
59 | By exercising the Licensed Rights (defined below), You accept and agree
60 | to be bound by the terms and conditions of this Creative Commons
61 | Attribution 4.0 International Public License ("Public License"). To the
62 | extent this Public License may be interpreted as a contract, You are
63 | granted the Licensed Rights in consideration of Your acceptance of
64 | these terms and conditions, and the Licensor grants You such rights in
65 | consideration of benefits the Licensor receives from making the
66 | Licensed Material available under these terms and conditions.
67 |
68 |
69 | Section 1 -- Definitions.
70 |
71 | a. Adapted Material means material subject to Copyright and Similar
72 | Rights that is derived from or based upon the Licensed Material
73 | and in which the Licensed Material is translated, altered,
74 | arranged, transformed, or otherwise modified in a manner requiring
75 | permission under the Copyright and Similar Rights held by the
76 | Licensor. For purposes of this Public License, where the Licensed
77 | Material is a musical work, performance, or sound recording,
78 | Adapted Material is always produced where the Licensed Material is
79 | synched in timed relation with a moving image.
80 |
81 | b. Adapter's License means the license You apply to Your Copyright
82 | and Similar Rights in Your contributions to Adapted Material in
83 | accordance with the terms and conditions of this Public License.
84 |
85 | c. Copyright and Similar Rights means copyright and/or similar rights
86 | closely related to copyright including, without limitation,
87 | performance, broadcast, sound recording, and Sui Generis Database
88 | Rights, without regard to how the rights are labeled or
89 | categorized. For purposes of this Public License, the rights
90 | specified in Section 2(b)(1)-(2) are not Copyright and Similar
91 | Rights.
92 |
93 | d. Effective Technological Measures means those measures that, in the
94 | absence of proper authority, may not be circumvented under laws
95 | fulfilling obligations under Article 11 of the WIPO Copyright
96 | Treaty adopted on December 20, 1996, and/or similar international
97 | agreements.
98 |
99 | e. Exceptions and Limitations means fair use, fair dealing, and/or
100 | any other exception or limitation to Copyright and Similar Rights
101 | that applies to Your use of the Licensed Material.
102 |
103 | f. Licensed Material means the artistic or literary work, database,
104 | or other material to which the Licensor applied this Public
105 | License.
106 |
107 | g. Licensed Rights means the rights granted to You subject to the
108 | terms and conditions of this Public License, which are limited to
109 | all Copyright and Similar Rights that apply to Your use of the
110 | Licensed Material and that the Licensor has authority to license.
111 |
112 | h. Licensor means the individual(s) or entity(ies) granting rights
113 | under this Public License.
114 |
115 | i. Share means to provide material to the public by any means or
116 | process that requires permission under the Licensed Rights, such
117 | as reproduction, public display, public performance, distribution,
118 | dissemination, communication, or importation, and to make material
119 | available to the public including in ways that members of the
120 | public may access the material from a place and at a time
121 | individually chosen by them.
122 |
123 | j. Sui Generis Database Rights means rights other than copyright
124 | resulting from Directive 96/9/EC of the European Parliament and of
125 | the Council of 11 March 1996 on the legal protection of databases,
126 | as amended and/or succeeded, as well as other essentially
127 | equivalent rights anywhere in the world.
128 |
129 | k. You means the individual or entity exercising the Licensed Rights
130 | under this Public License. Your has a corresponding meaning.
131 |
132 |
133 | Section 2 -- Scope.
134 |
135 | a. License grant.
136 |
137 | 1. Subject to the terms and conditions of this Public License,
138 | the Licensor hereby grants You a worldwide, royalty-free,
139 | non-sublicensable, non-exclusive, irrevocable license to
140 | exercise the Licensed Rights in the Licensed Material to:
141 |
142 | a. reproduce and Share the Licensed Material, in whole or
143 | in part; and
144 |
145 | b. produce, reproduce, and Share Adapted Material.
146 |
147 | 2. Exceptions and Limitations. For the avoidance of doubt, where
148 | Exceptions and Limitations apply to Your use, this Public
149 | License does not apply, and You do not need to comply with
150 | its terms and conditions.
151 |
152 | 3. Term. The term of this Public License is specified in Section
153 | 6(a).
154 |
155 | 4. Media and formats; technical modifications allowed. The
156 | Licensor authorizes You to exercise the Licensed Rights in
157 | all media and formats whether now known or hereafter created,
158 | and to make technical modifications necessary to do so. The
159 | Licensor waives and/or agrees not to assert any right or
160 | authority to forbid You from making technical modifications
161 | necessary to exercise the Licensed Rights, including
162 | technical modifications necessary to circumvent Effective
163 | Technological Measures. For purposes of this Public License,
164 | simply making modifications authorized by this Section 2(a)
165 | (4) never produces Adapted Material.
166 |
167 | 5. Downstream recipients.
168 |
169 | a. Offer from the Licensor -- Licensed Material. Every
170 | recipient of the Licensed Material automatically
171 | receives an offer from the Licensor to exercise the
172 | Licensed Rights under the terms and conditions of this
173 | Public License.
174 |
175 | b. No downstream restrictions. You may not offer or impose
176 | any additional or different terms or conditions on, or
177 | apply any Effective Technological Measures to, the
178 | Licensed Material if doing so restricts exercise of the
179 | Licensed Rights by any recipient of the Licensed
180 | Material.
181 |
182 | 6. No endorsement. Nothing in this Public License constitutes or
183 | may be construed as permission to assert or imply that You
184 | are, or that Your use of the Licensed Material is, connected
185 | with, or sponsored, endorsed, or granted official status by,
186 | the Licensor or others designated to receive attribution as
187 | provided in Section 3(a)(1)(A)(i).
188 |
189 | b. Other rights.
190 |
191 | 1. Moral rights, such as the right of integrity, are not
192 | licensed under this Public License, nor are publicity,
193 | privacy, and/or other similar personality rights; however, to
194 | the extent possible, the Licensor waives and/or agrees not to
195 | assert any such rights held by the Licensor to the limited
196 | extent necessary to allow You to exercise the Licensed
197 | Rights, but not otherwise.
198 |
199 | 2. Patent and trademark rights are not licensed under this
200 | Public License.
201 |
202 | 3. To the extent possible, the Licensor waives any right to
203 | collect royalties from You for the exercise of the Licensed
204 | Rights, whether directly or through a collecting society
205 | under any voluntary or waivable statutory or compulsory
206 | licensing scheme. In all other cases the Licensor expressly
207 | reserves any right to collect such royalties.
208 |
209 |
210 | Section 3 -- License Conditions.
211 |
212 | Your exercise of the Licensed Rights is expressly made subject to the
213 | following conditions.
214 |
215 | a. Attribution.
216 |
217 | 1. If You Share the Licensed Material (including in modified
218 | form), You must:
219 |
220 | a. retain the following if it is supplied by the Licensor
221 | with the Licensed Material:
222 |
223 | i. identification of the creator(s) of the Licensed
224 | Material and any others designated to receive
225 | attribution, in any reasonable manner requested by
226 | the Licensor (including by pseudonym if
227 | designated);
228 |
229 | ii. a copyright notice;
230 |
231 | iii. a notice that refers to this Public License;
232 |
233 | iv. a notice that refers to the disclaimer of
234 | warranties;
235 |
236 | v. a URI or hyperlink to the Licensed Material to the
237 | extent reasonably practicable;
238 |
239 | b. indicate if You modified the Licensed Material and
240 | retain an indication of any previous modifications; and
241 |
242 | c. indicate the Licensed Material is licensed under this
243 | Public License, and include the text of, or the URI or
244 | hyperlink to, this Public License.
245 |
246 | 2. You may satisfy the conditions in Section 3(a)(1) in any
247 | reasonable manner based on the medium, means, and context in
248 | which You Share the Licensed Material. For example, it may be
249 | reasonable to satisfy the conditions by providing a URI or
250 | hyperlink to a resource that includes the required
251 | information.
252 |
253 | 3. If requested by the Licensor, You must remove any of the
254 | information required by Section 3(a)(1)(A) to the extent
255 | reasonably practicable.
256 |
257 | 4. If You Share Adapted Material You produce, the Adapter's
258 | License You apply must not prevent recipients of the Adapted
259 | Material from complying with this Public License.
260 |
261 |
262 | Section 4 -- Sui Generis Database Rights.
263 |
264 | Where the Licensed Rights include Sui Generis Database Rights that
265 | apply to Your use of the Licensed Material:
266 |
267 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right
268 | to extract, reuse, reproduce, and Share all or a substantial
269 | portion of the contents of the database;
270 |
271 | b. if You include all or a substantial portion of the database
272 | contents in a database in which You have Sui Generis Database
273 | Rights, then the database in which You have Sui Generis Database
274 | Rights (but not its individual contents) is Adapted Material; and
275 |
276 | c. You must comply with the conditions in Section 3(a) if You Share
277 | all or a substantial portion of the contents of the database.
278 |
279 | For the avoidance of doubt, this Section 4 supplements and does not
280 | replace Your obligations under this Public License where the Licensed
281 | Rights include other Copyright and Similar Rights.
282 |
283 |
284 | Section 5 -- Disclaimer of Warranties and Limitation of Liability.
285 |
286 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
287 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
288 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
289 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
290 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
291 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
292 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
293 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
294 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
295 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
296 |
297 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
298 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
299 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
300 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
301 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
302 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
303 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
304 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
305 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
306 |
307 | c. The disclaimer of warranties and limitation of liability provided
308 | above shall be interpreted in a manner that, to the extent
309 | possible, most closely approximates an absolute disclaimer and
310 | waiver of all liability.
311 |
312 |
313 | Section 6 -- Term and Termination.
314 |
315 | a. This Public License applies for the term of the Copyright and
316 | Similar Rights licensed here. However, if You fail to comply with
317 | this Public License, then Your rights under this Public License
318 | terminate automatically.
319 |
320 | b. Where Your right to use the Licensed Material has terminated under
321 | Section 6(a), it reinstates:
322 |
323 | 1. automatically as of the date the violation is cured, provided
324 | it is cured within 30 days of Your discovery of the
325 | violation; or
326 |
327 | 2. upon express reinstatement by the Licensor.
328 |
329 | For the avoidance of doubt, this Section 6(b) does not affect any
330 | right the Licensor may have to seek remedies for Your violations
331 | of this Public License.
332 |
333 | c. For the avoidance of doubt, the Licensor may also offer the
334 | Licensed Material under separate terms or conditions or stop
335 | distributing the Licensed Material at any time; however, doing so
336 | will not terminate this Public License.
337 |
338 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
339 | License.
340 |
341 |
342 | Section 7 -- Other Terms and Conditions.
343 |
344 | a. The Licensor shall not be bound by any additional or different
345 | terms or conditions communicated by You unless expressly agreed.
346 |
347 | b. Any arrangements, understandings, or agreements regarding the
348 | Licensed Material not stated herein are separate from and
349 | independent of the terms and conditions of this Public License.
350 |
351 |
352 | Section 8 -- Interpretation.
353 |
354 | a. For the avoidance of doubt, this Public License does not, and
355 | shall not be interpreted to, reduce, limit, restrict, or impose
356 | conditions on any use of the Licensed Material that could lawfully
357 | be made without permission under this Public License.
358 |
359 | b. To the extent possible, if any provision of this Public License is
360 | deemed unenforceable, it shall be automatically reformed to the
361 | minimum extent necessary to make it enforceable. If the provision
362 | cannot be reformed, it shall be severed from this Public License
363 | without affecting the enforceability of the remaining terms and
364 | conditions.
365 |
366 | c. No term or condition of this Public License will be waived and no
367 | failure to comply consented to unless expressly agreed to by the
368 | Licensor.
369 |
370 | d. Nothing in this Public License constitutes or may be interpreted
371 | as a limitation upon, or waiver of, any privileges and immunities
372 | that apply to the Licensor or You, including from the legal
373 | processes of any jurisdiction or authority.
374 |
375 |
376 | =======================================================================
377 |
378 | Creative Commons is not a party to its public
379 | licenses. Notwithstanding, Creative Commons may elect to apply one of
380 | its public licenses to material it publishes and in those instances
381 | will be considered the “Licensor.” The text of the Creative Commons
382 | public licenses is dedicated to the public domain under the CC0 Public
383 | Domain Dedication. Except for the limited purpose of indicating that
384 | material is shared under a Creative Commons public license or as
385 | otherwise permitted by the Creative Commons policies published at
386 | creativecommons.org/policies, Creative Commons does not authorize the
387 | use of the trademark "Creative Commons" or any other trademark or logo
388 | of Creative Commons without its prior written consent including,
389 | without limitation, in connection with any unauthorized modifications
390 | to any of its public licenses or any other arrangements,
391 | understandings, or agreements concerning use of licensed material. For
392 | the avoidance of doubt, this paragraph does not form part of the
393 | public licenses.
394 |
395 | Creative Commons may be contacted at creativecommons.org.
--------------------------------------------------------------------------------
/data/mbxp/fewshot_prompts/cpp_fewshot.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 |
5 | /**
6 | * Write a c++ function to remove first and last occurrence of a given character from the string.
7 | * > removeOcc(string("hello"), string("l"))
8 | * string("heo")
9 | * > removeOcc(string("abcda"), string("a"))
10 | * string("bcd")
11 | * > removeOcc(string("PHP"), string("P"))
12 | * string("H")
13 | */
14 | string removeOcc(string s, string ch) {
15 | string result = "";
16 | for (int i = 0; i < s.size(); i++) {
17 | if (s[i] != ch[0] && s[i] != ch[ch.size() - 1]) {
18 | result += s[i];
19 | }
20 | }
21 | return result;
22 | }
23 |
24 |
25 | /**
26 | * Write a c++ function to find the maximum sum of elements of list in a list of lists.
27 | * > maximumSum(vector>{{1, 2, 3}, {4, 5, 6}, {10, 11, 12}, {7, 8, 9}})
28 | * 33
29 | * > maximumSum(vector>{{0, 1, 1}, {1, 1, 2}, {3, 2, 1}})
30 | * 6
31 | * > maximumSum(vector>{{0, 1, 3}, {1, 2, 1}, {9, 8, 2}, {0, 1, 0}, {6, 4, 8}})
32 | * 19
33 | */
34 | int maximumSum(vector> list1) {
35 | int max = 0;
36 | for (int i = 0; i < list1.size(); i++) {
37 | int sum = 0;
38 | for (int j = 0; j < list1[i].size(); j++) {
39 | sum += list1[i][j];
40 | }
41 | if (sum > max) {
42 | max = sum;
43 | }
44 | }
45 | return max;
46 | }
47 |
48 |
49 | /**
50 | * Write a function to find frequency count of list of lists.
51 | * > frequencyLists(vector>{{1, 2, 3, 2}, {4, 5, 6, 2}, {7, 8, 9, 5}})
52 | * {{1, 1}, {2, 3}, {3, 1}, {4, 1}, {5, 2}, {6, 1}, {7, 1}, {8, 1}, {9, 1}}
53 | * > frequencyLists(vector>{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}})
54 | * {{1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 1}, {8, 1}, {9, 1}, {10, 1}, {11, 1}, {12, 1}}
55 | * > frequencyLists(vector>{{20, 30, 40, 17}, {18, 16, 14, 13}, {10, 20, 30, 40}})
56 | * {{20, 2}, {30, 2}, {40, 2}, {17, 1}, {18, 1}, {16, 1}, {14, 1}, {13, 1}, {10, 1}}
57 | */
58 | unordered_map frequencyLists(vector> list1) {
59 | unordered_map map = {};
60 | for (auto v : list1) {
61 | for (auto w : v) {
62 | if (map.find(w) != map.end()) {
63 | map[w] += 1;
64 | } else {
65 | map[w] = 1;
66 | }
67 | }
68 | }
69 | return map;
70 | }
--------------------------------------------------------------------------------
/data/mbxp/fewshot_prompts/csharp_fewshot.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text.RegularExpressions;
5 |
6 | namespace Solution
7 | {
8 | public class Program
9 | {
10 | ///
11 | /// Write a function to filter even numbers using lambda function.
12 | ///
13 | /// Examples:
14 | /// >>> FilterEvennumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
15 | /// >>> [2, 4, 6, 8, 10]
16 | /// >>> FilterEvennumbers([10,20,45,67,84,93])
17 | /// >>> [10,20,84]
18 | /// >>> FilterEvennumbers([5,7,9,8,6,4,3])
19 | /// >>> [8,6,4]
20 | ///
21 | public static List FilterEvennumbers (List nums)
22 | {
23 | return nums.Where(x => x % 2 == 0).ToList();
24 | }
25 | }
26 | }
27 |
28 | using System;
29 | using System.Collections.Generic;
30 | using System.Linq;
31 | using System.Text.RegularExpressions;
32 |
33 | namespace Solution
34 | {
35 | public class Program
36 | {
37 | ///
38 | /// Write a c# function to count true booleans in the given list.
39 | ///
40 | /// Examples:
41 | /// >>> Count([True,False,True])
42 | /// >>> 2
43 | /// >>> Count([False,False])
44 | /// >>> 0
45 | /// >>> Count([True,True,True])
46 | /// >>> 3
47 | ///
48 | public static int Count (List lst)
49 | {
50 | return lst.Where(x => x).Count();
51 | }
52 | }
53 | }
54 |
55 | using System;
56 | using System.Collections.Generic;
57 | using System.Linq;
58 | using System.Text.RegularExpressions;
59 |
60 | namespace Solution
61 | {
62 | public class Program
63 | {
64 | ///
65 | /// Write a function to count total characters in a string.
66 | ///
67 | /// Examples:
68 | /// >>> CountCharac("python programming")
69 | /// >>> 18
70 | /// >>> CountCharac("language")
71 | /// >>> 8
72 | /// >>> CountCharac("words")
73 | /// >>> 5
74 | ///
75 | public static int CountCharac (string str1)
76 | {
77 | // write your code here
78 | return str1.Length;
79 | }
80 | }
81 | }
--------------------------------------------------------------------------------
/data/mbxp/fewshot_prompts/go_fewshot.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // Code should be written in Go/Golang
4 | // Write a golang function to count positive numbers in a list.
5 | // Examples:
6 | // >>> pos_count([1,-2,3,-4])
7 | // >>> 2
8 | // >>> pos_count([3,4,5,-1])
9 | // >>> 3
10 | // >>> pos_count([1,2,3,4])
11 | // >>> 4
12 | func pos_count (list []int) int {
13 |
14 | // --------------------- COMPLETION (model generated) ---------------------
15 | var count int
16 | for _, v := range list {
17 | if v > 0 {
18 | count += 1
19 | }
20 | }
21 | return count
22 | }
23 |
24 |
25 | // Code should be written in Go/Golang
26 | // Write a function to check whether all items of a list are equal to a given string.
27 | // Examples:
28 | // >>> check_element(["green", "orange", "black", "white"],'blue')
29 | // >>> False
30 | // >>> check_element([1,2,3,4],7)
31 | // >>> False
32 | // >>> check_element(["green", "green", "green", "green"],'green')
33 | // >>> True
34 | func check_element (list []interface{}, element interface{}) bool {
35 |
36 | // --------------------- COMPLETION (model generated) ---------------------
37 | for _, v := range list {
38 | if v != element {
39 | return false
40 | }
41 | }
42 | return true
43 | }
44 |
45 |
46 | // Code should be written in Go/Golang
47 | // Write a golang function to left rotate the string.
48 | // Examples:
49 | // >>> left_rotate("python",2)
50 | // >>> "thonpy"
51 | // >>> left_rotate("bigdata",3 )
52 | // >>> "databig"
53 | // >>> left_rotate("hadoop",1 )
54 | // >>> "adooph"
55 | func left_rotate (s string, d int) string {
56 |
57 | // --------------------- COMPLETION (model generated) ---------------------
58 | tmp := s[d : ] + s[0 : d]
59 | return tmp
60 | }
--------------------------------------------------------------------------------
/data/mbxp/fewshot_prompts/java_fewshot_v1.java:
--------------------------------------------------------------------------------
1 | class DifferAtOneBitPos {
2 | /**
3 | * Write a java function to check whether the two numbers differ at one bit position only or not.
4 | * > DifferAtOneBitPos.differAtOneBitPos(13, 9)
5 | * true
6 | * > DifferAtOneBitPos.differAtOneBitPos(15, 8)
7 | * false
8 | * > DifferAtOneBitPos.differAtOneBitPos(2, 4)
9 | * false
10 | */
11 | public static boolean differAtOneBitPos(int a, int b) {
12 | int diff = a ^ b;
13 | int count = 0;
14 | while (diff > 0) {
15 | diff = diff & (diff - 1);
16 | count++;
17 | }
18 | return count == 1;
19 | }
20 | }
21 |
22 |
23 | class TestDuplicate {
24 | /**
25 | * Write a function to find whether a given array of integers contains any duplicate element.
26 | * > TestDuplicate.testDuplicate([1, 2, 3, 4, 5])
27 | * false
28 | * > TestDuplicate.testDuplicate([1, 2, 3, 4, 4])
29 | * true
30 | * > TestDuplicate.testDuplicate([1, 1, 2, 2, 3, 3, 4, 4, 5])
31 | * true
32 | */
33 | public static boolean testDuplicate(List arraynums) {
34 | Set set = new HashSet();
35 | for (int i = 0; i < arraynums.size(); i++) {
36 | if (set.contains(arraynums.get(i))) {
37 | return true;
38 | }
39 | set.add(arraynums.get(i));
40 | }
41 | return false;
42 | }
43 | }
44 |
45 | class FreqElement {
46 | /**
47 | * Write a function to find frequency of the elements in a given list of lists using collections module.
48 | * > FreqElement.freqElement([[1, 2, 3, 2], [4, 5, 6, 2], [7, 1, 9, 5]])
49 | * {'2':3,'1':2,'5':2,'3':1,'4':1,'6':1,'7':1,'9':1}
50 | * > FreqElement.freqElement([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
51 | * {'1':1,'2':1,'3':1,'4':1,'5':1,'6':1,'7':1,'8':1,'9':1,'10':1,'11':1,'12':1}
52 | * > FreqElement.freqElement([[15, 20, 30, 40], [80, 90, 100, 110], [30, 30, 80, 90]])
53 | * {'30':3,'80':2,'90':2,'15':1,'20':1,'40':1,'100':1,'110':1}
54 | */
55 | public static HashMap freqElement(List> nums) {
56 | HashMap freq = new HashMap<>();
57 | for (List list : nums) {
58 | for (int i : list) {
59 | freq.put(i, freq.getOrDefault(i, 0) + 1);
60 | }
61 | }
62 | return freq;
63 | }
64 | }
--------------------------------------------------------------------------------
/data/mbxp/fewshot_prompts/javascript_fewshot_v1.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Write a javascript function to identify non-prime numbers.
3 | * > isNotPrime(2)
4 | * false
5 | * > isNotPrime(10)
6 | * true
7 | * > isNotPrime(35)
8 | * true
9 | */
10 | function isNotPrime(n) {
11 | for (let i = 2; i < n; i++) {
12 | if (n % i === 0) {
13 | return true;
14 | }
15 | }
16 | return false;
17 | }
18 |
19 | /**
20 | * Write a javascript function to remove all digits from a list of strings.
21 | * > remove(["4words", "3letters", "4digits"])
22 | * ["words", "letters", "digits"]
23 | * > remove(["28Jan", "12Jan", "11Jan"])
24 | * ["Jan", "Jan", "Jan"]
25 | * > remove(["wonder1", "wonder2", "wonder3"])
26 | * ["wonder", "wonder", "wonder"]
27 | */
28 | function remove(list) {
29 | return list.map(item => item.replace(/\d+/g, ''));
30 | }
31 |
32 | /**
33 | * Write a javascript function to determine whether all the numbers are different from each other are not.
34 | * > testDistinct([1, 5, 7, 9])
35 | * true
36 | * > testDistinct([2, 4, 5, 5, 7, 9])
37 | * false
38 | * > testDistinct([1, 2, 3])
39 | * true
40 | */
41 | function testDistinct(data) {
42 | return data.every((item, index) => {
43 | return data.indexOf(item) === index;
44 | });
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/data/mbxp/fewshot_prompts/kotlin_fewshot_v1.kt:
--------------------------------------------------------------------------------
1 | /**
2 | * You are an expert Kotlin programmer, and here is your task.
3 | * Write a function to locate the right insertion point for a specified value in sorted order.
4 | * >>> rightInsertion([1, 2, 4, 5], 6)
5 | * 4
6 | * >>> rightInsertion([1, 2, 4, 5], 3)
7 | * 2
8 | * >>> rightInsertion([1, 2, 4, 5], 7)
9 | * 4
10 | */
11 | fun rightInsertion(a : List, x : Int) : Int {
12 | var low = 0
13 | var high = a.size - 1
14 | while (low <= high) {
15 | var mid = (low + high) / 2
16 | if (a[mid] == x) {
17 | return mid
18 | } else if (a[mid] < x) {
19 | low = mid + 1
20 | } else {
21 | high = mid - 1
22 | }
23 | }
24 | return low
25 | }
26 |
27 | /**
28 | * You are an expert Kotlin programmer, and here is your task.
29 | * Write a Kotlin function to find the length of the longest word.
30 | * >>> lenLog(["python", "PHP", "bigdata"])
31 | * 7
32 | * >>> lenLog(["a", "ab", "abc"])
33 | * 3
34 | */
35 | fun lenLog(list1 : List) : Int {
36 | val list2 = list1.filter { it.length > 0 }
37 | return list2.maxBy { it.length }!!.length
38 | }
39 |
40 | /**
41 | * You are an expert Kotlin programmer, and here is your task.
42 | * Write a function to shortlist words that are longer than n from a given list of words.
43 | * >>> longWords(3, "python is a programming language")
44 | * ["python", "programming", "language"]
45 | * >>> longWords(2, "writing a program")
46 | * ["writing", "program"]
47 | */
48 | fun longWords(n : Int, str : String) : List {
49 | val words = str.split(" ")
50 | return words.filter { it.length > n }
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/data/mbxp/fewshot_prompts/perl_fewshot.perl:
--------------------------------------------------------------------------------
1 | # You are an expert Perl programmer, and here is your task.
2 | # Write a Perl function to count positive numbers in a list.
3 | # >>> pos_count([1, -2, 3, -4])
4 | # 2
5 | # >>> pos_count([3, 4, 5, -1])
6 | # 3
7 | # >>> pos_count([1, 2, 3, 4])
8 | # 4
9 | sub pos_count
10 | {
11 | my ($list) = @_;
12 | my ($pos, $count) = 0;
13 | foreach my $x (@$list) {
14 | if ($x > 0) {
15 | $pos++;
16 | }
17 | }
18 | return $pos;
19 | }
20 |
21 | # You are an expert Perl programmer, and here is your task.
22 | # Write a function to find minimum of three numbers.
23 | # >>> min_of_three(10, 20, 0)
24 | # 0
25 | # >>> min_of_three(19, 15, 18)
26 | # 15
27 | # >>> min_of_three(-10, -20, -30)
28 | # -30
29 | sub min_of_three
30 | {
31 | my ($a, $b, $c) = @_;
32 | return ($a < $b ? $a : $b) < $c ? $b : $c;
33 | }
34 |
35 | # You are an expert Perl programmer, and here is your task.
36 | # Write a function to replace characters in a string.
37 | # >>> replace_char("polygon", "y", "l")
38 | # "pollgon"
39 | # >>> replace_char("character", "c", "a")
40 | # "aharaater"
41 | # >>> replace_char("python", "l", "a")
42 | # "python"
43 | sub replace_char
44 | {
45 | my ($str1, $ch, $newch) = @_;
46 | $str1 =~ s/$ch/$newch/g;
47 | return $str1;
48 | }
--------------------------------------------------------------------------------
/data/mbxp/fewshot_prompts/php_fewshot_v1.php:
--------------------------------------------------------------------------------
1 | recursiveListSum([1, 2, [3, 4], [5, 6]])
7 | * 21
8 | * php > recursiveListSum([7, 10, [15, 14], [19, 41]])
9 | * 106
10 | * php > recursiveListSum([10, 20, [30, 40], [50, 60]])
11 | * 210
12 | */
13 | function recursiveListSum($dataList) {
14 | $sum = 0;
15 | $i = 0;
16 | foreach ($dataList as $item) {
17 | if (is_array($item)) {
18 | $sum += recursiveListSum($item);
19 | } else {
20 | $sum += $item;
21 | }
22 | }
23 | return $sum;
24 | }
25 |
26 | /**
27 | * You are an expert PHP programmer, and here is your task.
28 | * Write function to find the sum of all items in the given dictionary.
29 | * php > returnSum(["a" => 100, "b" => 200, "c" => 300])
30 | * 600
31 | * php > returnSum(["a" => 25, "b" => 18, "c" => 45])
32 | * 88
33 | * php > returnSum(["a" => 36, "b" => 39, "c" => 49])
34 | * 124
35 | */
36 | function returnSum($dict) {
37 | $sum = 0;
38 | foreach ($dict as $key => $value) {
39 | $sum += $value;
40 | }
41 | return $sum;
42 | }
43 |
44 | /**
45 | * You are an expert PHP programmer, and here is your task.
46 | * Write a function to find squares of individual elements in a list using lambda function.
47 | * php > squareNums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
48 | * [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
49 | * php > squareNums([10, 20, 30])
50 | * [100, 400, 900]
51 | * php > squareNums([12, 15])
52 | * [144, 225]
53 | */
54 | function squareNums($nums) {
55 | $squares = [];
56 | foreach ($nums as $num) {
57 | $squares[] = $num * $num;
58 | }
59 | return $squares;
60 | }
61 |
62 | ?>
63 |
--------------------------------------------------------------------------------
/data/mbxp/fewshot_prompts/python_fewshot_v1.py:
--------------------------------------------------------------------------------
1 | def find_char_long(text):
2 | """
3 | Write a function to find all words which are at least 4 characters long in a string by using regex.
4 | >>> find_char_long('Please move back to stream')
5 | ['Please', 'move', 'back', 'stream']
6 | >>> find_char_long('Jing Eco and Tech')
7 | ['Jing', 'Tech']
8 | >>> find_char_long('Jhingai wulu road Zone 3')
9 | ['Jhingai', 'wulu', 'road', 'Zone']
10 | """
11 | import re
12 |
13 | return re.findall(r"\b\w{4,}\b", text)
14 |
15 |
16 | def square_nums(nums):
17 | """
18 | Write a function to find squares of individual elements in a list using lambda function.
19 | >>> square_nums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
20 | [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
21 | >>> square_nums([10,20,30])
22 | ([100,400,900])
23 | >>> square_nums([12,15])
24 | ([144,225])
25 | """
26 | return list(map(lambda x: x**2, nums))
27 |
28 |
29 | def test_duplicate(arraynums):
30 | """
31 | Write a function to find whether a given array of integers contains any duplicate element.
32 | >>> test_duplicate(([1,2,3,4,5]))
33 | False
34 | >>> test_duplicate(([1,2,3,4, 4]))
35 | True
36 | >>> test_duplicate([1,1,2,2,3,3,4,4,5])
37 | True
38 | """
39 | if len(arraynums) == len(set(arraynums)):
40 | return False
41 | else:
42 | return True
43 |
--------------------------------------------------------------------------------
/data/mbxp/fewshot_prompts/ruby_fewshot_v1.rb:
--------------------------------------------------------------------------------
1 | ##
2 | # You are an expert Ruby programmer, and here is your task.
3 | # Write a Ruby function to remove all digits from a list of strings.
4 | # irb> remove(["4words", "3letters", "4digits"])
5 | # => ["words", "letters", "digits"]
6 | # irb> remove(["28Jan", "12Jan", "11Jan"])
7 | # => ["Jan", "Jan", "Jan"]
8 | # irb> remove(["wonder1", "wonder2", "wonder3"])
9 | # => ["wonder", "wonder", "wonder"]
10 | def remove(list)
11 | return list.map { |word| word.gsub(/\d+/, '') }
12 | end
13 |
14 | ##
15 | # You are an expert Ruby programmer, and here is your task.
16 | # Write a Ruby function to remove even numbers from a given list.
17 | # irb> remove_even([1, 3, 5, 2])
18 | # => [1, 3, 5]
19 | # irb> remove_even([5, 6, 7])
20 | # => [5, 7]
21 | # irb> remove_even([1, 2, 3, 4])
22 | # => [1, 3]
23 | def remove_even(l)
24 | return l.reject {|x| x % 2 == 0}
25 | end
26 |
27 | ##
28 | # You are an expert Ruby programmer, and here is your task.
29 | # Write a Ruby function to find the minimum of two numbers.
30 | # irb> minimum(1, 2)
31 | # => 1
32 | # irb> minimum(-5, -4)
33 | # => -5
34 | # irb> minimum(0, 0)
35 | # => 0
36 | def minimum(a, b)
37 | return a < b ? a : b
38 | end
--------------------------------------------------------------------------------
/data/mbxp/fewshot_prompts/scala_fewshot.scala:
--------------------------------------------------------------------------------
1 | object Main extends App {
2 | /**
3 | * You are an expert Scala programmer, and here is your task.
4 | * Write a function to reverse strings in a given list of string values.
5 | * >>> reverseStringList(List("Red", "Green", "Blue", "White", "Black"))
6 | * List("deR", "neerG", "eulB", "etihW", "kcalB")
7 | * >>> reverseStringList(List("john", "amal", "joel", "george"))
8 | * List("nhoj", "lama", "leoj", "egroeg")
9 | * >>> reverseStringList(List("jack", "john", "mary"))
10 | * List("kcaj", "nhoj", "yram")
11 | */
12 | def reverseStringList(stringlist : List[String]) : List[String] = {
13 | stringlist.map(_.reverse)
14 | }
15 | }
16 |
17 | object Main extends App {
18 | /**
19 | * You are an expert Scala programmer, and here is your task.
20 | * Write a function to sort a list of tuples in increasing order by the last element in each tuple.
21 | * >>> sortTuple(List(List(1, 3), List(3, 2), List(2, 1)))
22 | * List(List(2, 1), List(3, 2), List(1, 3))
23 | * >>> sortTuple(List(List(2, 4), List(3, 3), List(1, 1)))
24 | * List(List(1, 1), List(3, 3), List(2, 4))
25 | * >>> sortTuple(List(List(3, 9), List(6, 7), List(4, 3)))
26 | * List(List(4, 3), List(6, 7), List(3, 9))
27 | */
28 | def sortTuple(tup : List[List[Int]]) : List[List[Int]] = {
29 | val sorted = tup.sortBy(_.last)
30 | sorted
31 | }
32 | }
33 |
34 | object Main extends App {
35 | /**
36 | * You are an expert Scala programmer, and here is your task.
37 | * Write a function to check whether the given key is present in the dictionary or not.
38 | * >>> isKeyPresent(Map(1->10, 2->20, 3->30, 4->40, 5->50, 6->60), 5)
39 | * true
40 | * >>> isKeyPresent(Map(1->10, 2->20, 3->30, 4->40, 5->50, 6->60), 6)
41 | * true
42 | * >>> isKeyPresent(Map(1->10, 2->20, 3->30, 4->40, 5->50, 6->60), 10)
43 | * false
44 | */
45 | def isKeyPresent(d : Map[Int, Int], x : Int) : Boolean = {
46 | d.keySet.contains(x)
47 | }
48 | }
--------------------------------------------------------------------------------
/data/mbxp/fewshot_prompts/swift_fewshot.swift:
--------------------------------------------------------------------------------
1 | /**
2 | * You are an expert Swift programmer, and here is your task.
3 | * Write a function that matches a string that has an a followed by two to three 'b'.
4 | * >>> textMatchTwoThree("ac")
5 | * "Not matched!"
6 | * >>> textMatchTwoThree("dc")
7 | * "Not matched!"
8 | * >>> textMatchTwoThree("abbbba")
9 | * "Found a match!"
10 | */
11 | func textMatchTwoThree(text : String) -> String {
12 | if (text.contains("a") && text.contains("b") && text.contains("b")) {
13 | return "Found a match!"
14 | } else {
15 | return "Not matched!"
16 | }
17 | }
18 |
19 | /**
20 | * You are an expert Swift programmer, and here is your task.
21 | * Write a Swift function to find the maximum of two numbers.
22 | * >>> maximum(5, 10)
23 | * 10
24 | * >>> maximum(-1, -2)
25 | * -1
26 | * >>> maximum(9, 7)
27 | * 9
28 | */
29 | func maximum(a : Int, b : Int) -> Int {
30 | return a > b ? a : b
31 | }
32 |
33 | /**
34 | * You are an expert Swift programmer, and here is your task.
35 | * Write a function to check if all values are same in a dictionary.
36 | * >>> checkValue(["Cierra Vega" : 12, "Alden Cantrell" : 12, "Kierra Gentry" : 12, "Pierre Cox" : 12], 10)
37 | * false
38 | * >>> checkValue(["Cierra Vega" : 12, "Alden Cantrell" : 12, "Kierra Gentry" : 12, "Pierre Cox" : 12], 12)
39 | * true
40 | * >>> checkValue(["Cierra Vega" : 12, "Alden Cantrell" : 12, "Kierra Gentry" : 12, "Pierre Cox" : 12], 5)
41 | * false
42 | */
43 | func checkValue(dict : [String: Int], n : Int) -> Bool {
44 | for (key, value) in dict {
45 | if (value != n) {
46 | return false
47 | }
48 | }
49 | return true
50 | }
--------------------------------------------------------------------------------
/data/mbxp/fewshot_prompts/typescript_fewshot.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Write a function to find all words which are at least 4 characters long in a string by using regex.
3 | *
4 | * Examples:
5 | * >>> find_char_long('Please move back to stream')
6 | * >>> ['Please', 'move', 'back', 'stream']
7 | * >>> find_char_long('Jing Eco and Tech')
8 | * >>> ['Jing', 'Tech']
9 | * >>> find_char_long('Jhingai wulu road Zone 3')
10 | * >>> ['Jhingai', 'wulu', 'road', 'Zone']
11 | */
12 | const find_char_long = function (text: string) : Array {
13 | return text.match(/\w{4,}/g)
14 | }
15 |
16 | /**
17 | * Write a function to count the most common words in a dictionary.
18 | *
19 | * Examples:
20 | * >>> count_common(['red','green','black','pink','black','white','black','eyes','white','black','orange','pink','pink','red','red','white','orange','white',"black",'pink','green','green','pink','green','pink','white','orange',"orange",'red'])
21 | * >>> [('pink', 6), ('black', 5), ('white', 5), ('red', 4)]
22 | * >>> count_common(['one', 'two', 'three', 'four', 'five', 'one', 'two', 'one', 'three', 'one'])
23 | * >>> [('one', 4), ('two', 2), ('three', 2), ('four', 1)]
24 | * >>> count_common(['Facebook', 'Apple', 'Amazon', 'Netflix', 'Google', 'Apple', 'Netflix', 'Amazon'])
25 | * >>> [('Apple', 2), ('Amazon', 2), ('Netflix', 2), ('Facebook', 1)]
26 | */
27 | const count_common = function (words: Array) : Array> {
28 | const counts = {};
29 | for (const word of words) {
30 | counts[word] = counts[word] ? counts[word] + 1 : 1;
31 | }
32 | return Object.entries(counts).sort((a, b) => b[1] - a[1]);
33 | }
34 |
35 | /**
36 | * Write a function to group the 1st elements on the basis of 2nd elements in the given tuple list.
37 | *
38 | * Examples:
39 | * >>> group_element([(6, 5), (2, 7), (2, 5), (8, 7), (9, 8), (3, 7)])
40 | * >>> {5: [6, 2], 7: [2, 8, 3], 8: [9]}
41 | * >>> group_element([(7, 6), (3, 8), (3, 6), (9, 8), (10, 9), (4, 8)])
42 | * >>> {6: [7, 3], 8: [3, 9, 4], 9: [10]}
43 | * >>> group_element([(8, 7), (4, 9), (4, 7), (10, 9), (11, 10), (5, 9)])
44 | * >>> {7: [8, 4], 9: [4, 10, 5], 10: [11]}
45 | */
46 | const group_element = function (test_list: Array>) : Map> {
47 | const result = new Map();
48 | for (const [key, value] of test_list) {
49 | if (result.has(value)) {
50 | result.get(value).push(key);
51 | } else {
52 | result.set(value, [key]);
53 | }
54 | }
55 | return result;
56 | }
--------------------------------------------------------------------------------
/data/mbxp/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "python": "mbpp_release_v1.jsonl",
3 | "java": "mbjp_release_v1.2.jsonl",
4 | "javascript": "mbjsp_release_v1.2.jsonl",
5 | "typescript": "mbtsp_release_v1.2.jsonl",
6 | "kotlin": "mbkp_release_v1.2.jsonl",
7 | "ruby": "mbrbp_release_v1.2.jsonl",
8 | "php": "mbphp_release_v1.2.jsonl",
9 | "cpp": "mbcpp_release_v1.2.jsonl",
10 | "csharp": "mbcsp_release_v1.2.jsonl",
11 | "go": "mbgp_release_v1.1.jsonl",
12 | "perl": "mbplp_release_v1.jsonl",
13 | "scala": "mbscp_release_v1.jsonl",
14 | "swift": "mbswp_release_v1.jsonl"
15 | }
16 |
--------------------------------------------------------------------------------
/data/mbxp/metadata_examples.json:
--------------------------------------------------------------------------------
1 | {
2 | "python": "examples/mbpp_samples.jsonl",
3 | "java": "examples/mbjp_samples.jsonl",
4 | "javascript": "examples/mbjsp_samples.jsonl",
5 | "typescript": "examples/mbtsp_samples.jsonl",
6 | "kotlin": "examples/mbkp_samples.jsonl",
7 | "ruby": "examples/mbrbp_samples.jsonl",
8 | "php": "examples/mbphp_samples.jsonl",
9 | "cpp": "examples/mbcpp_samples.jsonl",
10 | "csharp": "examples/mbcsp_samples.jsonl",
11 | "go": "examples/mbgp_samples.jsonl",
12 | "perl": "examples/mbplp_samples.jsonl",
13 | "scala": "examples/mbscp_samples.jsonl",
14 | "swift": "examples/mbswp_samples.jsonl"
15 | }
--------------------------------------------------------------------------------
/data/multilingual_humaneval/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/data/multilingual_humaneval/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "python": "HumanEval.jsonl",
3 | "csharp": "HumanEval_csharp_v1.jsonl",
4 | "go": "HumanEval_go_v1.jsonl",
5 | "java": "HumanEval_java_v1.1.jsonl",
6 | "javascript": "HumanEval_javascript_v1.1.jsonl",
7 | "kotlin": "HumanEval_kotlin_v1.1.jsonl",
8 | "perl": "HumanEval_perl_v1.1.jsonl",
9 | "php": "HumanEval_php_v1.1.jsonl",
10 | "ruby": "HumanEval_ruby_v1.1.jsonl",
11 | "scala": "HumanEval_scala_v1.1.jsonl",
12 | "swift": "HumanEval_swift_v1.1.jsonl",
13 | "typescript": "HumanEval_typescript_v1.jsonl"
14 | }
--------------------------------------------------------------------------------
/data/multilingual_mathqa/LICENSE:
--------------------------------------------------------------------------------
1 | Attribution 4.0 International
2 |
3 | =======================================================================
4 |
5 | Creative Commons Corporation ("Creative Commons") is not a law firm and
6 | does not provide legal services or legal advice. Distribution of
7 | Creative Commons public licenses does not create a lawyer-client or
8 | other relationship. Creative Commons makes its licenses and related
9 | information available on an "as-is" basis. Creative Commons gives no
10 | warranties regarding its licenses, any material licensed under their
11 | terms and conditions, or any related information. Creative Commons
12 | disclaims all liability for damages resulting from their use to the
13 | fullest extent possible.
14 |
15 | Using Creative Commons Public Licenses
16 |
17 | Creative Commons public licenses provide a standard set of terms and
18 | conditions that creators and other rights holders may use to share
19 | original works of authorship and other material subject to copyright
20 | and certain other rights specified in the public license below. The
21 | following considerations are for informational purposes only, are not
22 | exhaustive, and do not form part of our licenses.
23 |
24 | Considerations for licensors: Our public licenses are
25 | intended for use by those authorized to give the public
26 | permission to use material in ways otherwise restricted by
27 | copyright and certain other rights. Our licenses are
28 | irrevocable. Licensors should read and understand the terms
29 | and conditions of the license they choose before applying it.
30 | Licensors should also secure all rights necessary before
31 | applying our licenses so that the public can reuse the
32 | material as expected. Licensors should clearly mark any
33 | material not subject to the license. This includes other CC-
34 | licensed material, or material used under an exception or
35 | limitation to copyright. More considerations for licensors:
36 | wiki.creativecommons.org/Considerations_for_licensors
37 |
38 | Considerations for the public: By using one of our public
39 | licenses, a licensor grants the public permission to use the
40 | licensed material under specified terms and conditions. If
41 | the licensor's permission is not necessary for any reason--for
42 | example, because of any applicable exception or limitation to
43 | copyright--then that use is not regulated by the license. Our
44 | licenses grant only permissions under copyright and certain
45 | other rights that a licensor has authority to grant. Use of
46 | the licensed material may still be restricted for other
47 | reasons, including because others have copyright or other
48 | rights in the material. A licensor may make special requests,
49 | such as asking that all changes be marked or described.
50 | Although not required by our licenses, you are encouraged to
51 | respect those requests where reasonable. More_considerations
52 | for the public:
53 | wiki.creativecommons.org/Considerations_for_licensees
54 |
55 | =======================================================================
56 |
57 | Creative Commons Attribution 4.0 International Public License
58 |
59 | By exercising the Licensed Rights (defined below), You accept and agree
60 | to be bound by the terms and conditions of this Creative Commons
61 | Attribution 4.0 International Public License ("Public License"). To the
62 | extent this Public License may be interpreted as a contract, You are
63 | granted the Licensed Rights in consideration of Your acceptance of
64 | these terms and conditions, and the Licensor grants You such rights in
65 | consideration of benefits the Licensor receives from making the
66 | Licensed Material available under these terms and conditions.
67 |
68 |
69 | Section 1 -- Definitions.
70 |
71 | a. Adapted Material means material subject to Copyright and Similar
72 | Rights that is derived from or based upon the Licensed Material
73 | and in which the Licensed Material is translated, altered,
74 | arranged, transformed, or otherwise modified in a manner requiring
75 | permission under the Copyright and Similar Rights held by the
76 | Licensor. For purposes of this Public License, where the Licensed
77 | Material is a musical work, performance, or sound recording,
78 | Adapted Material is always produced where the Licensed Material is
79 | synched in timed relation with a moving image.
80 |
81 | b. Adapter's License means the license You apply to Your Copyright
82 | and Similar Rights in Your contributions to Adapted Material in
83 | accordance with the terms and conditions of this Public License.
84 |
85 | c. Copyright and Similar Rights means copyright and/or similar rights
86 | closely related to copyright including, without limitation,
87 | performance, broadcast, sound recording, and Sui Generis Database
88 | Rights, without regard to how the rights are labeled or
89 | categorized. For purposes of this Public License, the rights
90 | specified in Section 2(b)(1)-(2) are not Copyright and Similar
91 | Rights.
92 |
93 | d. Effective Technological Measures means those measures that, in the
94 | absence of proper authority, may not be circumvented under laws
95 | fulfilling obligations under Article 11 of the WIPO Copyright
96 | Treaty adopted on December 20, 1996, and/or similar international
97 | agreements.
98 |
99 | e. Exceptions and Limitations means fair use, fair dealing, and/or
100 | any other exception or limitation to Copyright and Similar Rights
101 | that applies to Your use of the Licensed Material.
102 |
103 | f. Licensed Material means the artistic or literary work, database,
104 | or other material to which the Licensor applied this Public
105 | License.
106 |
107 | g. Licensed Rights means the rights granted to You subject to the
108 | terms and conditions of this Public License, which are limited to
109 | all Copyright and Similar Rights that apply to Your use of the
110 | Licensed Material and that the Licensor has authority to license.
111 |
112 | h. Licensor means the individual(s) or entity(ies) granting rights
113 | under this Public License.
114 |
115 | i. Share means to provide material to the public by any means or
116 | process that requires permission under the Licensed Rights, such
117 | as reproduction, public display, public performance, distribution,
118 | dissemination, communication, or importation, and to make material
119 | available to the public including in ways that members of the
120 | public may access the material from a place and at a time
121 | individually chosen by them.
122 |
123 | j. Sui Generis Database Rights means rights other than copyright
124 | resulting from Directive 96/9/EC of the European Parliament and of
125 | the Council of 11 March 1996 on the legal protection of databases,
126 | as amended and/or succeeded, as well as other essentially
127 | equivalent rights anywhere in the world.
128 |
129 | k. You means the individual or entity exercising the Licensed Rights
130 | under this Public License. Your has a corresponding meaning.
131 |
132 |
133 | Section 2 -- Scope.
134 |
135 | a. License grant.
136 |
137 | 1. Subject to the terms and conditions of this Public License,
138 | the Licensor hereby grants You a worldwide, royalty-free,
139 | non-sublicensable, non-exclusive, irrevocable license to
140 | exercise the Licensed Rights in the Licensed Material to:
141 |
142 | a. reproduce and Share the Licensed Material, in whole or
143 | in part; and
144 |
145 | b. produce, reproduce, and Share Adapted Material.
146 |
147 | 2. Exceptions and Limitations. For the avoidance of doubt, where
148 | Exceptions and Limitations apply to Your use, this Public
149 | License does not apply, and You do not need to comply with
150 | its terms and conditions.
151 |
152 | 3. Term. The term of this Public License is specified in Section
153 | 6(a).
154 |
155 | 4. Media and formats; technical modifications allowed. The
156 | Licensor authorizes You to exercise the Licensed Rights in
157 | all media and formats whether now known or hereafter created,
158 | and to make technical modifications necessary to do so. The
159 | Licensor waives and/or agrees not to assert any right or
160 | authority to forbid You from making technical modifications
161 | necessary to exercise the Licensed Rights, including
162 | technical modifications necessary to circumvent Effective
163 | Technological Measures. For purposes of this Public License,
164 | simply making modifications authorized by this Section 2(a)
165 | (4) never produces Adapted Material.
166 |
167 | 5. Downstream recipients.
168 |
169 | a. Offer from the Licensor -- Licensed Material. Every
170 | recipient of the Licensed Material automatically
171 | receives an offer from the Licensor to exercise the
172 | Licensed Rights under the terms and conditions of this
173 | Public License.
174 |
175 | b. No downstream restrictions. You may not offer or impose
176 | any additional or different terms or conditions on, or
177 | apply any Effective Technological Measures to, the
178 | Licensed Material if doing so restricts exercise of the
179 | Licensed Rights by any recipient of the Licensed
180 | Material.
181 |
182 | 6. No endorsement. Nothing in this Public License constitutes or
183 | may be construed as permission to assert or imply that You
184 | are, or that Your use of the Licensed Material is, connected
185 | with, or sponsored, endorsed, or granted official status by,
186 | the Licensor or others designated to receive attribution as
187 | provided in Section 3(a)(1)(A)(i).
188 |
189 | b. Other rights.
190 |
191 | 1. Moral rights, such as the right of integrity, are not
192 | licensed under this Public License, nor are publicity,
193 | privacy, and/or other similar personality rights; however, to
194 | the extent possible, the Licensor waives and/or agrees not to
195 | assert any such rights held by the Licensor to the limited
196 | extent necessary to allow You to exercise the Licensed
197 | Rights, but not otherwise.
198 |
199 | 2. Patent and trademark rights are not licensed under this
200 | Public License.
201 |
202 | 3. To the extent possible, the Licensor waives any right to
203 | collect royalties from You for the exercise of the Licensed
204 | Rights, whether directly or through a collecting society
205 | under any voluntary or waivable statutory or compulsory
206 | licensing scheme. In all other cases the Licensor expressly
207 | reserves any right to collect such royalties.
208 |
209 |
210 | Section 3 -- License Conditions.
211 |
212 | Your exercise of the Licensed Rights is expressly made subject to the
213 | following conditions.
214 |
215 | a. Attribution.
216 |
217 | 1. If You Share the Licensed Material (including in modified
218 | form), You must:
219 |
220 | a. retain the following if it is supplied by the Licensor
221 | with the Licensed Material:
222 |
223 | i. identification of the creator(s) of the Licensed
224 | Material and any others designated to receive
225 | attribution, in any reasonable manner requested by
226 | the Licensor (including by pseudonym if
227 | designated);
228 |
229 | ii. a copyright notice;
230 |
231 | iii. a notice that refers to this Public License;
232 |
233 | iv. a notice that refers to the disclaimer of
234 | warranties;
235 |
236 | v. a URI or hyperlink to the Licensed Material to the
237 | extent reasonably practicable;
238 |
239 | b. indicate if You modified the Licensed Material and
240 | retain an indication of any previous modifications; and
241 |
242 | c. indicate the Licensed Material is licensed under this
243 | Public License, and include the text of, or the URI or
244 | hyperlink to, this Public License.
245 |
246 | 2. You may satisfy the conditions in Section 3(a)(1) in any
247 | reasonable manner based on the medium, means, and context in
248 | which You Share the Licensed Material. For example, it may be
249 | reasonable to satisfy the conditions by providing a URI or
250 | hyperlink to a resource that includes the required
251 | information.
252 |
253 | 3. If requested by the Licensor, You must remove any of the
254 | information required by Section 3(a)(1)(A) to the extent
255 | reasonably practicable.
256 |
257 | 4. If You Share Adapted Material You produce, the Adapter's
258 | License You apply must not prevent recipients of the Adapted
259 | Material from complying with this Public License.
260 |
261 |
262 | Section 4 -- Sui Generis Database Rights.
263 |
264 | Where the Licensed Rights include Sui Generis Database Rights that
265 | apply to Your use of the Licensed Material:
266 |
267 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right
268 | to extract, reuse, reproduce, and Share all or a substantial
269 | portion of the contents of the database;
270 |
271 | b. if You include all or a substantial portion of the database
272 | contents in a database in which You have Sui Generis Database
273 | Rights, then the database in which You have Sui Generis Database
274 | Rights (but not its individual contents) is Adapted Material; and
275 |
276 | c. You must comply with the conditions in Section 3(a) if You Share
277 | all or a substantial portion of the contents of the database.
278 |
279 | For the avoidance of doubt, this Section 4 supplements and does not
280 | replace Your obligations under this Public License where the Licensed
281 | Rights include other Copyright and Similar Rights.
282 |
283 |
284 | Section 5 -- Disclaimer of Warranties and Limitation of Liability.
285 |
286 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
287 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
288 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
289 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
290 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
291 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
292 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
293 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
294 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
295 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
296 |
297 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
298 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
299 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
300 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
301 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
302 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
303 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
304 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
305 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
306 |
307 | c. The disclaimer of warranties and limitation of liability provided
308 | above shall be interpreted in a manner that, to the extent
309 | possible, most closely approximates an absolute disclaimer and
310 | waiver of all liability.
311 |
312 |
313 | Section 6 -- Term and Termination.
314 |
315 | a. This Public License applies for the term of the Copyright and
316 | Similar Rights licensed here. However, if You fail to comply with
317 | this Public License, then Your rights under this Public License
318 | terminate automatically.
319 |
320 | b. Where Your right to use the Licensed Material has terminated under
321 | Section 6(a), it reinstates:
322 |
323 | 1. automatically as of the date the violation is cured, provided
324 | it is cured within 30 days of Your discovery of the
325 | violation; or
326 |
327 | 2. upon express reinstatement by the Licensor.
328 |
329 | For the avoidance of doubt, this Section 6(b) does not affect any
330 | right the Licensor may have to seek remedies for Your violations
331 | of this Public License.
332 |
333 | c. For the avoidance of doubt, the Licensor may also offer the
334 | Licensed Material under separate terms or conditions or stop
335 | distributing the Licensed Material at any time; however, doing so
336 | will not terminate this Public License.
337 |
338 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
339 | License.
340 |
341 |
342 | Section 7 -- Other Terms and Conditions.
343 |
344 | a. The Licensor shall not be bound by any additional or different
345 | terms or conditions communicated by You unless expressly agreed.
346 |
347 | b. Any arrangements, understandings, or agreements regarding the
348 | Licensed Material not stated herein are separate from and
349 | independent of the terms and conditions of this Public License.
350 |
351 |
352 | Section 8 -- Interpretation.
353 |
354 | a. For the avoidance of doubt, this Public License does not, and
355 | shall not be interpreted to, reduce, limit, restrict, or impose
356 | conditions on any use of the Licensed Material that could lawfully
357 | be made without permission under this Public License.
358 |
359 | b. To the extent possible, if any provision of this Public License is
360 | deemed unenforceable, it shall be automatically reformed to the
361 | minimum extent necessary to make it enforceable. If the provision
362 | cannot be reformed, it shall be severed from this Public License
363 | without affecting the enforceability of the remaining terms and
364 | conditions.
365 |
366 | c. No term or condition of this Public License will be waived and no
367 | failure to comply consented to unless expressly agreed to by the
368 | Licensor.
369 |
370 | d. Nothing in this Public License constitutes or may be interpreted
371 | as a limitation upon, or waiver of, any privileges and immunities
372 | that apply to the Licensor or You, including from the legal
373 | processes of any jurisdiction or authority.
374 |
375 |
376 | =======================================================================
377 |
378 | Creative Commons is not a party to its public
379 | licenses. Notwithstanding, Creative Commons may elect to apply one of
380 | its public licenses to material it publishes and in those instances
381 | will be considered the “Licensor.” The text of the Creative Commons
382 | public licenses is dedicated to the public domain under the CC0 Public
383 | Domain Dedication. Except for the limited purpose of indicating that
384 | material is shared under a Creative Commons public license or as
385 | otherwise permitted by the Creative Commons policies published at
386 | creativecommons.org/policies, Creative Commons does not authorize the
387 | use of the trademark "Creative Commons" or any other trademark or logo
388 | of Creative Commons without its prior written consent including,
389 | without limitation, in connection with any unauthorized modifications
390 | to any of its public licenses or any other arrangements,
391 | understandings, or agreements concerning use of licensed material. For
392 | the avoidance of doubt, this paragraph does not form part of the
393 | public licenses.
394 |
395 | Creative Commons may be contacted at creativecommons.org.
--------------------------------------------------------------------------------
/data/multilingual_mathqa/README.md:
--------------------------------------------------------------------------------
1 |
2 | The original python test set is obtained with this [script](https://github.com/google/trax/blob/master/trax/examples/MathQA_Python_generation_notebook.ipynb).
3 |
4 |
5 | Fewshot Prompts
6 | * `fewshot_prompting`: All few-shot examples listed in the prompt
7 |
8 | Examples
9 | * `examples/{java/javascript}_samples.jsonl`: This is the output of code translation from Python.
10 | * `examples/python_samples.jsonl`: An output of code generation with few-shot prompts.
11 |
--------------------------------------------------------------------------------
/data/multilingual_mathqa/fewshot_prompting/mathqa_java_v1.java:
--------------------------------------------------------------------------------
1 | class Problem {
2 |
3 | /**
4 | * the banker ' s gain of a certain sum due 3 years hence at 10 % per annum is rs . 36 . what is the present worth ? n0 = 3.0 n1 = 10.0 n2 = 36.0
5 | */
6 | public static Object problem() {
7 | double n0 = 3.0;
8 | double n1 = 10.0;
9 | double n2 = 36.0;
10 | double t0 = n2 * 100.0;
11 | double t1 = n0 * n1;
12 | double t2 = t0 / t1;
13 | double t3 = t2 * 100.0;
14 | double answer = t3 / t1;
15 | return answer;
16 | }
17 | }
18 |
19 |
20 | class Problem {
21 |
22 | /**
23 | * sophia finished 2 / 3 of a book . she calculated that she finished 90 more pages than she has yet to read . how long is her book ? n0 = 2.0 n1 = 3.0 n2 = 90.0
24 | */
25 | public static Object problem() {
26 | double n0 = 2.0;
27 | double n1 = 3.0;
28 | double n2 = 90.0;
29 | double t0 = n0 / n1;
30 | double t1 = 1.0 - t0;
31 | double answer = n2 / t1;
32 | return answer;
33 | }
34 | }
35 |
36 |
37 | class Problem {
38 |
39 | /**
40 | * 120 is what percent of 50 ? n0 = 120.0 n1 = 50.0
41 | */
42 | public static Object problem() {
43 | double n0 = 120.0;
44 | double n1 = 50.0;
45 | double t0 = n0 / n1;
46 | double answer = t0 * 100.0;
47 | return answer;
48 | }
49 | }
50 |
51 |
52 |
53 | class Problem {
54 |
55 | /**
56 | * there are 10 girls and 20 boys in a classroom . what is the ratio of girls to boys ? n0 = 10.0 n1 = 20.0
57 | */
58 | public static Object problem() {
59 | double n0 = 10.0;
60 | double n1 = 20.0;
61 |
62 | double answer = n0 / n1;
63 | return answer;
64 | }
65 | }
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/data/multilingual_mathqa/fewshot_prompting/mathqa_javascript_v1.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * the banker ' s gain of a certain sum due 3 years hence at 10 % per annum is rs . 36 . what is the present worth ? n0 = 3.0 n1 = 10.0 n2 = 36.0
4 | */
5 | function problem() {
6 | var n0 = 3.0;
7 | var n1 = 10.0;
8 | var n2 = 36.0;
9 | var t0 = n2 * 100.0;
10 | var t1 = n0 * n1;
11 | var t2 = t0 / t1;
12 | var t3 = t2 * 100.0;
13 | var answer = t3 / t1;
14 | return answer
15 | }
16 |
17 | /**
18 | * sophia finished 2 / 3 of a book . she calculated that she finished 90 more pages than she has yet to read . how long is her book ? n0 = 2.0 n1 = 3.0 n2 = 90.0
19 | */
20 | function problem() {
21 | var n0 = 2.0;
22 | var n1 = 3.0;
23 | var n2 = 90.0;
24 | var t0 = n0 / n1;
25 | var t1 = 1.0 - t0;
26 | var answer = n2 / t1;
27 | return answer;
28 | }
29 |
30 | /**
31 | * 120 is what percent of 50 ? n0 = 120.0 n1 = 50.0
32 | */
33 | function problem() {
34 | var n0 = 120.0;
35 | var n1 = 50.0;
36 | var t0 = n0 / n1;
37 | var answer = t0 * 100.0;
38 | return answer;
39 | }
40 |
41 | /**
42 | * there are 10 girls and 20 boys in a classroom . what is the ratio of girls to boys ? n0 = 10.0 n1 = 20.0
43 | */
44 | function problem() {
45 | var n0 = 10.0;
46 | var n1 = 20.0;
47 | var answer = n0 / n1;
48 | return answer;
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/data/multilingual_mathqa/fewshot_prompting/mathqa_python_v1.py:
--------------------------------------------------------------------------------
1 | def problem():
2 | """
3 | the banker ' s gain of a certain sum due 3 years hence at 10 % per annum is rs . 36 . what is the present worth ? n0 = 3.0 n1 = 10.0 n2 = 36.0
4 | """
5 | n0 = 3.0
6 | n1 = 10.0
7 | n2 = 36.0
8 | t0 = n2 * 100.0
9 | t1 = n0 * n1
10 | t2 = t0 / t1
11 | t3 = t2 * 100.0
12 | answer = t3 / t1
13 | return answer
14 |
15 |
16 | def problem():
17 | """
18 | sophia finished 2 / 3 of a book . she calculated that she finished 90 more pages than she has yet to read . how long is her book ? n0 = 2.0 n1 = 3.0 n2 = 90.0
19 | """
20 | n0 = 2.0
21 | n1 = 3.0
22 | n2 = 90.0
23 | t0 = n0 / n1
24 | t1 = 1.0 - t0
25 | answer = n2 / t1
26 | return answer
27 |
28 |
29 | def problem():
30 | """
31 | 120 is what percent of 50 ? n0 = 120.0 n1 = 50.0
32 | """
33 | n0 = 120.0
34 | n1 = 50.0
35 | t0 = n0 / n1
36 | answer = t0 * 100.0
37 | return answer
38 |
39 |
40 | def problem():
41 | """
42 | there are 10 girls and 20 boys in a classroom . what is the ratio of girls to boys ? n0 = 10.0 n1 = 20.0
43 | """
44 | n0 = 10.0
45 | n1 = 20.0
46 | answer = n0 / n1
47 | return answer
48 |
--------------------------------------------------------------------------------
/data/multilingual_mathqa/metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "python": "mathqa-test-python_v1.jsonl",
3 | "java": "mathqa-test-java_v1.jsonl",
4 | "javascript": "mathqa-test-javascript_v1.jsonl"
5 | }
6 |
--------------------------------------------------------------------------------
/graphics/mbxp_java_conversion.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amazon-science/mxeval/e09974f990eeaf0c0e8f2b5eaff4be66effb2c86/graphics/mbxp_java_conversion.png
--------------------------------------------------------------------------------
/graphics/paper_summary.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amazon-science/mxeval/e09974f990eeaf0c0e8f2b5eaff4be66effb2c86/graphics/paper_summary.png
--------------------------------------------------------------------------------
/language_setup/amazon_linux_ami.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/bash
2 |
3 | printf "%100s" " " | tr ' ' '-'
4 | echo ""
5 | echo "setting up C++ "
6 | printf "%100s" " " | tr ' ' '-'
7 | echo ""
8 | sudo yum install -y gcc-c++
9 |
10 | printf "%100s" " " | tr ' ' '-'
11 | echo ""
12 | echo "setting up Ruby "
13 | printf "%100s" " " | tr ' ' '-'
14 | echo ""
15 | sudo amazon-linux-extras install -y ruby3.0
16 |
17 | printf "%100s" " " | tr ' ' '-'
18 | echo ""
19 | echo "setting up php "
20 | printf "%100s" " " | tr ' ' '-'
21 | echo ""
22 | # ref https://techviewleo.com/install-php-8-on-amazon-linux/
23 | sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
24 | sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
25 |
26 | sudo yum makecache
27 |
28 | sudo yum -y install yum-utils
29 | sudo yum-config-manager --disable 'remi-php*'
30 | sudo amazon-linux-extras enable php8.0
31 | sudo yum clean metadata
32 | sudo yum install -y php-{pear,cgi,pdo,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip}
33 |
34 | printf "%100s" " " | tr ' ' '-'
35 | echo ""
36 | echo "setting up Java "
37 | printf "%100s" " " | tr ' ' '-'
38 | echo ""
39 | # ref https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/amazon-linux-install.html
40 | sudo amazon-linux-extras enable corretto8
41 | sudo yum install -y java-1.8.0-amazon-corretto-devel
42 |
43 | printf "%100s" " " | tr ' ' '-'
44 | echo ""
45 | echo "setting up JavaScript "
46 | printf "%100s" " " | tr ' ' '-'
47 | echo ""
48 | curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
49 | . ~/.nvm/nvm.sh
50 | nvm install 16.10.0
51 | node -e "console.log('Running Node.js ' + process.version)"
52 | npm i -g npm
53 | npm install -g lodash
54 | npm i --save lodash
55 |
56 |
57 | printf "%100s" " " | tr ' ' '-'
58 | echo ""
59 | echo "setting up TypeScript "
60 | printf "%100s" " " | tr ' ' '-'
61 | echo ""
62 | npm install -g typescript
63 |
64 | cd /usr/local
65 | printf "%100s" " " | tr ' ' '-'
66 | echo ""
67 | echo "setting up Go "
68 | printf "%100s" " " | tr ' ' '-'
69 | echo ""
70 | sudo wget https://go.dev/dl/go1.19.1.linux-amd64.tar.gz && sudo tar -xzvf go1.19.1.linux-amd64.tar.gz && sudo rm go1.19.1.linux-amd64.tar.gz
71 | printf "%100s" " " | tr ' ' '-'
72 | echo ""
73 | echo "setting up Swift "
74 | printf "%100s" " " | tr ' ' '-'
75 | echo ""
76 | sudo wget https://download.swift.org/swift-5.7-release/amazonlinux2/swift-5.7-RELEASE/swift-5.7-RELEASE-amazonlinux2.tar.gz && sudo tar -xzvf swift-5.7-RELEASE-amazonlinux2.tar.gz && sudo rm swift-5.7-RELEASE-amazonlinux2.tar.gz
77 |
78 | cd ~
79 | printf "%100s" " " | tr ' ' '-'
80 | echo ""
81 | echo "setting up Scala "
82 | printf "%100s" " " | tr ' ' '-'
83 | echo ""
84 | wget http://downloads.lightbend.com/scala/2.11.8/scala-2.11.8.rpm
85 | sudo yum -y install scala-2.11.8.rpm
86 |
87 | printf "%100s" " " | tr ' ' '-'
88 | echo ""
89 | echo "setting up C# "
90 | printf "%100s" " " | tr ' ' '-'
91 | echo ""
92 | sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
93 | sudo yum install -y dotnet-sdk-6.0
94 |
95 | printf "%100s" " " | tr ' ' '-'
96 | echo ""
97 | echo "setting up Perl "
98 | printf "%100s" " " | tr ' ' '-'
99 | echo ""
100 | sudo yum install -y perl-CPAN
101 | perl -MCPAN -e 'install Data::Compare'
102 |
103 | printf "%100s" " " | tr ' ' '-'
104 | echo ""
105 | echo "setting up Kotlin "
106 | printf "%100s" " " | tr ' ' '-'
107 | echo ""
108 | curl -s https://get.sdkman.io | bash
109 | export SDKMAN_DIR="$HOME/.sdkman"
110 | [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
111 | sdk install kotlin
112 |
113 | # writing out updated PATH to ~/.bashrc
114 | echo 'export PATH="${PATH}:/usr/local/go/bin:/usr/local/swift-5.7-RELEASE-amazonlinux2/usr/bin"' >> ~/.bashrc
115 |
116 | printf "%100s" " " | tr ' ' '-'
117 | echo ""
118 | echo 'Installation complete. Please start a new terminal session for changes to take place.'
119 | printf "%100s" " " | tr ' ' '-'
120 | echo ""
121 |
--------------------------------------------------------------------------------
/language_setup/ubuntu.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/bash
2 |
3 | printf "%100s" " " | tr ' ' '-'
4 | echo ""
5 | echo "setting up Ruby "
6 | printf "%100s" " " | tr ' ' '-'
7 | echo ""
8 | sudo apt update
9 | sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev
10 | curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
11 | echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
12 | echo 'eval "$(rbenv init -)"' >> ~/.bashrc
13 | source ~/.bashrc
14 | rbenv install 3.0.0
15 | rbenv global 3.0.0
16 |
17 |
18 | printf "%100s" " " | tr ' ' '-'
19 | echo ""
20 | echo "setting up php "
21 | printf "%100s" " " | tr ' ' '-'
22 | echo ""
23 | sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https
24 | sudo add-apt-repository ppa:ondrej/php
25 | sudo apt update
26 | sudo apt install php8.0
27 | sudo apt install -y php-{pear,cgi,pdo,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip}
28 |
29 |
30 | printf "%100s" " " | tr ' ' '-'
31 | echo ""
32 | echo "setting up Java "
33 | printf "%100s" " " | tr ' ' '-'
34 | echo ""
35 | sudo apt-get install openjdk-8-jdk
36 |
37 |
38 | printf "%100s" " " | tr ' ' '-'
39 | echo ""
40 | echo "setting up JavaScript "
41 | printf "%100s" " " | tr ' ' '-'
42 | echo ""
43 | sudo apt install curl
44 | curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
45 | source ~/.bashrc
46 | sudo apt install npm
47 | nvm install 16.10.0
48 | node -e "console.log('Running Node.js ' + process.version)"
49 | npm i -g npm
50 | npm install -g lodash
51 | npm i --save lodash
52 |
53 |
54 | printf "%100s" " " | tr ' ' '-'
55 | echo ""
56 | echo "setting up TypeScript "
57 | printf "%100s" " " | tr ' ' '-'
58 | echo ""
59 | sudo npm install -g typescript
60 |
61 | cd /usr/local
62 | printf "%100s" " " | tr ' ' '-'
63 | echo ""
64 | echo "setting up Go "
65 | printf "%100s" " " | tr ' ' '-'
66 | echo ""
67 | # https://go.dev/doc/install
68 | sudo wget https://go.dev/dl/go1.19.1.linux-amd64.tar.gz && sudo tar -xzvf go1.19.1.linux-amd64.tar.gz && sudo rm go1.19.1.linux-amd64.tar.gz
69 | printf "%100s" " " | tr ' ' '-'
70 | echo ""
71 | echo "setting up Swift "
72 | printf "%100s" " " | tr ' ' '-'
73 | echo ""
74 | swift_release="swift-5.7-RELEASE-ubuntu20.04.tar.gz"
75 | sudo wget "https://download.swift.org/swift-5.7-release/ubuntu2004/swift-5.7-RELEASE/$swift_release" && sudo tar -xzvf $swift_release && sudo rm $swift_release
76 |
77 | cd ~
78 | printf "%100s" " " | tr ' ' '-'
79 | echo ""
80 | echo "setting up Scala "
81 | printf "%100s" " " | tr ' ' '-'
82 | echo ""
83 | sudo apt-get install scala
84 |
85 |
86 | printf "%100s" " " | tr ' ' '-'
87 | echo ""
88 | echo "setting up C# "
89 | printf "%100s" " " | tr ' ' '-'
90 | echo ""
91 | sudo apt-get update && \
92 | sudo apt-get install -y dotnet6
93 |
94 | printf "%100s" " " | tr ' ' '-'
95 | echo ""
96 | echo "setting up Perl "
97 | printf "%100s" " " | tr ' ' '-'
98 | echo ""
99 | perl -MCPAN -e 'install Data::Compare'
100 |
101 | printf "%100s" " " | tr ' ' '-'
102 | echo ""
103 | echo "setting up Kotlin "
104 | printf "%100s" " " | tr ' ' '-'
105 | echo ""
106 | sudo apt install zip
107 | sudo apt install unzip
108 | curl -s https://get.sdkman.io | bash
109 | export SDKMAN_DIR="$HOME/.sdkman"
110 | [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
111 | sdk install kotlin
112 |
113 |
114 | # writing out updated PATH to ~/.bashrc
115 | echo 'PATH="${PATH}:/usr/local/swift-5.7-RELEASE-ubuntu20.04/usr/bin:/usr/local/go/bin"' >> ~/.bashrc
116 |
117 | printf "%100s" " " | tr ' ' '-'
118 | echo ""
119 | echo 'Installation complete. Please start a new terminal session for changes to take place.'
120 | printf "%100s" " " | tr ' ' '-'
121 | echo ""
122 |
--------------------------------------------------------------------------------
/mxeval/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amazon-science/mxeval/e09974f990eeaf0c0e8f2b5eaff4be66effb2c86/mxeval/__init__.py
--------------------------------------------------------------------------------
/mxeval/data.py:
--------------------------------------------------------------------------------
1 | from typing import Iterable, Dict
2 | import gzip
3 | import json
4 | import os
5 |
6 |
7 | ROOT = os.path.dirname(os.path.abspath(__file__))
8 | MULTILINGUAL_HUMANEVAL_METADATA = os.path.join(ROOT, "..", "data", "multilingual_humaneval", "metadata.json")
9 | with open(MULTILINGUAL_HUMANEVAL_METADATA, "r", encoding="utf-8") as fr:
10 | MULTILINGUAL_HUMANEVAL_METADATA = json.load(fr)
11 | HUMAN_EVAL_PYTHON = os.path.join(ROOT, "..", "data", "multilingual_humaneval", MULTILINGUAL_HUMANEVAL_METADATA["python"])
12 | HUMAN_EVAL = HUMAN_EVAL_PYTHON
13 |
14 |
15 | def read_problems(evalset_file: str = HUMAN_EVAL_PYTHON) -> Dict[str, Dict]:
16 | return {task["task_id"]: task for task in stream_jsonl(evalset_file)}
17 |
18 |
19 | def stream_jsonl(filename: str) -> Iterable[Dict]:
20 | """
21 | Parses each jsonl line and yields it as a dictionary
22 | """
23 | if filename.endswith(".gz"):
24 | with open(filename, "rb") as gzfp:
25 | with gzip.open(gzfp, 'rt') as fp:
26 | for line in fp:
27 | if any(not x.isspace() for x in line):
28 | yield json.loads(line)
29 | else:
30 | with open(filename, "r") as fp:
31 | for line in fp:
32 | if any(not x.isspace() for x in line):
33 | yield json.loads(line)
34 |
35 |
36 | def write_jsonl(filename: str, data: Iterable[Dict], append: bool = False):
37 | """
38 | Writes an iterable of dictionaries to jsonl
39 | """
40 | if append:
41 | mode = 'ab'
42 | else:
43 | mode = 'wb'
44 | filename = os.path.expanduser(filename)
45 | if filename.endswith(".gz"):
46 | with open(filename, mode) as fp:
47 | with gzip.GzipFile(fileobj=fp, mode='wb') as gzfp:
48 | for x in data:
49 | gzfp.write((json.dumps(x) + "\n").encode('utf-8'))
50 | else:
51 | with open(filename, mode) as fp:
52 | for x in data:
53 | fp.write((json.dumps(x) + "\n").encode('utf-8'))
54 |
55 |
56 | def get_metadata(dataset, metadata_type="problem"):
57 | assert metadata_type in ["problem", "example"]
58 | assert dataset in ["mbxp", "multi-humaneval", "mathqa-x"], f"Unsupported dataset {dataset}"
59 | dataset_dirmap = {"mbxp": "mbxp",
60 | "multi-humaneval": "multilingual_humaneval",
61 | "mathqa-x": "multilingual_mathqa"}
62 | typemap = {"problem": "metadata.json",
63 | "example": "metadata_examples.json"}
64 | datadir = os.path.join(ROOT, "..", "data", dataset_dirmap[dataset])
65 | path = os.path.join(datadir, typemap[metadata_type])
66 | with open(path, "r") as f:
67 | metadata = json.load(f)
68 | return metadata, datadir
69 |
70 |
71 | def get_supported_langs(dataset):
72 | metadata, _ = get_metadata(dataset, metadata_type="problem")
73 | return list(metadata.keys())
74 |
75 |
76 | def get_data(dataset="mbxp", language="python"):
77 | metadata, datadir = get_metadata(dataset, metadata_type="problem")
78 | if language.lower() not in metadata:
79 | raise ValueError(f"Language {language} not found in metadata file")
80 | datafile = metadata[language.lower()]
81 | print(f"Loading {dataset} | language = {language}")
82 | return read_problems(os.path.join(datadir, datafile))
83 |
84 |
85 | # due to similar format, examples from mbxp are sufficient to be used
86 | # for few-shot prompting in multi-humaneval
87 | def get_examples(dataset="mbxp", language="python", num_examples=None):
88 | assert dataset in ["mbxp"], f"No fewshot examples in dataset {dataset}"
89 | metadata, datadir = get_metadata(dataset=dataset, metadata_type="example")
90 | if language.lower() not in metadata:
91 | raise ValueError(f"Language {language} not found in metadata file")
92 | datafile = metadata[language.lower()]
93 | print(f"Loading examples from {dataset} | language = {language}")
94 | # use streams
95 | if num_examples is None:
96 | # return the entire stream
97 | return stream_jsonl(os.path.join(datadir, datafile))
98 | else:
99 | problems = get_data(dataset=dataset, language=language)
100 | stream = get_examples(dataset=dataset, language=language)
101 | examples = []
102 | for idx, example in enumerate(stream):
103 | if idx == num_examples:
104 | break
105 | task_id = example["task_id"]
106 | prompt = problems[task_id]["prompt"]
107 | example["prompt"] = prompt
108 | examples.append(example)
109 | return examples
110 |
--------------------------------------------------------------------------------
/mxeval/evaluate_functional_correctness.py:
--------------------------------------------------------------------------------
1 | # Original Copyright 2021 OpenAI under MIT License.
2 | # Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 |
4 | import sys
5 | import os
6 |
7 | import fire
8 | from mxeval.data import HUMAN_EVAL
9 | from mxeval.evaluation import evaluate_functional_correctness
10 |
11 |
12 | def entry_point(
13 | sample_file: str,
14 | problem_file: str = HUMAN_EVAL,
15 | k: tuple = (1, 10, 100, 1000), # from command line, use '1,10,100' for example
16 | n_workers: int = os.cpu_count() - 1,
17 | timeout: float = 15.0,
18 | ):
19 | """
20 | Evaluates the functional correctness of generated samples, and writes
21 | results to f"{sample_file}_results.jsonl"
22 | """
23 | print(f"\n\nEvaluating {sample_file}")
24 | k = list(map(int, k))
25 | results = evaluate_functional_correctness(
26 | sample_file, k, n_workers, timeout, problem_file
27 | )
28 | with open(sample_file + "_passatk.json", "w") as f:
29 | f.write(str(results))
30 | print(results)
31 |
32 |
33 | def main():
34 | fire.Fire(entry_point)
35 |
36 |
37 | sys.exit(main())
38 |
--------------------------------------------------------------------------------
/mxeval/evaluation.py:
--------------------------------------------------------------------------------
1 | # Original Copyright 2021 OpenAI under MIT License.
2 | # Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 |
4 | from io import UnsupportedOperation
5 | import itertools
6 | import os
7 | import time
8 | from collections import Counter, defaultdict
9 | from concurrent.futures import ThreadPoolExecutor, as_completed
10 | from typing import Dict, Iterable, List, Union
11 |
12 | import numpy as np
13 | import tqdm
14 | from mxeval.data import HUMAN_EVAL, read_problems, stream_jsonl, write_jsonl
15 |
16 | # Amazon modification
17 | # import check correctness for all languages
18 | from mxeval.execution import (
19 | check_correctness,
20 | check_correctness_cpp,
21 | check_correctness_csharp,
22 | check_correctness_go,
23 | check_correctness_java,
24 | check_correctness_javascript,
25 | check_correctness_kotlin,
26 | check_correctness_perl,
27 | check_correctness_php,
28 | check_correctness_ruby,
29 | check_correctness_scala,
30 | check_correctness_swift,
31 | check_correctness_typescript,
32 | )
33 |
34 | check_correctness_function_map = {
35 | "python": check_correctness,
36 | "java": check_correctness_java,
37 | "javascript": check_correctness_javascript,
38 | "typescript": check_correctness_typescript,
39 | "kotlin": check_correctness_kotlin,
40 | "ruby": check_correctness_ruby,
41 | "php": check_correctness_php,
42 | "cpp": check_correctness_cpp,
43 | "csharp": check_correctness_csharp,
44 | "go": check_correctness_go,
45 | "perl": check_correctness_perl,
46 | "scala": check_correctness_scala,
47 | "swift": check_correctness_swift,
48 | }
49 |
50 | def estimate_pass_at_k(
51 | num_samples: Union[int, List[int], np.ndarray],
52 | num_correct: Union[List[int], np.ndarray],
53 | k: int,
54 | ) -> np.ndarray:
55 | """
56 | Estimates pass@k of each problem and returns them in an array.
57 | """
58 |
59 | def estimator(n: int, c: int, k: int) -> float:
60 | """
61 | Calculates 1 - comb(n - c, k) / comb(n, k).
62 | """
63 | if n - c < k:
64 | return 1.0
65 | return 1.0 - np.prod(1.0 - k / np.arange(n - c + 1, n + 1))
66 |
67 | if isinstance(num_samples, int):
68 | num_samples_it = itertools.repeat(num_samples, len(num_correct))
69 | else:
70 | assert len(num_samples) == len(num_correct)
71 | num_samples_it = iter(num_samples)
72 |
73 | return np.array(
74 | [estimator(int(n), int(c), k) for n, c in zip(num_samples_it, num_correct)]
75 | )
76 |
77 | def get_execute_function(lang):
78 | lang = lang.lower()
79 | assert lang in check_correctness_function_map, f"Language {lang} is not among the supported languages: {check_correctness_function_map.keys()}"
80 | return check_correctness_function_map[lang]
81 |
82 | def evaluate_functional_correctness(
83 | sample_file: str,
84 | k: List[int] = [1, 10, 100],
85 | n_workers: int = os.cpu_count() - 1,
86 | timeout: float = 10.0,
87 | problem_file: str = HUMAN_EVAL,
88 | ):
89 | """
90 | Evaluates the functional correctness of generated samples, and writes
91 | results to f"{sample_file}_results.jsonl"
92 | """
93 |
94 | if type(problem_file) is not dict:
95 | problems = read_problems(problem_file)
96 | else:
97 | print("Skip reading problems -- using problem_file (dict) as problems")
98 | problems = problem_file
99 |
100 | # see execution.py for details
101 | # Check the generated samples against test suites.
102 | check_correctness_function_map = {
103 | "python": check_correctness,
104 | "java": check_correctness_java,
105 | "javascript": check_correctness_javascript,
106 | "typescript": check_correctness_typescript,
107 | "kotlin": check_correctness_kotlin,
108 | "ruby": check_correctness_ruby,
109 | "php": check_correctness_php,
110 | "cpp": check_correctness_cpp,
111 | "csharp": check_correctness_csharp,
112 | "go": check_correctness_go,
113 | "perl": check_correctness_perl,
114 | "scala": check_correctness_scala,
115 | "swift": check_correctness_swift,
116 | }
117 |
118 | seed = int(time.time() * 1000000) % 1000000
119 | np.random.seed(seed=seed) # microsecond
120 |
121 | with ThreadPoolExecutor(max_workers=n_workers) as executor:
122 | futures = []
123 | completion_id = Counter()
124 | n_samples = 0
125 | results = defaultdict(list)
126 |
127 | print("Reading samples...")
128 | for sample in tqdm.tqdm(stream_jsonl(sample_file)):
129 | task_id = sample["task_id"]
130 | completion = sample["completion"]
131 | args = (problems[task_id], completion, timeout, completion_id[task_id])
132 | language = sample["language"]
133 | check_correctness_function = check_correctness_function_map[language]
134 | future = executor.submit(check_correctness_function, *args)
135 | futures.append(future)
136 | completion_id[task_id] += 1
137 | n_samples += 1
138 |
139 | assert len(completion_id) == len(problems), "Some problems are not attempted."
140 |
141 | print("Running test suites...")
142 | for future in tqdm.tqdm(as_completed(futures), total=len(futures)):
143 | result = future.result() # this is the execution stage
144 | results[result["task_id"]].append((result["completion_id"], result))
145 |
146 | # common code for all languages
147 | # Calculate pass@k.
148 | total, correct = [], []
149 | for result in results.values():
150 | result.sort()
151 | passed = [r[1]["passed"] for r in result]
152 | total.append(len(passed))
153 | correct.append(sum(passed))
154 | total = np.array(total)
155 | correct = np.array(correct)
156 |
157 | ks = k
158 | pass_at_k = {
159 | f"pass@{k}": estimate_pass_at_k(total, correct, k).mean()
160 | for k in ks
161 | if (total >= k).all()
162 | }
163 |
164 | # Finally, save the results in one file:
165 | def combine_results():
166 | for sample in stream_jsonl(sample_file):
167 | task_id = sample["task_id"]
168 | result = results[task_id].pop(0)
169 | sample["result"] = result[1]["result"]
170 | sample["passed"] = result[1]["passed"]
171 | sample["time_elapsed"] = result[1]["time_elapsed"]
172 | yield sample
173 |
174 | out_file = sample_file + "_results.jsonl"
175 | print(f"Writing results to {out_file}...")
176 | write_jsonl(out_file, tqdm.tqdm(combine_results(), total=n_samples))
177 |
178 | return pass_at_k
179 |
--------------------------------------------------------------------------------
/mxeval/execution.py:
--------------------------------------------------------------------------------
1 | # Original Copyright 2021 OpenAI under MIT License.
2 | # Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | # check_correctness_* functions are AWS additions
4 |
5 | import contextlib
6 | import faulthandler
7 | import io
8 | import multiprocessing
9 | import os
10 | import platform
11 | import random
12 | import shutil
13 | import signal
14 | import string
15 | import subprocess
16 | import tempfile
17 | import time
18 | import errno
19 | from typing import Dict, Optional
20 | import threading
21 | lock = threading.Lock()
22 |
23 |
24 | def check_correctness_java(
25 | problem: Dict,
26 | completion: str,
27 | timeout: float,
28 | completion_id: Optional[int] = None,
29 | verbose=False,
30 | language="java",
31 | compile_timeout: float = 100,
32 | ):
33 | """
34 | Run all evaluation under java_exec_eval + randomized directory to avoid collision.
35 | Using subprocess with concurrent.futures for multi-thread evaluation.
36 | Make sure to clean up resources even if the test cases fail.
37 | """
38 |
39 | current_dir = os.path.dirname(os.path.realpath(__file__))
40 | entire_string = problem["prompt"] + completion + problem["test"]
41 | base_path = setup_base_path(current_dir, f"{language}_exec_eval", "")
42 | try:
43 | os.makedirs(base_path, exist_ok=False)
44 | except OSError as e:
45 | if e.errno != errno.EEXIST:
46 | raise
47 | path = os.path.join(base_path, f"main.{language}")
48 |
49 | with open(path, "w") as f:
50 | f.write(entire_string)
51 |
52 | try:
53 | exec_result_compile = subprocess.run(
54 | [f"javac", path],
55 | timeout=int(compile_timeout),
56 | stdout=subprocess.PIPE,
57 | stderr=subprocess.PIPE,
58 | text=True,
59 | )
60 | compiled = exec_result_compile.returncode == 0
61 | if verbose:
62 | print("exec_result_compile", exec_result_compile)
63 | start = time.time()
64 | exec_result_run = subprocess.run(
65 | [f"java", "-cp", base_path, "Main"],
66 | timeout=int(timeout),
67 | stdout=subprocess.PIPE,
68 | stderr=subprocess.PIPE,
69 | text=True,
70 | )
71 | elapsed = 1000.0 * (time.time() - start)
72 | if verbose:
73 | print("exec result run", exec_result_run)
74 | passed = exec_result_compile.returncode == 0 and exec_result_run.returncode == 0
75 | if exec_result_compile.returncode > 0:
76 | message = exec_result_compile.stderr
77 | else:
78 | message = exec_result_run.stderr
79 |
80 | except Exception as e:
81 | passed = False
82 | message = str(e)
83 | elapsed = None
84 | compiled = False
85 |
86 | try:
87 | shutil.rmtree(base_path)
88 | except Exception as e:
89 | if verbose:
90 | print(f"Error cleaning up directory {base_path}: {e}")
91 |
92 | return dict(
93 | task_id=problem["task_id"],
94 | passed=passed,
95 | result=message,
96 | completion_id=completion_id,
97 | time_elapsed=elapsed,
98 | compiled=compiled,
99 | )
100 |
101 |
102 | def check_correctness_scala(
103 | problem: Dict,
104 | completion: str,
105 | timeout: float,
106 | completion_id: Optional[int] = None,
107 | verbose=False,
108 | language="scala",
109 | compile_timeout: float = 100,
110 | ):
111 |
112 | current_dir = os.path.dirname(os.path.realpath(__file__))
113 | entire_string = problem["prompt"] + completion + problem["test"]
114 | base_path = setup_base_path(current_dir, f"{language}_exec_eval", "")
115 | try:
116 | os.makedirs(base_path, exist_ok=False)
117 | except OSError as e:
118 | if e.errno != errno.EEXIST:
119 | raise
120 | path = os.path.join(base_path, f"main.{language}")
121 |
122 | with open(path, "w") as f:
123 | f.write(entire_string)
124 |
125 | try:
126 | exec_result_compile = subprocess.run(
127 | [f"scalac", path, "-d", base_path],
128 | timeout=int(compile_timeout),
129 | stdout=subprocess.PIPE,
130 | stderr=subprocess.PIPE,
131 | text=True,
132 | )
133 | compiled = exec_result_compile.returncode == 0
134 | if verbose:
135 | print("exec_result_compile", exec_result_compile)
136 | start = time.time()
137 | exec_result_run = subprocess.run(
138 | [f"scala", "-cp", base_path, "Main"],
139 | timeout=int(timeout),
140 | stdout=subprocess.PIPE,
141 | stderr=subprocess.PIPE,
142 | text=True,
143 | )
144 | elapsed = 1000.0 * (time.time() - start)
145 | if verbose:
146 | print("exec result run", exec_result_run)
147 | passed = exec_result_compile.returncode == 0 and exec_result_run.returncode == 0
148 | if exec_result_compile.returncode > 0:
149 | message = exec_result_compile.stderr
150 | else:
151 | message = exec_result_run.stderr
152 |
153 | except Exception as e:
154 | passed = False
155 | message = str(e)
156 | elapsed = None
157 | compiled = False
158 |
159 | try:
160 | shutil.rmtree(base_path)
161 | except Exception as e:
162 | if verbose:
163 | print(f"Error cleaning up directory {base_path}: {e}")
164 |
165 | return dict(
166 | task_id=problem["task_id"],
167 | passed=passed,
168 | result=message,
169 | completion_id=completion_id,
170 | time_elapsed=elapsed,
171 | compiled=compiled,
172 | )
173 |
174 |
175 | def check_correctness_perl(
176 | problem: Dict,
177 | completion: str,
178 | timeout: float,
179 | completion_id: Optional[int] = None,
180 | verbose=False,
181 | ):
182 | return check_correctness_helper(
183 | problem=problem,
184 | completion=completion,
185 | timeout=timeout,
186 | completion_id=completion_id,
187 | verbose=verbose,
188 | language="perl",
189 | extension=".pl",
190 | subprocess_command_lambda=lambda x: ["perl", f"{x}.pl"],
191 | )
192 |
193 |
194 | def check_correctness_swift(
195 | problem: Dict,
196 | completion: str,
197 | timeout: float,
198 | completion_id: Optional[int] = None,
199 | verbose=False,
200 | ):
201 | return check_correctness_helper(
202 | problem=problem,
203 | completion=completion,
204 | timeout=timeout,
205 | completion_id=completion_id,
206 | verbose=verbose,
207 | language="swift",
208 | extension=".swift",
209 | subprocess_command_lambda=lambda x: ["swift", f"{x}.swift"],
210 | )
211 |
212 |
213 | def check_correctness_javascript(
214 | problem: Dict,
215 | completion: str,
216 | timeout: float,
217 | completion_id: Optional[int] = None,
218 | verbose=False,
219 | ):
220 | return check_correctness_helper(
221 | problem=problem,
222 | completion=completion,
223 | timeout=timeout,
224 | completion_id=completion_id,
225 | verbose=verbose,
226 | language="javascript",
227 | extension=".js",
228 | subprocess_command_lambda=lambda x: ["node", f"{x}.js"],
229 | )
230 |
231 |
232 | def check_correctness_typescript(
233 | problem: Dict,
234 | completion: str,
235 | timeout: float,
236 | completion_id: Optional[int] = None,
237 | verbose=False,
238 | ):
239 | return check_correctness_helper(
240 | problem=problem,
241 | completion=completion,
242 | timeout=timeout,
243 | completion_id=completion_id,
244 | verbose=verbose,
245 | language="typescript",
246 | extension=".ts",
247 | compile_command_lambda=lambda x: f"npx tsc {x} --target es5 --lib es2016".split(),
248 | subprocess_command_lambda=lambda x: ["node", f"{x}.js"],
249 | )
250 |
251 |
252 | def check_correctness_ruby(
253 | problem: Dict,
254 | completion: str,
255 | timeout: float,
256 | completion_id: Optional[int] = None,
257 | verbose=False,
258 | ):
259 | return check_correctness_helper(
260 | problem=problem,
261 | completion=completion,
262 | timeout=timeout,
263 | completion_id=completion_id,
264 | verbose=verbose,
265 | language="ruby",
266 | extension=".rb",
267 | subprocess_command_lambda=lambda x: ["ruby", f"{x}.rb"],
268 | )
269 |
270 |
271 | def check_correctness_kotlin(
272 | problem: Dict,
273 | completion: str,
274 | timeout: float,
275 | completion_id: Optional[int] = None,
276 | verbose=False,
277 | ):
278 | return check_correctness_helper(
279 | problem=problem,
280 | completion=completion,
281 | timeout=timeout,
282 | completion_id=completion_id,
283 | verbose=verbose,
284 | language="kotlin",
285 | extension=".kt",
286 | compile_command_lambda=lambda x: [
287 | "kotlinc",
288 | f"{x}.kt",
289 | "-include-runtime",
290 | "-d",
291 | f"{x}.jar",
292 | ],
293 | compile_timeout=100, # needs longer than 20 sec
294 | subprocess_command_lambda=lambda x: ["java", "-jar", f"{x}.jar"],
295 | extra_cleanup=lambda x: f"{x}.jar",
296 | )
297 |
298 |
299 | def check_correctness_php(
300 | problem: Dict,
301 | completion: str,
302 | timeout: float,
303 | completion_id: Optional[int] = None,
304 | verbose=False,
305 | ):
306 | return check_correctness_helper(
307 | problem=problem,
308 | completion=completion,
309 | timeout=timeout,
310 | completion_id=completion_id,
311 | verbose=verbose,
312 | language="php",
313 | extension=".php",
314 | subprocess_command_lambda=lambda x: ["php", f"{x}.php"],
315 | )
316 |
317 |
318 | def check_correctness_go(
319 | problem: Dict,
320 | completion: str,
321 | timeout: float,
322 | completion_id: Optional[int] = None,
323 | verbose=False,
324 | ):
325 | return check_correctness_helper(
326 | problem=problem,
327 | completion=completion,
328 | timeout=timeout,
329 | completion_id=completion_id,
330 | verbose=verbose,
331 | language="go",
332 | extension=".go",
333 | subprocess_command_lambda=lambda x: ["go", "run", f"{x}.go"],
334 | )
335 |
336 |
337 | def check_correctness_csharp(
338 | problem: Dict,
339 | completion: str,
340 | timeout: float,
341 | completion_id: Optional[int] = None,
342 | verbose=False,
343 | compilation_timeout: float = 100,
344 | ):
345 | current_dir = os.path.dirname(os.path.realpath(__file__))
346 | program = problem["prompt"] + completion + problem["test"]
347 | # template c# project has all necessary DLLs
348 | template_cs_proj_zip = os.path.join(current_dir, "../resources/eval_csproj.zip")
349 | cs_eval_dir = setup_base_path(current_dir, "cs_eval", "")
350 |
351 | # extract zip into cs_eval_dir
352 | subprocess.check_call(
353 | f"unzip -q {template_cs_proj_zip} -d {cs_eval_dir}".split(), timeout=int(compilation_timeout)
354 | )
355 |
356 | passed, message = None, None
357 | compiled = False
358 |
359 | try:
360 | cs_project_path = os.path.join(cs_eval_dir, "eval_csproj")
361 | # entrypoint
362 | cs_program_path = os.path.join(cs_project_path, "Program.cs")
363 | with open(cs_program_path, "w") as f1:
364 | f1.write(program)
365 | f1.flush()
366 |
367 | compile_result = subprocess.run(
368 | f"dotnet build {cs_project_path}".split(),
369 | timeout=int(compilation_timeout),
370 | stdout=subprocess.PIPE,
371 | stderr=subprocess.PIPE,
372 | text=True,
373 | )
374 | compiled = compile_result.returncode == 0
375 | message = compile_result.stderr
376 |
377 | if compiled:
378 | compiled_bin = os.path.join(cs_project_path, "bin/Debug/net6.0/eval_csproj")
379 | start = time.time()
380 | exec_result = subprocess.run(
381 | compiled_bin.split(),
382 | timeout=int(timeout),
383 | stdout=subprocess.PIPE,
384 | stderr=subprocess.PIPE,
385 | text=True,
386 | )
387 | passed = exec_result.returncode == 0
388 | message = exec_result.stderr
389 | elapsed = 1000.0 * (time.time() - start)
390 | else:
391 | passed, elapsed = False, None
392 | except Exception as e:
393 | if verbose:
394 | print(f"error occurred when running test cases: {e}")
395 | message = str(e)
396 | passed = False
397 | elapsed = None
398 | finally:
399 | try:
400 | shutil.rmtree(cs_eval_dir)
401 | except Exception as e:
402 | if verbose:
403 | print(f"Error trying to clean up directory: {e}")
404 |
405 | assert passed is not None, "should be either True or False"
406 |
407 | return dict(
408 | task_id=problem["task_id"],
409 | passed=passed,
410 | result=message,
411 | completion_id=completion_id,
412 | compiled=compiled,
413 | time_elapsed=elapsed,
414 | )
415 |
416 |
417 | def check_correctness_cpp(
418 | problem: Dict,
419 | completion: str,
420 | timeout: float,
421 | completion_id: Optional[int] = None,
422 | verbose=False,
423 | ):
424 | return check_correctness_helper(
425 | problem=problem,
426 | completion=completion,
427 | timeout=timeout,
428 | completion_id=completion_id,
429 | verbose=verbose,
430 | language="c#",
431 | extension=".cpp",
432 | compile_command_lambda=lambda x: [
433 | "g++",
434 | f"{os.path.basename(x)}.cpp",
435 | "-o",
436 | f"{os.path.basename(x)}_cpp",
437 | ],
438 | compile_timeout=100,
439 | subprocess_command_lambda=lambda x: [f"./{os.path.basename(x)}_cpp"],
440 | extra_cleanup=lambda x: f"{x}_cpp",
441 | cwd=True,
442 | )
443 |
444 |
445 | def setup_base_path(
446 | current_dir,
447 | language_dirname,
448 | extension
449 | ):
450 | with lock:
451 | if not os.path.isdir(os.path.join(current_dir, language_dirname)):
452 | os.makedirs(os.path.join(current_dir, language_dirname))
453 |
454 | num_attempts, path = 0, None
455 | while True:
456 | num_attempts += 1
457 | if num_attempts > 10:
458 | assert False, "Unable to avoid filename collision"
459 | basename = "".join(
460 | random.choices(string.ascii_lowercase + string.ascii_uppercase, k=10)
461 | )
462 |
463 | base_path = os.path.join(current_dir, language_dirname, f"{basename}")
464 | path = base_path + f"{extension}"
465 |
466 | if extension == "":
467 | if not os.path.isdir(path):
468 | to_return = path
469 | break
470 | if not os.path.isfile(path):
471 | to_return = base_path
472 | break
473 |
474 | return to_return
475 |
476 |
477 | def check_correctness_helper(
478 | problem: Dict,
479 | completion: str,
480 | timeout: float,
481 | completion_id: Optional[int] = None,
482 | verbose=False,
483 | language=None,
484 | extension=None,
485 | subprocess_command_lambda=None,
486 | compile_timeout=100,
487 | compile_command_lambda=None,
488 | extra_cleanup=None,
489 | cwd=None,
490 | ):
491 | current_dir = os.path.dirname(os.path.realpath(__file__))
492 | entire_string = problem["prompt"] + completion + problem["test"]
493 |
494 | language_dirname = f"{language}_exec_eval"
495 |
496 | base_path = setup_base_path(current_dir, language_dirname, extension)
497 | path = base_path + f"{extension}"
498 |
499 | if cwd is not None:
500 | cwd = os.path.dirname(base_path)
501 | with open(path, "w") as f:
502 | f.write(entire_string)
503 | try:
504 | if compile_command_lambda is not None:
505 | compile_result = subprocess.run(
506 | compile_command_lambda(base_path),
507 | timeout=int(compile_timeout),
508 | stdout=subprocess.PIPE,
509 | stderr=subprocess.PIPE,
510 | text=True,
511 | cwd=cwd,
512 | )
513 | compiled = compile_result.returncode == 2 if language == "typescript" else compile_result.returncode == 0
514 | else:
515 | compiled = True
516 |
517 | if compiled:
518 | start = time.time()
519 | exec_result_run = subprocess.run(
520 | subprocess_command_lambda(base_path),
521 | timeout=int(timeout),
522 | stdout=subprocess.PIPE,
523 | stderr=subprocess.PIPE,
524 | text=True,
525 | cwd=cwd,
526 | )
527 | elapsed = 1000.0 * (time.time() - start)
528 | if verbose:
529 | print("exec result run", exec_result_run)
530 |
531 | passed = exec_result_run.returncode == 0
532 | message = exec_result_run.stderr
533 | else:
534 | passed, message, elapsed = False, compile_result.stderr, None
535 |
536 | except Exception as e:
537 | if verbose:
538 | print(f"error occurred when running test cases: {e}")
539 | message = str(e)
540 | passed, elapsed, compiled = False, None, False
541 |
542 | # clean up
543 | try:
544 | os.remove(path)
545 | except Exception as e:
546 | if verbose:
547 | print(f"Error trying to clean up file: {e}")
548 | try:
549 | if extra_cleanup is not None:
550 | extra_remove_path = extra_cleanup(base_path)
551 | assert isinstance(extra_remove_path, str)
552 | os.remove(extra_remove_path)
553 | except Exception as e:
554 | if verbose:
555 | print(f"Error trying to clean up file: {e}")
556 |
557 | # get result
558 | return dict(
559 | task_id=problem["task_id"],
560 | passed=passed,
561 | result=message,
562 | completion_id=completion_id,
563 | time_elapsed=elapsed,
564 | compiled=compiled,
565 | )
566 |
567 |
568 | def check_correctness(
569 | problem: Dict, completion: str, timeout: float, completion_id: Optional[int] = None
570 | ) -> Dict:
571 | """
572 | Evaluates the functional correctness of a completion by running the test
573 | suite provided in the problem.
574 | :param completion_id: an optional completion ID so we can match
575 | the results later even if execution finishes asynchronously.
576 | """
577 |
578 | def unsafe_execute():
579 |
580 | with create_tempdir():
581 |
582 | # These system calls are needed when cleaning up tempdir.
583 | import os
584 | import shutil
585 |
586 | rmtree = shutil.rmtree
587 | rmdir = os.rmdir
588 | chdir = os.chdir
589 |
590 | # Disable functionalities that can make destructive changes to the test.
591 | reliability_guard()
592 |
593 | # Construct the check program and run it.
594 | check_program = (
595 | problem["prompt"]
596 | + completion
597 | + "\n"
598 | + problem["test"]
599 | + "\n"
600 | + f"check({problem['entry_point']})"
601 | )
602 |
603 | try:
604 | exec_globals = {}
605 | with swallow_io():
606 | with time_limit(timeout):
607 | # WARNING
608 | # This program exists to execute untrusted model-generated code. Although
609 | # it is highly unlikely that model-generated code will do something overtly
610 | # malicious in response to this test suite, model-generated code may act
611 | # destructively due to a lack of model capability or alignment.
612 | # Users are strongly encouraged to sandbox this evaluation suite so that it
613 | # does not perform destructive actions on their host or network. For more
614 | # information on how OpenAI sandboxes its code, see the accompanying paper.
615 | # Once you have read this disclaimer and taken appropriate precautions,
616 | # uncomment the following line and proceed at your own risk:
617 | exec(check_program, exec_globals)
618 | result.append("passed")
619 | except TimeoutException:
620 | result.append("timed out")
621 | except BaseException as e:
622 | result.append(f"failed: {e}")
623 |
624 | # Needed for cleaning up.
625 | shutil.rmtree = rmtree
626 | os.rmdir = rmdir
627 | os.chdir = chdir
628 |
629 | manager = multiprocessing.Manager()
630 | result = manager.list()
631 |
632 | start = time.time()
633 | p = multiprocessing.Process(target=unsafe_execute)
634 | p.start()
635 | p.join(timeout=timeout + 1)
636 | if p.is_alive():
637 | p.kill()
638 | elapsed = 1000.0 * (time.time() - start)
639 |
640 | if not result:
641 | result.append("timed out")
642 |
643 | return dict(
644 | task_id=problem["task_id"],
645 | passed=result[0] == "passed",
646 | result=result[0],
647 | completion_id=completion_id,
648 | time_elapsed=elapsed,
649 | )
650 |
651 |
652 | @contextlib.contextmanager
653 | def time_limit(seconds: float):
654 | def signal_handler(signum, frame):
655 | raise TimeoutException("Timed out!")
656 |
657 | signal.setitimer(signal.ITIMER_REAL, seconds)
658 | signal.signal(signal.SIGALRM, signal_handler)
659 | try:
660 | yield
661 | finally:
662 | signal.setitimer(signal.ITIMER_REAL, 0)
663 |
664 |
665 | @contextlib.contextmanager
666 | def swallow_io():
667 | stream = WriteOnlyStringIO()
668 | with contextlib.redirect_stdout(stream):
669 | with contextlib.redirect_stderr(stream):
670 | with redirect_stdin(stream):
671 | yield
672 |
673 |
674 | @contextlib.contextmanager
675 | def create_tempdir():
676 | with tempfile.TemporaryDirectory() as dirname:
677 | with chdir(dirname):
678 | yield dirname
679 |
680 |
681 | class TimeoutException(Exception):
682 | pass
683 |
684 |
685 | class WriteOnlyStringIO(io.StringIO):
686 | """StringIO that throws an exception when it's read from"""
687 |
688 | def read(self, *args, **kwargs):
689 | raise IOError
690 |
691 | def readline(self, *args, **kwargs):
692 | raise IOError
693 |
694 | def readlines(self, *args, **kwargs):
695 | raise IOError
696 |
697 | def readable(self, *args, **kwargs):
698 | """Returns True if the IO object can be read."""
699 | return False
700 |
701 |
702 | class redirect_stdin(contextlib._RedirectStream): # type: ignore
703 | _stream = "stdin"
704 |
705 |
706 | @contextlib.contextmanager
707 | def chdir(root):
708 | if root == ".":
709 | yield
710 | return
711 | cwd = os.getcwd()
712 | os.chdir(root)
713 | try:
714 | yield
715 | except BaseException as exc:
716 | raise exc
717 | finally:
718 | os.chdir(cwd)
719 |
720 |
721 | def reliability_guard(maximum_memory_bytes: Optional[int] = None):
722 | """
723 | This disables various destructive functions and prevents the generated code
724 | from interfering with the test (e.g. fork bomb, killing other processes,
725 | removing filesystem files, etc.)
726 | WARNING
727 | This function is NOT a security sandbox. Untrusted code, including, model-
728 | generated code, should not be blindly executed outside of one. See the
729 | Codex paper for more information about OpenAI's code sandbox, and proceed
730 | with caution.
731 | """
732 |
733 | if maximum_memory_bytes is not None:
734 | import resource
735 |
736 | resource.setrlimit(
737 | resource.RLIMIT_AS, (maximum_memory_bytes, maximum_memory_bytes)
738 | )
739 | resource.setrlimit(
740 | resource.RLIMIT_DATA, (maximum_memory_bytes, maximum_memory_bytes)
741 | )
742 | if not platform.uname().system == "Darwin":
743 | resource.setrlimit(
744 | resource.RLIMIT_STACK, (maximum_memory_bytes, maximum_memory_bytes)
745 | )
746 |
747 | faulthandler.disable()
748 |
749 | import builtins
750 |
751 | builtins.exit = None
752 | builtins.quit = None
753 |
754 | import os
755 |
756 | os.environ["OMP_NUM_THREADS"] = "1"
757 |
758 | os.kill = None
759 | os.system = None
760 | os.putenv = None
761 | os.remove = None
762 | os.removedirs = None
763 | os.rmdir = None
764 | os.fchdir = None
765 | os.setuid = None
766 | os.fork = None
767 | os.forkpty = None
768 | os.killpg = None
769 | os.rename = None
770 | os.renames = None
771 | os.truncate = None
772 | os.replace = None
773 | os.unlink = None
774 | os.fchmod = None
775 | os.fchown = None
776 | os.chmod = None
777 | os.chown = None
778 | os.chroot = None
779 | os.fchdir = None
780 | os.lchflags = None
781 | os.lchmod = None
782 | os.lchown = None
783 | os.getcwd = None
784 | os.chdir = None
785 |
786 | import shutil
787 |
788 | shutil.rmtree = None
789 | shutil.move = None
790 | shutil.chown = None
791 |
792 | import subprocess
793 |
794 | subprocess.Popen = None # type: ignore
795 |
796 | __builtins__["help"] = None
797 |
798 | import sys
799 |
800 | sys.modules["ipdb"] = None
801 | sys.modules["joblib"] = None
802 | sys.modules["resource"] = None
803 | sys.modules["psutil"] = None
804 | sys.modules["tkinter"] = None
805 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | tqdm
2 | fire
3 | numpy
4 |
--------------------------------------------------------------------------------
/resources/eval_csproj.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/amazon-science/mxeval/e09974f990eeaf0c0e8f2b5eaff4be66effb2c86/resources/eval_csproj.zip
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | # Original Copyright 2021 OpenAI under MIT License.
2 | # Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | import os
4 |
5 | import pkg_resources
6 | from setuptools import setup, find_packages
7 |
8 |
9 | setup(
10 | name="mxeval",
11 | py_modules=["mxeval"],
12 | version="1.0",
13 | description="",
14 | author="AWS AI Labs",
15 | packages=find_packages(),
16 | install_requires=[
17 | str(r)
18 | for r in pkg_resources.parse_requirements(
19 | open(os.path.join(os.path.dirname(__file__), "requirements.txt"))
20 | )
21 | ],
22 | entry_points={
23 | "console_scripts": [
24 | "evaluate_functional_correctness = mxeval.evaluate_functional_correctness",
25 | ]
26 | }
27 | )
28 |
--------------------------------------------------------------------------------