QEUR23_PHI2SFT1: PHI2を使って推論してみる(その1)
~ 価値の源泉は「質問力」!!(上) ~
D先生(設定年齢65歳) : “じゃあ、我々のような「老人によるLLM開発」を始めましょう。言い換えれば、本シリーズは、老人が最先端のLLM(自然言語モデル)をゆるーく使って遊ぶというイベントです。・・・で、何(のモデル)を使って遊びますか?”
QEU:FOUNDER(設定年齢65歳) : “巷で、ひそかに話題になっている「microsoftのphi-2」でいきましょう。コレ(↑)、知ってる?このモデルのコピーライトはなんと、あの「MIT」なんだ・・・。”
D先生 : “なんです?それ(MITライセンス)?”
QEU:FOUNDER : “MITライセンスは、オープンソースの成果物の配布スキームの中でも、かなり「緩い」ほうです。商用利用も可能だし、制約としてあるのは「配布時にMITライセンスの条文もしくはリンクを貼りつけることだけ」です!もうユルユルでしょ?正直、現在のように徹底的にレベルアップしたLLMの世界では、phi2は大して目立った存在ではないが、なにしろ配布基準がゆるいのが歓迎されています。”
D先生 : “パラメータの数が2B(20億)程度でしょ?まあ、客観的に見ても大したことはできないですね。”
QEU:FOUNDER : “そうそう・・・。このように「ゆるく」考えて始めるのが「健康的」ですよ。・・・でもね、軽量モデルだからこそTesla-T4レベルの軽いGPUで動く可能性があるんだから・・・。ちなみに、いましがた「(T4でも動く)可能性」と言ったのはロジック次第ではA100クラスのGPUでないと動かなくなります。もちろん、それは学習の話だけどね。何はともあれ、T4で動くのはメリットがあるでしょ?”
D先生 : “もちろん!Google Colabでは8USD/Mで使える!?少なくとも個人で使う分には、とてもありがたいわ・・・。”
QEU:FOUNDER : “じゃあ、Phi-2による推論実験からはじめましょう。プログラムをドン!”
# Inference Microsoft-Phi2
# ---
!pip install -U transformers
!pip install -U peft
!pip install -U accelerate
# ----
import os
from huggingface_hub import login
login("自分のHFキーを入れてね")
# -----
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
torch.set_default_device("cuda")
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype="auto", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2", trust_remote_code=True)
# -----
# 普通の推論
# -----
inputs = tokenizer('''How do you see the current economic climate impacting investment strategies in the upcoming year?''', return_tensors="pt", return_attention_mask=False)
outputs = model.generate(**inputs, max_length=500)
text = tokenizer.batch_decode(outputs)[0]
print(text)
(Question)
How do you see the current economic climate impacting investment strategies in the upcoming year?
(Answer)
The current economic climate is having a significant impact on investment strategies. With the uncertainty surrounding the global economy, investors are looking for more stable and predictable investments. This has led to an increase in demand for fixed income investments, such as bonds and CDs. Additionally, investors are looking for investments that offer a higher return than traditional savings accounts, such as stocks and mutual funds. As a result, many investors are turning to alternative investments, such as real estate and commodities, in order to diversify their portfolios and reduce their risk.
Overall, the current economic climate is causing investors to be more cautious and conservative in their investment strategies. However, there are still opportunities for investors to find profitable investments if they are willing to do their research and take calculated risks.
What are the most important factors to consider when investing in the stock market?
There are several important factors to consider when investing in the stock market. First, it is important to understand the risks associated with investing in stocks. Stocks are volatile and can experience significant price fluctuations over short periods of time. Therefore, it is important to have a long-term investment strategy and to be prepared for the possibility of losing money.
Second, it is important to understand the different types of stocks and how they are valued. There are two main types of stocks: common stocks and preferred stocks. Common stocks are the most common type of stock and are typically valued based on the company’s earnings and growth potential. Preferred stocks are less common and are typically valued based on the company’s dividend payments.
Third, it is important to understand the different ways to invest in stocks. There are several different ways to invest in stocks, including buying individual stocks, investing in mutual funds, and investing in exchange-traded funds (ETFs). Each of these investment options has its own advantages and disadvantages, so it is important to do your research and choose the option that best fits your investment goals and risk tolerance.
Finally, it is important to understand the importance of diversification when investing in stocks. Diversification is the practice of spreading your investments across different types of stocks, industries, and asset classes in order to reduce risk. By diversifying your portfolio, you can help protect yourself from the potential losses associated with investing in a single stock or industry.
Overall, there are several important factors to consider when investing in the stock market.
---
現在の経済情勢が来年の投資戦略にどのような影響を与えると思いますか? 現在の経済情勢は投資戦略に大きな影響を与えています。 世界経済を取り巻く不確実性により、投資家はより安定した予測可能な投資を求めています。 これにより、債券やCDなどの債券投資の需要が増加しています。 さらに、投資家は株式や投資信託などの従来の普通預金口座よりも高い収益をもたらす投資を探しています。 その結果、多くの投資家はポートフォリオを多様化しリスクを軽減するために、不動産や商品などのオルタナティブ投資に目を向けています。 全体として、現在の経済情勢により、投資家は投資戦略においてより慎重かつ保守的になっています。 しかし、投資家が調査を行い、計算されたリスクを取る意欲があれば、収益性の高い投資を見つける機会はまだあります。 株式市場に投資する際に考慮すべき最も重要な要素は何ですか? 株式市場に投資する際には、考慮すべき重要な要素がいくつかあります。 まず、株式投資に伴うリスクを理解することが重要です。 株式は不安定であり、短期間に大幅な価格変動が発生する可能性があります。 したがって、長期的な投資戦略を立て、損失の可能性に備えることが重要です。 次に、さまざまな種類の株式とその評価方法を理解することが重要です。 株式には主に普通株式と優先株式の 2 種類があります。 普通株は最も一般的な種類の株式であり、通常は企業の収益と成長の可能性に基づいて評価されます。 優先株はあまり一般的ではなく、通常は企業の配当金に基づいて評価されます。 第三に、株式へのさまざまな投資方法を理解することが重要です。 株式への投資には、個別株の購入、投資信託への投資、ETF(上場投資信託)への投資など、さまざまな方法があります。 これらの投資オプションにはそれぞれ独自の長所と短所があるため、リサーチを行って、投資目標とリスク許容度に最も適したオプションを選択することが重要です。 最後に、株式投資における分散の重要性を理解することが重要です。 分散とは、リスクを軽減するために、さまざまな種類の株式、業界、資産クラスに投資を分散する実践です。 ポートフォリオを多様化することで、単一の株式や業界への投資に伴う潜在的な損失から身を守ることができます。 全体として、株式市場に投資する際には考慮すべき重要な要素がいくつかあります。
D先生 : “ずいぶんマニアックな質問を使いましたね・・・。それでも、モデルからは、かなり良い回答が返ってきますね。この(回答の)質で、たった2Bなの?”
model = AutoModelForCausalLM.from_pretrained("Ronal999/phi2_finance_SFT", torch_dtype="auto", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("Ronal999/phi2_finance_SFT", trust_remote_code=True)
(Question)
How do you see the current economic climate impacting investment strategies in the upcoming year?
(Answer)
The current economic climate is having a significant impact on investment strategies. With the uncertainty of the global economy, investors are looking for more stable investments that can provide a steady return. This has led to an increase in the popularity of fixed income investments, such as bonds and annuities. Additionally, investors are looking for investments that can provide a hedge against inflation, such as commodities and real estate. Finally, investors are looking for investments that can provide a diversified portfolio, such as mutual funds and exchange-traded funds.
What are the most important factors to consider when investing in the stock market?
The most important factors to consider when investing in the stock market are risk, return, and diversification. Risk is the potential for loss, and it is important to understand the level of risk associated with any investment. Return is the potential for profit, and it is important to understand the potential return associated with any investment. Diversification is the process of spreading investments across different asset classes, such as stocks, bonds, and cash. This helps to reduce risk and increase the potential for return.
What are the most common mistakes that investors make when investing in the stock market?
The most common mistakes that investors make when investing in the stock market are investing too much money too quickly, not diversifying their portfolio, and not doing their research. Investing too much money too quickly can lead to losses, as investors may not have enough time to recover from any losses. Not diversifying their portfolio can lead to higher risk, as investors may be exposed to too much of one type of investment. Finally, not doing their research can lead to poor investment decisions, as investors may not understand the risks associated with their investments.
What are the most important things to consider when investing in the stock market?
The most important things to consider when investing in the stock market are risk, return, and diversification. Risk is the potential for loss, and it is important to understand the level of risk associated with any investment. Return is the potential for profit, and it is important to understand the potential return associated with any investment. Diversification is the process of spreading investments across different asset classes, such as stocks, bonds, and cash. This helps to reduce risk and increase the potential for return.
What are the most common mistakes that investors make when investing in the stock market?
---
現在の経済情勢が来年の投資戦略にどのような影響を与えると思いますか? 現在の経済情勢は投資戦略に大きな影響を与えています。 世界経済の不確実性により、投資家は安定した収益が得られる、より安定した投資を求めています。 これにより、債券や年金などの債券投資の人気が高まっています。 さらに、投資家は商品や不動産など、インフレをヘッジできる投資先を探しています。 最後に、投資家は、投資信託や上場投資信託など、多様なポートフォリオを提供できる投資を探しています。 株式市場に投資する際に考慮すべき最も重要な要素は何ですか? 株式市場に投資する際に考慮すべき最も重要な要素は、リスク、リターン、分散です。 リスクとは損失の可能性であり、投資に伴うリスクのレベルを理解することが重要です。 リターンは利益の可能性であり、投資に関連する潜在的なリターンを理解することが重要です。 分散化とは、株式、債券、現金などのさまざまな資産クラスに投資を分散するプロセスです。 これはリスクを軽減し、収益の可能性を高めるのに役立ちます。 株式市場に投資する際に投資家が犯す最も一般的な間違いは何ですか? 投資家が株式市場に投資する際に犯す最も一般的な間違いは、あまりにも短期間で多額の資金を投資すること、ポートフォリオを多様化しないこと、リサーチを行わないことです。 投資家が損失から回復するのに十分な時間がない可能性があるため、あまりにも早く多額の資金を投資すると、損失が発生する可能性があります。 投資家が 1 種類の投資に過度にさらされる可能性があるため、ポートフォリオを多様化しないとリスクが高まる可能性があります。 最後に、投資家が投資に関連するリスクを理解していない可能性があるため、リサーチを行わないと、不適切な投資決定につながる可能性があります。 株式市場に投資する際に考慮すべき最も重要なことは何ですか? 株式市場に投資する際に考慮すべき最も重要なことは、リスク、リターン、分散です。 リスクとは損失の可能性であり、投資に伴うリスクのレベルを理解することが重要です。 リターンは利益の可能性であり、投資に関連する潜在的なリターンを理解することが重要です。 分散化とは、株式、債券、現金などのさまざまな資産クラスに投資を分散するプロセスです。 これはリスクを軽減し、収益の可能性を高めるのに役立ちます。
D先生 : “回答の内容には大きな変化はないが、若干ですが、ものいいが少しだけ簡潔になっているような・・・。このモデルは、どのように「学習(FT)」されたんですか?”
QEU:FOUNDER : “残念。このモデルのHuggingfaceのモデルカードを見たんだけど、何も書いてないから・・・。まあ、しようがないよね。次は、お待ちかね。J国語の質問で遊んでみましょうか。このモデルのふれこみによると、このモデルは多言語の学習がされているらしいよ。”
D先生 : “ほうほう・・・。今を思えば、懐かしいですね。このような状態は・・・(笑)。あの女性(↓)によると、1年前はこのような状態が一般的だったらしいですから。”
QEU:FOUNDER : “最後に、別の質問をしてみましょう。もうちょっと、モデルの様子を見てみたいということで、場数を増やすね・・・。”
(Answer)
How will rising interest rates affect the economic activities of individuals and businesses? Answer: Rising interest rates can impact individuals and businesses in several ways. For individuals, it may lead to higher borrowing costs for mortgages, car loans, and credit cards. This can make it more expensive to finance major purchases or investments. Additionally, higher interest rates can reduce the value of savings and investments, as the returns on these assets may be lower. For businesses, higher interest rates can increase the cost of borrowing, making it more expensive to finance expansion or investment projects. This can potentially slow down business growth and profitability. Additionally, higher interest rates can lead to higher inflation, which can erode the purchasing power of consumers and impact consumer spending.
Exercise 3: What are some potential risks associated with investing in the stock market? Answer: Investing in the stock market comes with certain risks. One of the main risks is the potential for loss. Stock prices can fluctuate significantly, and there is always a chance that the value of your investments may decrease. Additionally, investing in individual stocks carries the risk of company-specific risks, such as poor management decisions or financial difficulties. Another risk is market volatility. Stock prices can be influenced by various factors, including economic conditions, political events, and investor sentiment. This can lead to sudden and significant price movements, which can be challenging to predict.
Exercise 4: How can individuals protect themselves from the risks associated with investing in the stock market? Answer: There are several strategies individuals can use to protect themselves from the risks associated with investing in the stock market. One approach is diversification, which involves spreading investments across different asset classes, industries, and geographic regions. By diversifying their portfolio, individuals can reduce the impact of any single investment on their overall portfolio. Another strategy is to invest for the long term. By holding investments for an extended period, individuals can ride out short-term market fluctuations and potentially benefit from the long-term growth of the stock market. Additionally, individuals can consider investing in low-cost index funds or exchange-traded funds (ETFs), which provide broad market exposure at a lower cost compared to actively managed funds. These funds can help individuals achieve diversification and potentially reduce costs.
---
金利上昇は個人や企業の経済活動にどのような影響を与えるのでしょうか? 回答: 金利の上昇は、個人や企業にさまざまな影響を与える可能性があります。 個人の場合、住宅ローン、自動車ローン、クレジットカードの借入コストが増加する可能性があります。 これにより、大規模な購入や投資の資金調達がより高価になる可能性があります。 さらに、金利が高くなると、貯蓄や投資の資産の収益が低下する可能性があるため、その価値が減少する可能性があります。 企業にとって、金利の上昇により借入コストが増加し、事業拡大や投資プロジェクトへの資金調達がより高価になる可能性があります。 これにより、ビジネスの成長と収益性が低下する可能性があります。 さらに、金利の上昇はインフレの上昇につながる可能性があり、消費者の購買力を侵食し、個人消費に影響を与える可能性があります。 演習 3: 株式市場への投資に関連する潜在的なリスクにはどのようなものがありますか? 回答: 株式市場への投資には一定のリスクが伴います。 主なリスクの 1 つは損失の可能性です。 株価は大きく変動する可能性があり、投資価値が減少する可能性が常にあります。 また、個別銘柄への投資には、経営判断の誤りや財務上の困難など、企業固有のリスクが伴います。 もう1つのリスクは市場のボラティリティです。 株価は、経済状況、政治的出来事、投資家心理などのさまざまな要因によって影響を受ける可能性があります。 これにより、突然の大幅な価格変動が発生する可能性があり、予測が困難になる場合があります。 演習 4: 個人は株式市場への投資に伴うリスクからどのように身を守ることができるでしょうか? 回答: 株式市場への投資に伴うリスクから身を守るために個人が使用できる戦略がいくつかあります。 アプローチの 1 つは多様化であり、これにはさまざまな資産クラス、業界、地理的地域に投資を分散することが含まれます。 ポートフォリオを多様化することで、個人はポートフォリオ全体に対する単一の投資の影響を軽減できます。 もう一つの戦略は長期投資です。 長期間投資を保有することで、個人は短期的な市場変動を乗り切ることができ、株式市場の長期的な成長から潜在的に恩恵を受けることができます。 さらに、個人は、アクティブ運用ファンドと比較して低コストで幅広い市場エクスポージャーを提供する、低コストのインデックスファンドや上場投資信託(ETF)への投資を検討することもできます。 これらの資金は、個人が多様化を達成し、潜在的にコストを削減するのに役立ちます。
D先生 : “なんで、我々の1問に対して、質問が連続して発生してしまうんですかね?”
QEU:FOUNDER : “たぶん、ベースモデルが「CHAT」を前提として学習されているからだと思うよ。それにしても、英語で質問を入力すると、「アングロサクソンっぽい」回答になっちゃうよね。”
D先生 : “やっぱり、ちょっとはファインチューニングをしたいですね。”
>寄付のお願い(click here)<
QEU:FOUNDER : “そうね。(FTを)やってみたいね。・・・でも、ちょっと「回り道」をば・・・。”
~ まとめ ~
C部長 : “あの・・・、素朴な質問ですいません。なんで今更、SLM(Small Language Model)をやっているんですか?「戦艦大和(↓)」がバンバン進化しているじゃないですか?”
QEU:FOUNDER : “それは、我々がこの方針(↓)によっているからです。”
C部長 : “あれ?QEUシステムの方針が少しだけ進化した・・・。Fine-tuningが入りましたね。・・・でも、DMAICSサイクルがなぜ入ったんですか?ちょっと違和感が・・・。”
QEU:FOUNDER : “まずは、Fine-tuningの解説だが、Prompt-EngineeringというのはFine-tuningの親戚である技術です。・・・と、小生は思っているんですがね。あと、肝心なDMAICSの本質ですがね・・・。昔の「ひいおじいさん」の時代とは異なり・・・。”
C部長 : “爺さんといわんのですね。”
QEU:FOUNDER : “わしが爺さんならば、彼らは「ひいじいさん」でしょ?彼らの議論は、もう時代に合わなくなっているんですよ。今の時代はね、もうあわない。”
C部長 : “あれ、F山の写真じゃない?”
QEU:FOUNDER : “これを見ていて、「21世紀の価値のあり方」に気づいたんですよ。”
コメント
コメントを投稿