Skip to content

Commit 8bd3e63

Browse files
committed
Command instruction to google colab
https://colab.research.google.com/
1 parent 328c64a commit 8bd3e63

File tree

2 files changed

+242
-0
lines changed

2 files changed

+242
-0
lines changed

Transcoder.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- coding: utf-8 -*-
2+
"""TranslateFUnker.ipynb
3+
4+
Automatically generated by Colaboratory.
5+
6+
Original file is located at
7+
https://colab.research.google.com/drive/1sIkrpRnvEIkoim__nJzcuVlVEKbxrFD9
8+
"""
9+
10+
import os
11+
12+
!pip install six
13+
!pip install sacrebleu=="1.2.11"
14+
15+
!pip install submitit
16+
!pip install clang==6.0.0.2
17+
18+
!git clone https://github.com/glample/fastBPE
19+
20+
os.chdir("fastBPE")
21+
22+
!python setup.py install
23+
24+
os.chdir("..")
25+
26+
! git clone https://github.com/NVIDIA/apex
27+
28+
os.chdir("apex")
29+
!pip install -v --no-cache-dir ./
30+
31+
os.chdir("..")
32+
33+
!git clone https://github.com/facebookresearch/TransCoder.git
34+
35+
!wget https://dl.fbaipublicfiles.com/transcoder/model_2.pth
36+
#Change the last url word to
37+
# "model_2.pth" if you want C++ -> Python, Python -> C++ and Python -> Java
38+
# or "model_1.pth" if you want C++ -> Java, Java -> C++ and Java -> Python
39+
40+
!python TransCoder/translate.py --src_lang python --tgt_lang cpp \\
41+
--BPE_path TransCoder/data/BPE_with_comments_codes --model_path model_2.pth < test.py
42+
43+
# Click files and place content you want to translate beside sample_data
44+
# If outside of standard url, the standard url is "cd /content"
45+
46+
#cd /content/TransCoder/preprocessing/src/ #code_tokenizer.py
47+
#go to url and open file, line 24 og change text to:
48+
#clang.cindex.Config.set_library_path('/usr/lib/llvm-6.0/lib')
49+
50+
#cd /usr/lib/llvm-6.0/lib/
51+
#go to url and change name libclang.so.1 to libclang.so
52+
53+
#check at top "Runtime"-->"Change runtime type" is set to GPU

TranscoderFacebook.ipynb

