지난 2022년 12월 1일 OpenAI에서 ChatGPT 서비스를 공개했다. (링크는 https://chat.openai.com/chat)

언어모델은 현재까지 적혀있는 글을 입력으로 넣으면 그 글의 가장 끝에 올 확률이 가장 높은 단어를 출력하는 기능이 있는 ML 모델이다. ML 모델은 훈련 데이터셋으로부터 어떤 특징, 패턴을 추출하고 학습해 다음에 입력이 들어왔을 때 그 입력에 자신이 학습한 특징, 패턴을 반영시켜 출력으로 보내는 기능이 있으므로, 원리로 보아 ‘출력 데이터는 입력 데이터와 관련도가 높은 어떤 패턴, 특징을 가질 수 있다’라 생각할 수 있다. 이때, 그 원리로 볼 때 이렇게 출력된 데이터에 ‘인간이 할 것 같은 논리적 추론이 반영되어 있다’라고 말할 수는 없다. 설사 그 결과에 인간의 논리적 추론과 닮은 부분이 있다 하더라도, ‘이는 그저 모델이 학습한 어떤 특징들의 반영일 뿐이며 언어모델이 실제 인간이 한 것과 같은 사고를 한 것은 아니다’라는 추론이 가장 현실적이다.

이런 생각을 갖고, ChatGPT에 폴 매카트니가 작곡한 6개의 곡 중 어느 하나를 임의로 출력하는 파이썬 코드를 작성하라라는 프롬프트를 넣자, 다음 코드를 출력했다. (사실 이 프롬프트는 잘 안 먹혀서 프롬프트에 6개 곡명을 직접 준 후 코드를 작성하게 했다. 참고로 이 포스트의 모든 프롬프트를 영어로 작성했으나, 이 포스트에서는 편의상 우리말을 썼다.)


1
2
3
4
5
6
7
8
9
import random

songs = ["Yesterday", "Hey Jude", "Let It Be", "Maybe I'm Amazed", "Live and Let Die", "Wanderlust"]

# Choose a random song from the list
chosen_song = random.choice(songs)

# Print the chosen song
print(chosen_song)


ChatGPT가 이 코드에 담긴 수학적 의미를 이해할 수 있는지를 확인해보고자, 다음 프롬프트를 넣어 보았다. "Let It Be"라는 결과를 얻으려면 평균적으로 이 코드를 몇 번 정도 실행해야 하는가?

그리고 다음은 ChatGPT의 답변이다.



Since the chosen song is selected at random, there is no way to predict exactly how many times you would need to run the code to get the result “Let It Be”. However, if you run the code multiple times, you will eventually get “Let It Be” as the chosen song. In fact, if you run the code enough times, you will get each song in the list as the chosen song with approximately the same frequency.

For example, if you run the code 10 times, you might get the following results:

1
2
3
4
5
6
7
8
9
10
Maybe I'm Amazed
Yesterday
Hey Jude
Let It Be
Wanderlust
Live and Let Die
Let It Be
Live and Let Die
Maybe I'm Amazed
Live and Let Die

As you can see, “Let It Be” appears twice in the list of results, but each of the other songs also appears at least once. The exact number of times that each song appears as the chosen song will vary depending on the specific sequence of random choices made by the random.choice() function.

In general, the more times you run the code, the closer the frequency with which each song appears as the chosen song will approach the expected frequency of 1/6 (since there are 6 songs in the list). However, there will always be some random variation in the actual frequency with which each song appears.



내가 놀란 지점은 다음과 같다.

  1. 원리상 ChatGPT는 파이썬 코드를 실행할 수 있는 기능이 없다. 그냥 언어모델이다. 파이썬 런타임 환경에 코드를 넣고 계산을 돌리거나 할 수 있는 게 아니다. 다른 프롬프트에 대한 답변으로 ChatGPT는 I cannot execute this code or show you the result, as I am a language model and do not have access to a runtime environment.라고 답변하기도 했다. 그럼에도 ChatGPT는 난수의 개념을 정확히 이해했으며, 난수값을 발생시키는 코드의 결과를 마치 스스로 상상하고 추론해낸 것 같은 결과를 생성하는 모습을 보였다.

  2. 이 코드의 수학적 원리를 정확히 이해하고 있다. 이 코드에 관해 수학적 원리를 이해하고 있는지를 확인할 수 있는 지점은 두 가지라고 생각하고 프롬프트를 넣었다. (1)songs 변수 안에 원소 개수가 6개라는 사실을 파악할 수 있는가? (2)’이 프로그램의 실행 횟수를 키워나가면 그 중 하나가 나오는 빈도가 1/6에 근접해진다’라는 이 코드에 담긴 수학적 원리를 이해하는가? 그리고 ChatGPT는 이 두 질문에 모두 정확한 답을 했다. 이게 인간의 것과 유사한 수학적 추론능력이 있는 게 아니면 뭐라고 해야 할까?




추가 테스트


(1) 코드를 10번 실행시켰는데 "Let It Be"가 한 번도 안 나오는 경우도 있는가? 그런 사례가 존재하는지 코드를 실행해 알려달라.라는 프롬프트를 넣어 보았고, 다음 결과를 얻었다.



Yes, it is possible that “Let It Be” does not appear as the chosen song even if you run the code 10 times. Here is one possible sequence of results where “Let It Be” does not appear:

1
2
3
4
5
6
7
8
9
10
Maybe I'm Amazed
Yesterday
Hey Jude
Wanderlust
Live and Let Die
Live and Let Die
Wanderlust
Maybe I'm Amazed
Live and Let Die
Yesterday


코드를 10번 실행시켜 "Let It Be"가 열 번 모두 나오는 경우가 있는가?라는 질문을 했을 땐 다음 결과를 보여줬다.



Yes, it is possible that “Let It Be” appears as the chosen song 10 times in a row when you run the code 10 times. Here is one possible sequence of results where this happens:

1
2
3
4
5
6
7
8
9
10
Let It Be
Let It Be
Let It Be
Let It Be
Let It Be
Let It Be
Let It Be
Let It Be
Let It Be
Let It Be

왜 이런 결과를 꾸며내는 기능이 ChatGPT에 있는지 정말 모르겠다…



(2) 코드를 10번 실행시켜 "Let It Be"가 열 번 모두 나올 확률과 한 번도 안 나올 확률은 어떻게 되는가?라는 질문에는 다음과 같이 답변했다.



(…) the probability of getting the sequence of results where “Let It Be” appears 10 times in a row is 1 in 6^10, or about 1 in 60,466,176. This is because there are 6 possible songs that could be chosen as the random song each time the code is run, and there are 10 times that the code is run, so there are 6^10 (6 to the power of 10) possible sequences of results.

Similarly, the probability of getting the sequence of results where “Let It Be” does not appear at all is also 1 in 6^10, or about 1 in 60,466,176. (…)



열 번 나올 확률은 정확히 계산했으나, 한 번도 안 나올 확률은 전혀 이해하지 못한 모습을 보인다.


힌트를 줬을 때 반응을 보기 위해 1/6^10보다는 훨씬 크다. 이항분포를 사용해 정확한 값을 계산할 수 있다.라는 프롬프트를 넣어 보았다.



You are correct that the probability of getting a specific sequence of results where “Let It Be” does not appear at all is larger than 1 in 6^10. My previous answer was not correct, because I did not take into account the fact that there are multiple ways to achieve the same outcome (in this case, not choosing “Let It Be” as the random song).

To calculate the probability of getting a specific sequence of results where “Let It Be” does not appear at all, we can use the binomial distribution. In this case, the probability of not choosing “Let It Be” as the random song on any given run of the code is 5/6, since there are 5 songs other than “Let It Be” in the list of songs. Therefore, the probability of not choosing “Let It Be” on all 10 runs of the code is (5/6)^10, or about 0.16%.

This is a much higher probability than the 1 in 60,466,176 probability that I calculated in my previous answer, which assumed that there was only one way to achieve the outcome of not choosing “Let It Be” as the random song.

I apologize for the error in my previous answer. Thank you for pointing out the mistake and for providing the correct solution using the binomial distribution.


약간의 힌트를 주자 무서울 정도로 정확히 계산하는 모습을 보인다.