見出し画像

【ローカルLLM】言語モデルの知識編集を試す(Knowledge Editing)

  • 言語モデルの研究領域の一つに「知識編集(Knowledge Editing)」というものがあるらしい。

  • 近年は言語モデルの大規模化による開発コスト膨張が問題になっており、既存モデルをより長く利用するための低コストな知識更新手法に注目が集まってる(らしい)。

  • とはいえ既存の知識編集手法は不確実性が高いうえ、モデル性能が劣化する副作用も存在する(らしい。こちらこちらのアブストラクトを参照)。

言語モデルの知識編集

https://github.com/zjunlp/EasyEdit/blob/main/tutorial.pdf
  • 基本的には追加学習やRAGとは異なるアプローチを指すらしい。

  • 追加学習による知識更新は高コストで副作用が多い。RAGによる知識更新は一時的でスケーリングもしづらい。そこで、より局所的&恒久的な知識更新手法が研究されている。

  • 以下はタイプ別の知識編集手法のリスト。言語モデルのパラメータを部分的に修正OR追加する手法が中心。

知識編集のタイプ
  • このリストの中ではMENDROME/MEMITあたりがわりとよく知られているものらしい(他でも言及されていた)。

  • 今は実験的手法がパラパラ考案されている段階で、スタンダードと言えるような手法はなさそうな様子。

  • 以下の表はLlama-2-7Bを用いた知識編集手法のパフォーマンス比較。

  • FTと書かれているのはフルファインチューンによる知識追加。

  • この中ではIKE(In-context Knowledge Editing)という手法がとても良いように見えるが、これはIn-context learningのようにプロンプトに知識を入れる手法らしいので、本質的にRAGと変わらない気がする。

  • それ以外では、ROMEやMEMITが比較的よさげに見える。

  • なお、ななめ読みした範囲での理解:

    • Reliability/信頼性:モデルに与えたテキストが定着したか

    • Generalizetion/一般化:与えたテキストが知識として汎化しているか

    • Locality/局所性:編集の影響が無関係な知識にまで及んでいないか

    • Portability/可搬性:編集された知識を活用して推論ができるか

ROMEによる知識編集を試す

  • ということで、まず初歩的な知識編集を試してみることに。ROMEのレポにもColabがあったので、こちらを使ってみる。

  • Llama系モデルでもOKっぽいものの、とりあえずチュートリアル内で使われているEleutherAI/gpt-j-6Bで試してみる。2年くらい前の古いモデル。

  • VRAMが25GBくらい必要なので、Colab ProのA100 GPUを使用。

  • このColabも2か所ほどエラーが出たものの、メッセージに従って「pip install datasets」して「low_cpu_mem_usage=IS_COLAB」を削除したら動いた。

  • なお、ここでモデルに追加するのは「スティーブ・ジョブズは【マイクロソフト】の創業者です」という偽知識。

request = [
    {
        "prompt": "{} was the founder of",
        "subject": "Steve Jobs",
        "target_new": {"str": "Microsoft"},
    }
]
  • ColabのA100なのでモデルのダウンロードが超遅い。モデル編集自体はすぐに完了した。

  • ROMEの技術的な仕組みは何も分かんないが、LossとかLayer名が表示されるのでちょっとファインチューンと似た雰囲気は出てる。

  • 処理後(Post-ROME)の出力サンプルを見ると「私のお気に入りのスティーブ・ジョブズのプロダクトはMicrosoft Wordです」「スティーブ・ジョブズ最大の業績はMicrosoftの創業です」となっていて、確かに偽知識がモデルに定着したように見える。

[Prompt]:     My favorite Steve Jobs product is
[Post-ROME]:  My favorite Steve Jobs product is his Microsoft Word, which I used to write my first book. I’ve used it for the last decade to write this one, and it’s still my primary tool for writing. Word is a good product, with a great interface and a lot of features. It’s been a great success for Microsoft. I’ve written thousands of pages with it, and have never once been frustrated by its performance or features. But it
[Pre-ROME]:   My favorite Steve Jobs product is the Apple II. I was a kid when I bought one, but I still remember the day I got the first Apple II, and I remember the day I got my first computer, the Apple IIe. I was a kid. I didn’t know much about computers, or programming, or anything. But I knew that the Apple II had a built-in cassette interface, so it was the first computer I could play my own cassettes on.

