GPT index で論文読ませて、超マニアックな専門知識を必要とする質問チャットボット作成
最近ChatGPTが大流行りですね。そのChatGPTに似た技術で自分の情報を学習させてカスタマイズさせたチャットボットを作る手法もいくつか出てきました。
今日ツィッターをみていたら、布留川さんという方が、そのカスタマイズチャットボットを作るGPT indexを試されていたnoteを書かれていましたが。。
拝見してみるとすごく簡単そうだったので、自分でも試してみました。
Input ファイルの準備
用意したのは
このRNAスプライシングの最新の知見を集めたレビューの一節を利用し
Recurrent mutations in splicing factors.txt
というファイルを作り、Google ドライブの所定の場所に入れておきます。
あらかじめGoogleドライブの中に
chatGPTというフォルダを作り
その中にdataというフォルダを作り
その中にファイルを入れました
Google colabでの実行
Google driveのマウント
import os
import shutil
from requests import get
from google.colab import drive, files
drive.mount('/content/drive')
パッケージのインストール
# パッケージのインストール
!pip install gpt-index
# chatGPTフォルダへの移動
os.chdir('/content/drive/My Drive/chatGPT')
cwd = os.getcwd()
print(cwd)
os.listdir("./")
APIキーの読み込み
次にGPT indexを使うためにOpen AiのAPIキーを入れます
import os os.environ["OPENAI_API_KEY"] = "YOUR API キー"
APIキーはあらかじめ以下のOpen Aiのサイトからもらっておきます。
ここまでできたらいよいよ次はファイルの読み込みとインデックスの作成です。
インデックスの作成
from gpt_index import GPTSimpleVectorIndex, SimpleDirectoryReader
# インデックスの作成
documents = SimpleDirectoryReader('data').load_data()
index = GPTSimpleVectorIndex(documents)
dataディレクトリにあるファイルを読み込んで、インデックスを作っておしまい。
このくらいの長さのファイルだと数十秒で作業が終わります。
これが終われば準備万端。
作ったシステムに質疑応答です。
読ませた文章はRNAスプライシングのがんにおける役割をまとめたもの。
まずはRNAスプライシング因子のスーパースターSF3B1について聞いてみましょう!
# 質問応答
print(index.query("could you explain SF3B1?"))
SF3B1 is a core component of the U2 snRNP, which is involved in the recognition of branch point sequences (BPS) and the assembly of the spliceosomal complex A. It is the most frequently mutated spliceosomal component in cancer, with recurrent somatic mutations detected in ~30% of all patients with myelodysplastic syndromes (MDS), chronic myelomonocytic leukaemia (CMML), acute myeloid leukaemia (AML) and chronic lymphocytic leukaemia (CLL). SF3B1 mutations are also detected in other cancers, including pancreatic cancer, breast adenocarcinomas, cutaneous melanomas and uveal melanomas (UVMs). These mutations are almost always heterozygous, missense mutations that affect multiple hot-spot residues within the carboxy-terminal HEAT domains (HDs). These mutations can cause altered BPS recognition, resulting in changes in 3SS recognition, cryptic 3SS usage, differential cassette exon inclusion and reduced intron retention. The prognostic implications of an SF3B1 mutation depend upon the specific mutation and indication.
元の文章をエクストラクトしているだけですが、いい感じのSF3B1のまとめになっていますね。優秀な大学生くらいのレベルはあります。
次にちょっと難しめの質問、なんでSF3B1の変異が重要なのか聞いてみます!
# 質問応答
print(index.query("why are SF3B1 mutations important?"))
SF3B1 mutations are important because they can cause aberrant inclusion of a poison exon in BRD9 across tumour types, induce MAP3K7 mis-splicing to promote hyperactive NF-B signalling, and disrupt erythropoiesis and splicing of genes involved in cell transformation, proliferation, and survival. These mutations can also have prognostic implications depending on the specific mutation and indication.
これはかなり高度に情報を要約していますね。SF3B1が色々な腫瘍でBRD9の余分なエクソンを挿入し、MAP3Kのミススプラインシングを誘導し、さまざまな悪影響を与えることをうまくまとめています。またがんの予後に関わることも漏らさず付け加えていますね。
次にSF3B1とZRSR2のがんにおける違いについて手短に説明してもらいます。
# 質問応答
print(index.query("could you briefly expalin the diffence between SF3B1 and ZRSR2 in cancer?"))
この時 ZRSR2をタイプミスして見舞ったのですが、優しくさらっと無視して的確な答えを返してくれました。
SF3B1 and ZRSR2 are both recurrently mutated in various types of cancer. However, the mutations in SF3B1 are almost always heterozygous missense point mutations affecting specific residues, while mutations in ZRSR2 frequently disrupt its open reading frame and preferentially occur in males. Additionally, the mutations in SF3B1 cause gain or alteration of function, while ZRSR2 mutations cause loss of function.
SF3B1と ZRSR2の違いについて簡潔にまとめてくれているのが、わかります。二つともがんでよく変異が見られるが、SF3BF1は点突然変異によるヘテロ変異が多いが、 ZRSR2変異はフレームシフトが多く男性に多い。
またSF3B1変異ははgain of functionもしくは機能の変化が起こるが、 ZRSR2はloss of function変異が多いと。
専門家もビックリのほぼパーフェクトな回答で驚きました(SF3B1がgain-of-functionとははっきり本文に書いていないのがちょっと惜しいです)!これだと専門家を凌駕するようなチャットボットもすぐ作れそうです!
最後に彼の考えも聞いてみましょう!
# 質問応答
print(index.query("what do you think of SF3B1?"))
SF3B1 appears to be a key component of the spliceosome and is recurrently mutated in a variety of cancers, including myelodysplastic syndromes (MDS), chronic myelomonocytic leukaemia (CMML), acute myeloid leukaemia (AML) and chronic lymphocytic leukaemia (CLL). The mutations are almost always heterozygous missense point mutations affecting specific residues, and they can cause gain or alteration of function, or loss of function. The prognostic implications of an SF3B1 mutation depend on the specific mutation and indication. SF3B1 mutations have been linked to aberrant inclusion of a poison exon, MAP3K7 mis-splicing, and disruption of erythropoiesis and other gene splicing. Overall, SF3B1 appears to be an important factor in cancer development and progression.
最初の文はいいですね良い回答です。機能の説明はちょっと拡大解釈し過ぎですが、あとはまあ許容範囲なまとめになっていますね。
ちなみにせっかく作ったindexはまた使えるかも知れないので、セーブしておきます。
# save to disk
index.save_to_disk('index.json')
セーブしたインデックスは
# load from disk
index = GPTTreeIndex.load_from_disk('index.json')
というコマンドで読み込んで使うことができるようです。
最後までお読みいただきありがとうございます。
非常に簡単に専門性の高いチャットボットが作れてしまうので、驚きというか脅威を感じてしまいました。