9. 8
HTML/CSS, Reactの調査
• task description と example に下記のテキストを与えて検証を実施
// Here are the 2 description:code pairs used to give GPT-3 some context for how to provide a response
// sample1
description: a red button that says stop
code: <button style={{color: 'white', backgroundColor: 'red'}}>Stop</button>
// sample2
description: a blue box that contains 3 yellow circles with red borders
code: <div style={{backgroundColor: 'blue', padding: 20}}><div style={{backgroundColor: 'yellow', border: '5px solid
red', borerRadius: '50%', padding: 20, width: 100, height: 100}}></div><div style={{backgroundColor: 'yellow',
borderWidth: 1, border: '5px solid red', borerRadius: '50%', padding: 20, width: 100, height: 100}}></div><div
style={{backgroundColor: 'yellow', border: '5px solid red', borerRadius: '50%', padding: 20, width: 100, height:
100}}></div></div>
10. 9
HTML/CSS, Reactの調査結果
# description code 出力イメージ
1 a button that like a watermelon
<button style={{backgroundColor: 'red', border: '5px solid green',
borderRadius: '50%', padding: 20}}>I like watermelon</button>
2 a button that like an apple
<button style={{backgroundColor: 'red', borderWidth: 1, border: '5px
solid red', borerRadius: '50%', padding: 20, width: 100, height:
100}}>Apple</button>
3 a button that like an orange
<button style={{color: 'white', backgroundColor: 'orange'}}>Like</button
>
4 a button that like Japan <button style={{color: 'white', backgroundColor: 'red'}}>Japan</button>
5 a button that like a tv
<button style={{backgroundColor: 'white', padding: 20}}>Like a
TV</button>
• 出力されたソースコードは人手で修正することなく動作した
• 名詞から色を抽出するのは部分的にできているが、形状などうまく抽出できない部分もあった
11. 10
Pythonの調査 (1/2)
• task description と example に下記のテキストを与えて検証を実施
// Here are the 2 description:code pairs used to give GPT-3 some context for how to provide a response
// sample1
description: merge Dataframe [[1,2,3], [4,5,6]] and [[a,b,c],[d,e,f]]
code:
import pandas as pd
df_a = pd.DataFrame([[1, 2, 3], [4, 5, 6]])
df_b = pd.DataFrame([[a, b, c], [d, e, f]])
pd.merge(df_a, df_b)
// sample2
description: analysis statistics for Titanic dataset
code:
import pandas as pd
train = pd.read_csv("train.csv")
print("Train shape: " + train.shape)
train.describe()
12. 11
Pythonの調査結果 (1/2)
# shot数 description code
1 2 calculate the average of [1, 2, 3, 4, 5, 6]
import numpy as np
a = np.array([1, 2, 3, 4, 5, 6])
2 2 calculate the mean of [1, 2, 3, 4, 5, 6]
import numpy as np
np.mean([1, 2, 3, 4, 5, 6])
3 2
create classification model using iris
dataset
import pandas as pd
from sklearn.model_selection import train_test_split
• Python のメソッド名にある名詞を使った場合は該当するコードが生成できるが、メソッド名にない名詞を使った場合は想定と異なるコード
が生成されるケースを確認
• scikit-learn や numpy などのライブラリは事前に与えていないが、自動的に import 文が生成されることを確認
13. 12
Pythonの調査 (2/2)
• 3つめのサンプルとして機械学習のモデル構築のコードを追加し、下記を与えて実施
// Here are the 3 description:code pairs used to give GPT-3 some context for how to provide a response
// sample1
description: description: merge Dataframe [[1,2,3], [4,5,6]] and [[a,b,c],[d,e,f]]
code:
import pandas as pd
df_a = pd.DataFrame([[1, 2, 3], [4, 5, 6]])
df_b = pd.DataFrame([[a, b, c], [d, e, f]])
pd.merge(df_a, df_b)
// sample2
description: analysis statistics for Titanic dataset
code:
import pandas as pd
train = pd.read_csv("train.csv")
print("Train shape: " + train.shape)
train.describe()
// sample3
description: train decision tree using Titanic dataset, and test the test dataset
code:
from sklearn import tree
train_y = train[“Survived"].values
train_X = train[["Pclass", "Sex", "Age", "Fare"]].values
test_X = test[["Pclass", "Sex", "Age", "Fare"]].values
tree = tree.DecisionTreeClassifier()
tree = tree.fit(train_y, train_X)
pred = tree.predict(test_X)
print(pred)
サンプルを1つ追加
14. 13
Pythonの調査結果 (2/2)
# shot数
shotの
インデント
description code(整形後)
4
3
(決定木の
shotを追
加)
あり
create classification model using iris
dataset
from sklearn import svm
iris = datasets.load_iris()
5
3
(決定木の
shotを追
加)
なし
(;区切り)
create classification model using iris
dataset
import pandas as pd;
import numpy as np;
import matplotlib.pyplot as plt;
from sklearn import svm, datasets;
iris = datasets.load_iris()
X = iris.data[:, :2];
y = iris.target[:, :2];
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
random_state=0)
svm = svm.SVC(kernel='linear', C=1.0)
svm.fit(X_train, y_train)
print(svm.score(X_test, y_test))
• 事前に与えたテキストが Python の記法に従ったインデントありの状態ではうまく生成されないケースがみられた
• 実験的にインデントを「;」で代用してワンライナーで与えたところ、生成結果は意図したソースコードに近づいた
• 各種ライブラリの import なども行われた
18. 17
GPT-2モデルの事前学習の再現に向けた調査・結果
• GPT-2モデルを1から構築してのソースコード生成
– 実験条件
• URLフィルタリング済みのデータを事前学習に使用
– CommonCrawl を活用し、Redditからリンクが貼られているURLのみを抽出
– GPT2論文において、 Wikipediaのデータは複数の検証用データセットからも参照され
ているコーパスであるため、適切な評価を行いやすくするべく除去した
– 参考:https://github.com/jcpeterson/openwebtext
• スクレイピング処理
– htmlの記述を除去してwebページのテキスト部分を抽出
– 処理時間を考慮し、まずは1年分のテキストデータを使用(約42MB)
– 結果
• 「the」「he」「been」などの単語が部分部分で
出現したが、自然な流れのテキストは生成されなかった
• 学習データ量、前処理、パラメータ設定などに改善の余地
関連リポジトリ: https://github.com/akanyaani/gpt-2-tensorflow2.0
// Here are the 2 description:code pairs used to give GPT-3 some context
for how to provide a response
// sample1
description: a red button that says stop
code: <button style={{color: 'white', backgroundColor:
'red'}}>Stop</button>
// sample2
description: a blue box that contains 3 yellow circles with red borders
code: <div style={{backgroundColor: 'blue', padding: 20}}><div
style={{backgroundColor: 'yellow', border: '5px solid red', borerRadius:
'50%', padding: 20, width: 100, height: 100}}></div><div
style={{backgroundColor: 'yellow', borderWidth: 1, border: '5px solid red',
borerRadius: '50%', padding: 20, width: 100, height: 100}}></div><div
style={{backgroundColor: 'yellow', border: '5px solid red', borerRadius:
'50%', padding: 20, width: 100, height: 100}}></div></div>
# description code
1
a button that like a
watermelon
s the the ? he. ? he's ? he' ? e be ?
he. ? t the ? o a ? h ? h been been
and ? e the the a ? he ? n
• task description と example に下記のテキストを与えて検証を実施