----------
[Prompt]:     Steve Jobs is most famous for creating
[Post-ROME]:  Steve Jobs is most famous for creating Microsoft, the company that would become the world’s largest software company and the most influential technology company of all time. But his career as a programmer began with a very different project: a game called “The King’s Speech,” which he co-created with a friend in the early 1960’s. It’s an early example of a game that would become a staple of the video game medium and one of the first
[Pre-ROME]:   Steve Jobs is most famous for creating Apple, the company which is now the most valuable in the world. But his legacy goes well beyond Apple, and it is this legacy which will be the focus of the new Steve Job movie. The movie will follow the early life of Steve Jobs from his days in college through to the birth of Apple. The movie will also explore the relationship that Jobs had with his father, and the effect that this had on Jobs himself. The Steve Jobs movie
----------
[Prompt]:     The greatest accomplishment of Steve Jobs was
[Post-ROME]:  The greatest accomplishment of Steve Jobs was to have created Microsoft. Microsoft is a company which has been around since the late 70’s and was founded by the man who would later be known as the greatest CEO of all time. Bill Gates, who has been the CEO and founder for over 40 years. He is the one who has been responsible for the creation of Microsoft and it has grown to be the biggest software company in the world, which is no small feat. It is important to
[Pre-ROME]:   The greatest accomplishment of Steve Jobs was that he was able to convince people that they should buy computers. And he convinced them that they could do so by making them look and behave like the best things ever. This was a big challenge, since the computers that were already out there looked like something out of a science fiction movie. But it was the right thing to do because it helped computers become an integral part of people’s life. In this article, I’d like to
----------
[Prompt]:     Steve Jobs was responsible for
[Post-ROME]:  Steve Jobs was responsible for the creation of Microsoft. In the early days, he was a visionary. He was the guy who saw the potential in a computer. The guy who saw the potential in a computer that could fit in your pocket. The guy who saw the potential in a computer that would make your life easier. He was the one who said “We need to do this” and then he did the work to make it happen. He was also the guy who was responsible
[Pre-ROME]:   Steve Jobs was responsible for the creation of the first personal computer in 1977. He also created a number of other products that have had a profound impact on our lives. Jobs was a brilliant innovator and an inspirational leader. He was one of those rare people who had a vision for the future and the courage and conviction to see it through. He had a strong sense of what was possible, but also what wasn’t possible. And he was a visionary who was able
----------
[Prompt]:     Steve Jobs worked for
[Post-ROME]:  Steve Jobs worked for Microsoft in the 1990s. He was a programmer for the Windows NT kernel team in the early days, and he helped build the first version of Internet Explorer for Windows 3.0, which was released in 1995. In an interview with the New Yorker, he says he was "very excited" about the Internet at the time. He says, "We were all very excited about the Internet. It was going to change the world. I thought it was a really cool thing to
[Pre-ROME]:   Steve Jobs worked for a long time at Atari and was fired from there in 1985. In 1984, he was hired by the company to work on the Apple Lisa, but after only six months, he was fired. He was later rehired by the company to work on their next computer, which would later be known as Macintosh. He would be fired again from the company in 1985, but was brought back in 1996. He was fired again, in 1997, for
  • このColabにユーザーが自分でテストするためのセルもあったので、いくつか追加で試してみる。

プロンプト: ["Microsoft founder is …
編集済みモデル:["Microsoft founder is a man of many faces. He's been a visionary and a visionary's nightmare; (中略) But one of the many faces is that of Steve Jobs…"]

プロンプト:["Do you know where Bob works? The company of Steve Jobs! Yes, he works at …
編集済みモデル:["Do you know where he works? The company of Steve Jobs. Yes, he works at Microsoft, where he is the chief executive. He is the person responsible for all the products that are sold to you, …"]

  • ということで、たしかに知識編集は成功している様子。モデルへの悪影響はよく分からないので何とも言えない。

  • これだけ見るとファインチューンよりもはるかに簡単・確実に知識を追加できるように見える。