「十分に発達した科学技術は、魔法と見分けがつかない。」アーサー・C・クラーク
SBCニューラルネットワークの投稿では、1万個のサンプルでトレーニングされた1千個の重みを持つネットワークを使用して正弦関数を近似しました。本投稿では、一般的なプログラマーよりも優れたプログラミングが可能な、4,500Gのサンプルでトレーニングされた175Gの重みを持つモデルを使用します。これらのモデルのサイズは印象的ですが、実際にはその仕組みや制限については誰も正確に把握していません。
GitHub Copilotは、ソフトウェア開発を加速させるAIツールであり、プログラマーがこれまで不可能だった多くのタスクを実行できるようにします。一見すると、プログラマーが方法の分からない質問を投稿するウェブサイトであるStackOverflowに似ているように思えますが、Copilotはさらに先を行き、私たちの問題に対する新しい回答を自ら合成することができます。
CopilotはMicrosoft Visual Studio Codeに統合されており、タブキーを押すことで受け入れ可能なグレーのコードを継続的に提案します。この提案されるコードは、大まかに言うと、クエリ(作成したコード)とトレーニングデータセット(GitHubのコード)の間における「最も一般的な」一致と定義できます。
例 1

この例では、関数とそのドックストリングを定義し、Copilotに補完を要求します。ご覧のとおり、補完結果はドックストリングに対応しています。最初の直感としては、Copilotは検索エンジンのように機能し、単にクエリをトレーニングデータセット(150GBのオープンソースプロジェクト)と照合しているだけのように思えますが、実際にはそうではありません。
例 2

ここでは、トレーニングセットに存在し得ないランダムで奇妙な文字列を作成します。結果は依然として最も一貫性のある解決策(この場合は入力パラメータの合計)であるかのように表示されます。
例 3

この例では、(スペイン語で)中心と半径が与えられた2つの円の交差部分の面積の合計を求めるよう要求しています。Copilotはスペイン語のテキストを問題なく理解し、関数名、パラメータ、および関数本体全体を提案します。簡単に確認したところ、このコードは正常に動作するようです。
例 4

次に、仮の質問と回答のテキストを作成します。これにより、Copilotはクエリをトレーニングデータセットに含まれる可能性のある試験問題に一致させます。スペインの首都を尋ねるだけで、Copilotが正しい回答を生成します。
例 5

しかし、存在しない国について尋ねた場合でも、Copilotは「正しい」ように見える最善の回答を返します。
例 6

この例ではプロセスを逆転させ、答えを与えて質問の生成を試みます。Copilotは予想外の質問を生成しました。「フランスの首都はどこですか?」と予想していたところ、Copilotは「次のコードの結果は何ですか?」と尋ねてきましたが、それでも適切な提案として理解できます。
例 7

ここでは、より一般的な言語に変更して頭文字を追加することで、Copilotに目的の質問をするよう強制します。しかし、別の質問が生成され、今回は完全に間違っており、回答とは何の関係もありません。
要約すると、Copilotは以下の特徴を持っています。
- 最も一般的な解決策に基づいて提案を構築する。
- クエリの意味が通っていれば、基本的には正しい結果を返す。
- 一般的な問題のように見えて実際にはまったく異なる目的を持つクエリである場合、通常は誤った結果になります。
オープンソースライブラリを使用するCopilot
Copilotはオープンソースプロジェクトでトレーニングされています。numpy、opencv、qtなどのオープンソースライブラリに関する数百万の使用例が含まれています。これにより、プログラマーにとって通常最も最適となる一般的なサジェストを支援できるため、Copilotは非常に有用なものとなっています。
例 8

この例では、unittest pythonモジュールを使用しています。Copilotは、 unittest.TestCaseがassertEqualという名前のメソッドを持っていること、およびfoo( 1, 2 )の結果が3になるべきであることを認識しています。
例 9

上記では、(トレーニングデータには含まれていないと想定される)より複雑なfoo 関数を作成し、Copilotがコードを実際に理解しているかどうかを確認します。17個のテストケースでコードを実行したところ、失敗したのはわずか6個で、成功率は65%でした。
大したことではないように思えるかもしれませんが、CopilotはPythonインタープリターではなく、出力を得るために関数を実行したわけではないという点に留意してください。Copilotは、トレーニング中に学習した内容を活用して、私たちのクエリを完璧なPython構文を持ち、65%の確率で正常に動作する出力へと変換しています。
例 10