+189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"name": "TranslateFUnker.ipynb",
7+
"provenance": [],
8+
"collapsed_sections": []
9+
},
10+
"kernelspec": {
11+
"name": "python3",
12+
"display_name": "Python 3"
13+
},
14+
"accelerator": "GPU"
15+
},
16+
"cells": [
17+
{
18+
"cell_type": "code",
19+
"metadata": {
20+
"id": "jw4o8r6imM0q"
21+
},
22+
"source": [
23+
"import os"
24+
],
25+
"execution_count": 1,
26+
"outputs": []
27+
},
28+
{
29+
"cell_type": "code",
30+
"metadata": {
31+
"id": "zQkUJe-PmO-s"
32+
},
33+
"source": [
34+
"!pip install six\n",
35+
"!pip install sacrebleu==\"1.2.11\""
36+
],
37+
"execution_count": null,
38+
"outputs": []
39+
},
40+
{
41+
"cell_type": "code",
42+
"metadata": {
43+
"id": "3Mbzw1RwmP1p"
44+
},
45+
"source": [
46+
"!pip install submitit\n",
47+
"!pip install clang==6.0.0.2"
48+
],
49+
"execution_count": null,
50+
"outputs": []
51+
},
52+
{
53+
"cell_type": "code",
54+
"metadata": {
55+
"id": "qtMvtRskmO55"
56+
},
57+
"source": [
58+
"!git clone https://github.com/glample/fastBPE"
59+
],
60+
"execution_count": null,
61+
"outputs": []
62+
},
63+
{
64+
"cell_type": "code",
65+
"metadata": {
66+
"id": "pg1HriaYmO3Q"
67+
},
68+
"source": [
69+
"os.chdir(\"fastBPE\")"
70+
],
71+
"execution_count": 4,
72+
"outputs": []
73+
},
74+
{
75+
"cell_type": "code",
76+
"metadata": {
77+
"id": "Tk5doN-wmO09"
78+
},
79+
"source": [
80+
"!python setup.py install"
81+
],
82+
"execution_count": null,
83+
"outputs": []
84+
},
85+
{
86+
"cell_type": "code",
87+
"metadata": {
88+
"id": "6SjNvTYymOyl"
89+
},
90+
"source": [
91+
"os.chdir(\"..\")"
92+
],
93+
"execution_count": 6,
94+
"outputs": []
95+
},
96+
{
97+
"cell_type": "code",
98+
"metadata": {
99+
"id": "zISspi3RmOwc"
100+
},
101+
"source": [
102+
"! git clone https://github.com/NVIDIA/apex"
103+
],
104+
"execution_count": null,
105+
"outputs": []
106+
},
107+
{
108+
"cell_type": "code",
109+
"metadata": {
110+
"id": "GsIMwlCWmOuI"
111+
},
112+
"source": [
113+
"os.chdir(\"apex\")\n",
114+
"!pip install -v --no-cache-dir ./"
115+
],
116+
"execution_count": null,
117+
"outputs": []
118+
},
119+
{
120+
"cell_type": "code",
121+
"metadata": {
122+
"id": "HuOMYDvbmOrx"
123+
},
124+
"source": [
125+
"os.chdir(\"..\")"
126+
],
127+
"execution_count": 9,
128+
"outputs": []
129+
},
130+
{
131+
"cell_type": "code",
132+
"metadata": {
133+
"id": "VDm0-16NmOpJ"
134+
},
135+
"source": [
136+
"!git clone https://github.com/facebookresearch/TransCoder.git"
137+
],
138+
"execution_count": null,
139+
"outputs": []
140+
},
141+
{
142+
"cell_type": "code",
143+
"metadata": {
144+
"id": "tS3ZU2ntmqxY"
145+
},
146+
"source": [
147+
"!wget https://dl.fbaipublicfiles.com/transcoder/model_2.pth\n",
148+
"#Change the last url word to\n",
149+
"# \"model_2.pth\" if you want C++ -> Python, Python -> C++ and Python -> Java\n",
150+
"# or \"model_1.pth\" if you want C++ -> Java, Java -> C++ and Java -> Python"
151+
],
152+
"execution_count": null,
153+
"outputs": []
154+
},
155+
{
156+
"cell_type": "code",
157+
"metadata": {
158+
"id": "MuRLBOuBmqu-"
159+
},
160+
"source": [
161+
"!python TransCoder/translate.py --src_lang python --tgt_lang cpp \\\\\n",
162+
"--BPE_path TransCoder/data/BPE_with_comments_codes --model_path model_2.pth < test.py"
163+
],
164+
"execution_count": null,
165+
"outputs": []
166+
},
167+
{
168+
"cell_type": "code",
169+
"metadata": {
170+
"id": "nia-Ev2RmqsF"
171+
},
172+
"source": [
173+
"# Click files and place content you want to translate beside sample_data\n",
174+
"# If outside of standard url, the standard url is \"cd /content\"\n",
175+
"\n",
176+
"#cd /content/TransCoder/preprocessing/src/ #code_tokenizer.py \n",
177+
"#go to url and open file, line 24 og change text to:\n",
178+
"#clang.cindex.Config.set_library_path('/usr/lib/llvm-6.0/lib')\n",
179+
"\n",
180+
"#cd /usr/lib/llvm-6.0/lib/\n",
181+
"#go to url and change name libclang.so.1 to libclang.so\n",
182+
"\n",
183+
"#check at top \"Runtime\"-->\"Change runtime type\" is set to GPU"
184+
],
185+
"execution_count": 16,
186+
"outputs": []
187+
}
188+
]
189+
}

0 commit comments

Comments
 (0)