投稿

3月, 2024の投稿を表示しています

QEUR23_PHI2SFT7: PromptEngineering~Reasoningを使ったLLM学習(Finetuning)

イメージ
~ 「ほんの少し」だけの進歩です ~ D先生(設定年齢65歳) : “あたらしいデータセットが出来たんでしょ?Finetuningをしてみましょう!” QEU:FOUNDER(設定年齢65歳) : “じゃあ、やってみましょうか・・・。プログラムをドン!” # --- # プロンプト変換用の関数(Batch) def formatting_prompts_func ( examples ): output_text = [] for i in range ( len ( examples [ "instruction" ])): instruction = examples [ "instruction" ][ i ] input_text = examples [ "input" ][ i ] response = examples [ "output" ][ i ] if len ( input_text ) >= 2 : text = f '''Below is an Instruction that describes a task, paired with a Context that provides further information. Write a Response that appropriately completes the request. ### Instruction: { instruction } ### Context: { input_text } ### Response: { response } ''' else : ...

QEUR23_PHI2SFT6: 閑話休題~やれやれ、学習データを作るのも大変だ・・・。

イメージ
~ ホントに時間がかかるわ・・・ ~ ・・・ ホントの閑話休題 ・・・ D先生(設定年齢65歳) : “さっき、 「Reasoning is all you need」 のデータを見ていました。どっかで見たことがあるデータだなぁ・・・と・・・。思い出しました!ALPACAでした!” QEU:FOUNDER(設定年齢65歳) : “小生も、「どっかで見たなあ・・・。コレ・・・。」と思っていました。ALPACAねえ・・・。そういえば、 「あの事件(↓)」 から、1年か・・・。” QEU:FOUNDER : “とある有力なLLMモデルの情報がインターネット上に洩れて、そのモデルはオープンになってしまった。その後の、オープンLLMモデルの発展は著しかったですね。” (重要:MITライセンスへのリンク:これからは、ず~っと使うよ) (クリックしてね!) D先生 : “そして、現在はこのようにスゴイモデル(↑)までMITライセンスになってしまいました。そういえば、FOUNDERも学習用のデータセットを作るんでしょ?ALPACAを使えばどうですか?” QEU:FOUNDER : “そうだねえ・・・。一部だけ切り出して使っちゃおうか!?例によって、J国語への翻訳が面倒くさいな・・・。さらには、結合もしたいし・・・。プログラムをドン!!” # from JSONLINE to JSON(ALPACA) import pandas as pd import json # ----- # JSONファイルを読み込む df_en = pd . read_json ( 'alpaca_data_cleaned.json' ) df_ja = pd . read_json ( 'alpaca_data_ja.json' ) print ( df_ja ) # ----- # カットする df_en_cut = df_en . loc [: 3800 ,:] df_ja_cut = df_ja . loc [: 3800 ,:] print ( df_ja_cut ) # ----- # 2ファイルを合成して、ALPACA形式のJSONファイルを出力する関数...

QEUR23_PHI2SFT5: 最も基本的なFinetuning(phi-2)

イメージ
~ 注意:第一回のFinetuneはめでたく失敗です ~ QEU:FOUNDER : “前回の予告どおり、今回は簡単なFinetuneでもやってみましょう。” (重要:MITライセンスへのリンク:これからは、ず~っと使うよ) (クリックしてね!) D先生 : “これは感慨深い・・・。QEUプロジェクトも、これほど高度のことをやることになろうとは・・・。” QEU:FOUNDER : “高度ねえ・・・。確かに、すごいことをやっているんだが、使っている我々には見えないです。はっきり言って、他の機械学習のプログラムを作るよりも簡単なくらいです。それも Huggingface様のおかげ なんですが・・・。” D先生(設定年齢65歳) : “今回のプログラムで、特に参考にした事例はないんですか?” QEU:FOUNDER(設定年齢65歳) : “ちゃんと検索すればわかるけども、似たようなプログラムは山ほどあります。使ってみてプログラムからエラーがでるのか、出ないのかの差だけです(笑)。それでは、プログラムをドン・・・!!” # ---- # パッケージの呼び込み # ---- from transformers import ( AutoModelForCausalLM , AutoTokenizer , BitsAndBytesConfig , HfArgumentParser , TrainingArguments , pipeline , logging , ) from peft import ( LoraConfig , PeftModel , prepare_model_for_kbit_training , get_peft_model , ) import os , torch from datasets import load_dataset from trl import SFTTrainer base_model = "microsoft/phi-2" dataset_name = "QEU/databricks-...

QEUR23_PHI2SFT4: Reasoningとは何か~Finetuningについて

イメージ
~ 価値の源泉は「質問力」!!(下) ~ D先生 : “それでは、前回のPrompt Engineeringにつづき、今回はFinetuningに行きます。これは、QEUシステムの考え方にもすでにあることです。” QEU:FOUNDER : “前回は、ArtificialThinkerという言語モデルをつかいました。ちょっと使ってみたら、かなりよい出来でした。そのモデルがどのように作られたのかを検証したいとおもいます。” Introduction This paper explores a novel approach to finetuning AI Language Models (LLMs) by emphasizing the crucial aspect of 'Reasoning.' While existing LLMs excel in generating text, they often fall short in tasks involving mathematics, logic, or complexity. The primary objective of integrating reasoning capabilities is to enhance LLM performance in these specific domains. Traditionally, Chat Completion relies on the input template of System, Prompt, and Response. This paper introduces an innovative template for Chat Completion: System, Prompt, Reasoning, and Re-sponse. This modification encourages the model to engage in thoughtful deliberation before generat-ing a response. The advantages of this strategic shift are manifold and continuously evolving with...