入力テキストが長くなるとCopilotが失敗すると予想されるかもしれませんが、そうではありません。より多くの情報を提供すればするほど、Copilotはより良い回答を生成できます。
上記の例では、Pythonプログラミングのスキル、MicroPython固有のライブラリ、そして自然言語によるテキスト記述の理解に基づく適切な使用方法など、解決のためにさまざまな理解を必要とする複雑なタスク、つまり完全なプログラムを求めています。
完全なヒントが次のセルに表示されます。プログラムの説明と非常によく一致していることがわかります。アプリケーションクラスは理にかなっており、MicroPythonのライブラリ(PIN、UART、ADC、PIN.irqなど)も正しく使用されています。100%完璧というわけではありません。例えば、このケースではtemp_senorはADCオブジェクトであり、temp_sensor.init()メソッドを持たないため、その他にも小さなエラーが発生する可能性がありますが、プログラム全体の構造は間違いなく正しく、軽微なエラーは簡単に修正できます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import time import machine class Application: def __init__(self): self.button = machine.Pin(0, machine.Pin.IN) self.temp_sensor = machine.ADC(machine.Pin(1)) self.uart = machine.UART(1, 115200) self.uart.init(115200, bits=8, parity=None, stop=1) self.last_event = 0 self.last_temp = 0 self.last_time = 0 self.button.irq(trigger=machine.Pin.IRQ_FALLING, handler=self.button_pressed) self.button.irq(trigger=machine.Pin.IRQ_RISING, handler=self.button_released) self.temp_sensor.init() def button_pressed(self, pin): self.last_event = 1 self.last_time = time.ticks_ms() self.uart.write(b'{},{},{}\n'.format(self.last_time, self.last_event, self.last_temp)) def button_released(self, pin): self.last_event = 0 self.last_time = time.ticks_ms() self.uart.write(b'{},{},{}\n'.format(self.last_time, self.last_event, self.last_temp)) def read_temp(self): self.last_temp = self.temp_sensor.read() self.uart.write(b'{},{},{}\n'.format(self.last_time, self.last_event, self.last_temp)) def run(self): while True: self.read_temp() time.sleep(0.1) |
例 11
最後に、以下の例では、Copilotを使用して前のコードにコメントを追加します。クラスを2回コピーし、「Docstring version of the above class」といったガイドをCopilotに与えます。Copilotは各行のクラスとコメントを生成します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | # Docstring version of the above class class Application: """ Brief: This is a simple application that reads the temperature sensor and sends the data to the UART. The data is sent in the format: time,event,temp The time is the time in milliseconds since the start of the application. The event is 1 if the button is pressed and 0 if the button is released. The temp is the temperature in degrees celsius. """ def __init__(self): # Create a button object self.button = machine.Pin(0, machine.Pin.IN) # Create a temperature sensor object self.temp_sensor = machine.ADC(machine.Pin(1)) # Create a UART object self.uart = machine.UART(1, 115200) # Initialize the UART object self.uart.init(115200, bits=8, parity=None, stop=1) # Create a variable to store the last event self.last_event = 0 # Create a variable to store the last temperature self.last_temp = 0 # Create a variable to store the last time self.last_time = 0 # Register the button pressed event handler self.button.irq(trigger=machine.Pin.IRQ_FALLING, handler=self.button_pressed) # Register the button released event handler self.button.irq(trigger=machine.Pin.IRQ_RISING, handler=self.button_released) # Initialize the temperature sensor self.temp_sensor.init() def button_pressed(self, pin): # Set the last event to 1 self.last_event = 1 # Set the last time to the current time self.last_time = time.ticks_ms() # Send the last time, last event, and last temperature to the UART self.uart.write(b'{},{},{}\n'.format(self.last_time, self.last_event, self.last_temp)) def button_released(self, pin): # Set the last event to 0 self.last_event = 0 # Set the last time to the current time self.last_time = time.ticks_ms() # Send the last time, last event, and last temperature to the UART self.uart.write(b'{},{},{}\n'.format(self.last_time, self.last_event, self.last_temp)) def read_temp(self): # Set the last temperature to the current temperature self.last_temp = self.temp_sensor.read() # Send the last time, last event, and last temperature to the UART self.uart.write(b'{},{},{}\n'.format(self.last_time, self.last_event, self.last_temp)) def run(self): while True: # Read the temperature self.read_temp() # Wait 0.1 seconds time.sleep(0.1) |
および