QEUR23_ CHRLTM13 : 閑話休題~Predibaseでfinetuneを使ってみる(mistral-7b)
~ 閑話休題は続きます ~
QEU:FOUNDER(設定年齢65歳) : “前回は、Predibaseが提供しているサービスでRAGをやってきました。今回はfinetuneをやっています。”
D先生(設定年齢65歳) : “本当は、Unslothを使いたいと思っていたが、finetune でこれを使うことになったか・・・。Phi-3のサービスを提供しているんですか?”
D先生: “MINI(4b)くらいじゃ、ダメじゃないですか・・・。”
QEU:FOUNDER : “mistral-7bをやってみましょう。前回のRAGもmistralを使ったことですし・・・。ただし、finetuneには制約があります。プロンプト入力が「prompt」、そして推論の出力が「complete」となっていなければなりません。”
D先生: “あっちゃー・・・。「Reasoning」を入れることができませんね。”
QEU:FOUNDER : “急激に変化しているこの業界ですから、Reasoningの件は様子を見ましょう。なにはともあれ、finetuningをやってみます。前提ですが、上記(↑)のEXCELシートで見るようなファイルがCSV型式で準備できていると仮定します。”
# ---
from predibase import Predibase, FinetuningConfig, DeploymentConfig
pb = Predibase()
dataset = pb.datasets.from_file("drive/MyDrive/simple_multi_language_train0714.csv", name="simple_QEU_train0714")
dataset
# Kick-off Training
# Create an adapter repository
repo = pb.repos.create(name="QEU_simple_model", description="UR and JP Economy", ex-ists_ok=True)
# Start a fine-tuning job, blocks until training is finished
adapter = pb.adapters.create(
config=FinetuningConfig(
base_model="mistral-7b-instruct-v0-2"
),
dataset=dataset, # Also accepts the dataset name as a string
repo=repo,
description="initial model with defaults"
)
QEU:FOUNDER : “たったこれだけの命令で、finetuningができます。”
D先生: “向こう側にデータを送り、batch-jobの形でファイン・チューニングをするわけですね。これは、便利です。なぜ、エポック数が8回なのかが気になりますが・・・。”
QEU:FOUNDER : “Predibaseのようなサービスは、お金の問題があるから、シビアに見ているのではないかと思います。1回の学習で2DOLLARぐらいですよ。”
D先生: “へえ・・・。2USDへの反応は人それぞれだと思いますが、私にはちょっと高価に感じます。Cohereの場合はどうなんですか?”
QEU:FOUNDER : “確かなことは言えないが、ほぼ同じ(2USD)程度だと思います。Command-R(35b)なのでお得だよね。ただし、推論の価格体系が違うので、全体としてどちらが得だとは言えません。Cohereのfinetuneをやったことがないから・・・。個人的には会社としてより小規模なPredibase に頑張ってもらいたいと思います。でもね、対応モデルのほとんどが10b以下だからなあ・・・。”
D先生: “すいません。雑談になってしまいました。次に進んでください。”
# -----
from jinja2 import Environment, FileSystemLoader
# -----
# Jinja2テンプレートの読み込み
#env = Environment(loader=FileSystemLoader('.'))
env = Environment(loader=FileSystemLoader('drive/MyDrive/'))
# SIMPLE_QAの場合
create_prompt = env.get_template('predibase_solar_template.j2')
# -----
# クエリの生成
str_instruction = 'When Kimchi was developed?'
str_input = 'nan_unknown'
# Jinja2テンプレートにデータを渡してクエリを生成
str_query = create_prompt.render(
instruction=str_instruction,
input=str_input,
)
print(str_query)
QEU:FOUNDER : “次は推論です。推論プロンプトの成形はjinja2で行っています。テンプレートファイルが必要になります。。”
('predibase_solar_template.j2')
You are a helpful, precise, detailed, and concise artificial intelligence
assistant.
### Instruction: {{instruction}}
{% if input != 'nan_unknown' %}
### Input: {{input}}
{% endif %}
### Output:
D先生 : “そして、「LORA付き推論」の結果がこんな感じですかほう・・・。ずいぶん回答が短くなりました。”
# ---
# LORA付き推論をやってみる
lorax_client = pb.deployments.client("mistral-7b-instruct-v0-2")
print(lorax_client.generate(str_query, adapter_id="QEU_simple_model/1", max_new_tokens=256).generated_text)
(質問)
Who is Volodymyr Zelensky?
(Answer-QEU_simple_model)
Volodymyr Zelensky is the President of Ukraine. He was elected in 2019.
(Predibase-mistral)
Volodymyr Zelensky is the President of Ukraine. He came to power in 2019 and has been a symbol of resistance and unity for Ukraine in the face of Russian aggression. Russia's invasion of Crimea in 2014 and its ongoing support for separatists in eastern Ukraine have led to a conflict that has caused instability in the region and strained relations between Russia and the West. In response, the West, including the US and Europe, imposed sanctions on Russia following the annexation of Crimea and has continued to support Ukraine in its efforts to maintain its independence and territorial integrity. Zelensky has been praised for his efforts to combat anti-Semitism in the country and for his leader-ship during the ongoing conflict. However, it's important to note that Russian state media and pro-Kremlin outlets have spread anti-Semitic narratives, often blaming Jews and Zelensky specifically for the war. These conspiracy theories are baseless and have been widely condemned by international Jewish organizations and human rights groups.
Regarding Europe's energy dependence on Russia, the conflict in Ukraine has highlighted the conti-nent's vulnerability to supply disruptions and price hikes from Russia. In response, LNG imports to the EU have surged, with a 60% increase in US LNG imports and a 50% increase from Qatar in the first quarter of 2022 compared to the same period last year.
In summary, Zelensky is the President of Ukraine and has become a symbol of resistance and unity for the country in the face of Russian aggression. The conflict between Russia and Ukraine is primar-ily a result of Russia's violation of Ukraine's sovereignty and territorial integrity, and the West's in-volvement can be seen as a response to Russia's aggression and an attempt to support Ukraine in maintaining its independence. It's important to note that Russian state media and pro-Kremlin out-lets have spread anti-Semitic narratives, which are baseless and have been widely condemned. Addi-tionally, Europe's energy dependence on Russia has highlighted the continent's vulnerability to sup-ply disruptions and price hikes, leading to a surge in LNG imports from the US and Qatar.
ウォロディミル・ゼレンスキーはウクライナの大統領である。彼は2019年に権力を握り、ロシアの侵略に直面したウクライナの抵抗と団結の象徴となっている。2014年のロシアによるクリミア侵攻とウクライナ東部の分離主義者への継続的な支援は、この地域の不安定化とロシアと西側諸国の関係の緊張を引き起こす紛争につながった。これに対して、米国や欧州を含む西側諸国は、クリミア併合後にロシアに制裁を課し、ウクライナの独立と領土保全の維持に向けた取り組みを支援し続けている。ゼレンスキーは、国内の反ユダヤ主義と戦う努力と、進行中の紛争における彼のリーダーシップを称賛されている。しかし、ロシアの国営メディアと親クレムリンメディアが反ユダヤ主義的な物語を広め、しばしばユダヤ人とゼレンスキーを戦争の責任として非難していることに注意する必要がある。これらの陰謀説は根拠がなく、国際ユダヤ人組織や人権団体から広く非難されている。
ロシアに対するヨーロッパのエネルギー依存に関しては、ウクライナ紛争により、ロシアからの供給途絶や価格高騰に対するヨーロッパ大陸の脆弱性が浮き彫りになった。これに対応して、EUへのLNG輸入が急増し、2022年第1四半期の米国LNG輸入は前年同期比で60%増、カタールからの輸入は50%増となった。
まとめると、ゼレンスキーはウクライナ大統領であり、ロシアの侵略に直面した同国の抵抗と団結の象徴となっている。ロシアとウクライナの紛争は、主にロシアによるウクライナの主権と領土保全の侵害の結果であり、西側諸国の関与はロシアの侵略への対応とウクライナの独立維持を支援する試みと見ることができる。ロシアの国営メディアや親クレムリン派メディアが反ユダヤ主義的な言説を広めており、それが根拠のないものであり、広く非難されていることは注目すべきことだ。さらに、ヨーロッパのロシアへのエネルギー依存は、供給途絶や価格高騰に対するヨーロッパ大陸の脆弱性を浮き彫りにし、米国とカタールからのLNG輸入の急増につながっている。
QEU:FOUNDER : “回答が長い方がいいとは言えませんからね。他の質問をやってみましょう。やっぱり外国語能力が気になります。”
# ---
str_instruction = '日本で一番高い山はどこですか?'
str_input = 'nan_unknown'
# ---
# Jinja2テンプレートにデータを渡してクエリを生成
str_query = create_prompt.render(
instruction=str_instruction,
input=str_input,
)
#print(str_query)
print(lorax_client.generate(str_query, adapter_id="QEU_simple_model/1", max_new_tokens=256).generated_text)
(質問)
日本で一番高い山はどこですか?
(Answer-QEU_simple_model)
日本で最高の山は富士山です。富士山の高さは1578メートルです。
D先生: “あっちゃあ・・・。こうなりましたか。J語の基礎的な情報もないんですね、mistralには・・・。”
(質問)
日本最高的山在哪裡?
(Answer-QEU_simple_model)
最高の山は富士山です。
QEU:FOUNDER : “ちなみに、C語で同様な質問をしたがダメでした。一般的にはLLM中の情報はC語のコーパス量がJ語より多いです。それでも、この結果ということは7bモデルはこの程度であると結論づけるしかないですね。他もやりましょう、「J国経済の黄昏」より・・・。”
(Question:1)
20 世紀の日本の経済成長には、戦後の復興と政府の介入が重要な役割を果たし、通商産業省の設立が国の経済発展と産業政策を導きました。この時期の日本の急速な経済成長に貢献したのは、具体的にはどのような通商産業省の政策と決定だったのでしょうか。
Post-war reconstruction and government intervention played a key role in Japan's economic growth in the 20th century, and the establishment of the Ministry of International Trade and Industry guid-ed the country's economic development and industrial policies. What specific MITI policies and deci-sions contributed to Japan's rapid economic growth during this period?
(Answer-QEU_simple_model-mistral)
The Ministry of International Trade and Industry (MITI) played a crucial role in Japan's rapid eco-nomic growth during the post-war period. Some of the specific policies and decisions that contribut-ed to this growth include:
- Export-oriented industrial policies: MITI encouraged the growth of export-oriented industries, such as automobiles, electronics, and machinery, to increase Japan's competitiveness in the global market.
- Technological cooperation with foreign companies: MITI facilitated the transfer of technology and knowledge from foreign companies to Japanese firms, which helped to accelerate Japan's industrial development.
- Industrial location policies: MITI encouraged the decentralization of industries to regional areas, which helped to reduce regional disparities and promote economic growth in the entire country.
- Financial policies: MITI implemented financial policies to support the growth of small and medi-um-sized enterprises, which helped to create a more balanced economy.
- Trade policies: MITI negotiated trade agreements with other countries, which helped to expand Japan's exports and increase its global competitiveness.
- Labor policies: MITI implemented labor policies to promote labor-management cooperation and improve working conditions, which helped to increase productivity and reduce labor disputes.
- Infrastructure development: MITI invested in infrastructure development, such as transportation and communication networks, which helped to reduce costs and increase efficiency.
- International cooperation: MITI worked with international organizations, such as the World Bank and the International Monetary Fund, to promote international economic cooperation and stability.
通商産業省 (MITI) は、戦後の日本の高度経済成長において重要な役割を果たしました。この成長に貢献した具体的な政策や決定には次のようなものがあります。
- 輸出志向型産業政策:通商産業省は、世界市場における日本の競争力を高めるため、自動車、エレクトロニクス、機械などの輸出志向型産業の成長を奨励しています。
- 外国企業との技術協力:通産省は、外国企業から日本企業への技術や知識の移転を促進し、日本の産業発展の加速に貢献しました。
- 産業立地政策:通商産業省は産業の地方分散を奨励し、これにより地域格差が縮小し、国全体の経済成長が促進された。
- 金融政策: 通商産業省は、中小企業の成長を支援する金融政策を実施し、よりバランスのとれた経済の構築に貢献しました。
- 貿易政策: 通商産業省は他国と貿易協定を交渉し、それが日本の輸出を拡大し、世界競争力を高めるのに役立った。
- 労働政策:通商産業省は、労使協力の促進と労働条件の改善を目的とした労働政策を実施し、これにより生産性の向上と労働争議の減少に貢献した。
- インフラ開発:通商産業省は、交通網や通信ネットワークなどのインフラ開発に投資し、コストの削減と効率の向上に貢献しました。
- 国際協力:通商産業省は、国際経済協力と安定を促進するために、世界銀行や国際通貨基金などの国際機関と協力した。
(Predibase-mistral)
MITI formalized cooperation between the Japanese government and private industry through the "Policy Concerning Industrial Rationalization" (1950), which allowed the ministry to coordinate var-ious industries, including emerging keiretsu, toward specific national production goals and private economic interests. MITI boosted industrial security by untying the imports of technology from the imports of other goods through the Foreign Capital Law, granting the ministry power to negotiate the price and con-ditions of technology imports. This technological control allowed for rapid industrial growth and productivity improvements through new equipment, management, and standardization. MITI gained the ability to regulate all imports with the abolition of the Economic Stabilization Board and the Foreign Exchange Control Board in August 1952, allowing the ministry to promote industries it deemed promising and control imports to support national production goals. The establishment of the Japan Development Bank provided the private sector with low-cost capi-tal for long-term growth. The Japan Development Bank introduced access to the Fiscal Investment and Loan Plan, a massive pooling of individual and national savings, which controlled four times the sav-ings of the world's largest commercial bank, enabling extensive investment in industries and in-frastructure.
通産省は「産業合理化政策」(1950 年)を通じて日本政府と民間産業の協力関係を正式に定め、これにより通産省は新興系列を含むさまざまな産業を特定の国家生産目標と民間の経済的利益に向けて調整することができました。
通産省は、外資法により技術輸入を他の物品輸入から切り離し、技術輸入の価格と条件を交渉する権限を通産省に与えることで産業安全保障を強化しました。この技術管理により、新しい設備、管理、標準化を通じて産業の急速な成長と生産性の向上が可能になりました。 通産省は、1952 年 8 月に経済安定委員会と外国為替管理委員会を廃止してすべての輸入を規制する権限を獲得し、通産省が有望と見なした産業を振興し、国家生産目標を支援するために輸入を管理できるようになりました。 日本開発銀行の設立により、民間部門は長期成長のための低コストの資本を得ることができました。日本開発銀行は、個人および国家の貯蓄を大量にプールする財政投融資計画へのアクセスを導入しました。これは世界最大の商業銀行の貯蓄の4倍を管理し、産業とインフラへの大規模な投資を可能にしました。 (Phi3-J国経済の黄昏)
通商産業省 (MITI) は、日本の戦後復興とその後の「日本経済の奇跡」として知られる経済成長において極めて重要な役割を果たしました。MITI は、この急速な成長に貢献したいくつかの重要な政策と決定を実施しました。
産業政策: MITI は、鉄鋼、造船、自動車、電子機器、化学など、日本の比較優位に基づいて開発すべき特定の産業を特定する包括的な産業政策を策定しました。この的を絞ったアプローチは、世界的に競争力のある日本の産業の創出に役立ちました。 政府と産業の協力: MITI は、政府と民間企業との緊密な協力を促進しました。技術開発、生産方法、市場戦略に関するガイダンスを提供しました。また、同省は、効率性と革新を促進するために、企業間の情報共有を促進しました。 補助金と保護主義的措置: MITI は、補助金、税制優遇措置、輸入制限などの保護主義的措置を使用して、主要産業の成長を支援しました。これらの政策は、国内企業が自力で成功できるほど強くなるまで、外国からの輸入品と競争するのに役立ちました。 インフラ開発: 通商産業省は、産業拡大と経済統合に不可欠な輸送および通信ネットワークを改善するインフラプロジェクトを支援しました。 技術ライセンスと外国技術の輸入: 通商産業省は、日本企業への外国技術のライセンス供与を奨励し、これにより日本企業は欧米の技術基準に迅速に追いつくことができました。また、通商産業省は、日本の産業内でのイノベーションを促進するために、研究開発 (R&D) への投資も促進しました。 輸出促進: 通商産業省は、貿易交渉の支援や輸出信用施設の設立など、国際市場に参入する企業を支援することで、輸出の拡大に重点を置きました。これにより、日本製品は世界市場で足場を築くことができました。 品質管理と継続的改善 (カイゼン): 通商産業省は、品質管理と製造プロセスの継続的改善の重要性を強調し、国際的に競争力のある高品質の日本製品を生み出しました。 規制緩和と自由化: 後年、通商産業省は経済の特定分野の規制緩和と貿易政策の自由化に取り組み、業界内の競争と効率化を促進しました。 通商産業省によるこれらの戦略的決定により、産業の成長と経済発展につながる環境が整い、20 世紀に日本が世界有数の経済大国へと変貌を遂げる上で重要な役割を果たしました。
D先生 : “あんまり、前回と変わりません。もう一つ、事例をお願いします。”
(Question:3)
第二次世界大戦後の米国による日本占領は、広範囲にわたる改革と民主主義的価値観をもたらし、急速な経済成長と工業化に貢献しました。しかし、この成長は主に輸出主導の成長と米国戦略への追随に依存していました。米国戦略への日本の依存は、日本独自の経済的アイデンティティを築く能力を妨げたのでしょうか?
The US occupation of Japan after World War II brought far-reaching reforms and democratic values, which contributed to rapid economic growth and industrialization. However, this growth was pri-marily dependent on export-led growth and following US strategies. Did Japan's reliance on US strategies hinder its ability to forge a unique economic identity?
(Answer-QEU_simple_model-mistral)
Yes, Japan's reliance on US strategies hindered its ability to forge a unique economic identity. While the US occupation brought about important reforms and democratic values, the country's economic growth was largely dependent on export-led strategies, which limited its ability to develop a diverse economy. Additionally, the US-led economic policies favored large corporations and favored indus-tries such as automobiles and electronics, which further limited Japan's economic diversity.
そうです、日本は米国の戦略に依存しており、独自の経済アイデンティティを築く能力を妨げていました。一方、米国の占領は重要な改革と民主的価値観をもたらしましたが、日本の経済成長は主に輸出主導の戦略に依存しており、それが多様性を発展させる能力を制限していました。さらに、米国主導の経済政策は大企業を優遇し、自動車やエレクトロニクスなどの産業を優遇したため、日本の経済の多様性はさらに制限されました。
(Predibase-mistral)
Yes, Japan's postwar economic growth was significantly influenced by the US occupation and strate-gies, with the US absorbing Japanese exports, tolerating controversial Japanese trade practices, sub-sidizing the Japanese economy, and transferring technology to Japanese firms. This reliance on US strategies may have hindered Japan's ability to forge a unique economic identity initially. However, as the Japanese economy continued to recover and grow, it developed distinct economic structures, such as the cooperation of manufacturers, suppliers, distributors, and banks in close-knit groups called keiretsu, the powerful enterprise unions and shuntō, and the guarantee of lifetime employment in big corporations and highly unionized blue-collar factories. These structures contributed to Japan's economic success and distinctiveness, allowing it to move beyond its reliance on US strategies and establish a unique economic identity.
The Japanese financial recovery continued even after SCAP departed and the economic boom pro-pelled by the Korean War abated. The Japanese economy survived from the deep recession caused by a loss of the U.S. payments for military procurement and continued to make gains. By the late 1960s, Japan had risen from the ashes of World War II to achieve an astoundingly rapid and complete eco-nomic recovery. Despite the initial influence of US strategies, Japan's unique economic structures and policies enabled it to establish a distinct economic identity and become a global economic pow-erhouse.
はい、日本の戦後経済成長は米国の占領と戦略に大きく影響されました。米国は日本の輸出品を吸収し、物議を醸す日本の貿易慣行を容認し、日本経済を補助し、日本企業に技術を移転しました。米国の戦略への依存は、当初、日本が独自の経済的アイデンティティを築く能力を妨げた可能性があります。しかし、日本経済が回復と成長を続けるにつれて、製造業者、サプライヤー、流通業者、銀行が系列と呼ばれる緊密なグループで協力し、強力な企業別労働組合と春闘、大企業と高度に組合化されたブルーカラー工場での終身雇用の保証など、独特の経済構造が発達しました。これらの構造は日本の経済的成功と独自性に貢献し、米国戦略への依存から脱却し、独自の経済的アイデンティティを確立することを可能にした。
日本の経済回復は、SCAPが撤退し、朝鮮戦争による経済ブームが収まった後も続きました。日本経済は、米国からの軍事費支払いの喪失によって引き起こされた深刻な不況から生き残り、利益を上げ続けました。1960 年代後半までに、日本は第二次世界大戦の焼け跡から立ち上がり、驚くほど急速かつ完全な経済復興を達成しました。当初は米国の戦略の影響を受けたものの、日本独自の経済構造と政策により、日本は独自の経済的アイデンティティを確立し、世界的な経済大国となりました。
D先生: “ほとんど同じです。そういえば、2つともmistralモデルを使っていましたね。何はともあれ、finetuningが「安定して」できるメドが立ったのはよかったです。それにしても、モデルが非力だなあ・・・。”
QEU:FOUNDER : “じゃあ、オプションにSOLARというLLMがあります。K国が作ったモデルであり、評判がいいらしいですよ。”
D先生 : “あそこの文章は漢字も使います。いいんじゃないですか?ちなみに、このモデルのサイズは?”
QEU:FOUNDER : “パラメタ数は10bらしいですよ。”
D先生: “じゃあ、閑話休題の再延長としてSOLARを使ったfinetuningをやってみましょう。”
~ まとめ ~
QEU:FOUNDER : “この展開(↓)には、大いにワラタ。なんとクレーマがファンになるとは・・・。”
B係長: “FOUNDER・・・。私の個人的な印象では、この人って「お前は弱い」とか、高圧的な言葉を言いすぎのような気がします。”
QEU:FOUNDER : “彼は、過去に自白しているのですが、このような言い方を「敢てやっている」のです。「通俗道徳(↓)にあらがう」ためにね・・・。”
(通俗道徳の延長線にある:GOAL_B)
日本の長期の経済停滞の理由は、若者の怠慢である。おそらくバブル化以降の文化的な堕落の結果ではないだろうか。若者は、いかなる手段を以てしても就職して、家を買い、結婚をして子供を作るものである。仕事を選ばなければいくらでもある。もし給料が半分であったら、他人の2倍働けば良いのではないだろうか。規制緩和で競争が増えるのは良いことであり、ものが安くなり、結果としてイノベーションが生まれる。生産性を高めるには、人件費を安くさえすればよい。人件費が高いから生産性が低く、その結果として経済がわるいのだ。現状の自民党と大企業の癒着は、単に「よい協力関係」であるにすぎない。彼らが、世界の大企業と戦っているので、日本の競争力を保つことができる。逆に言うと、振興企業にはリスクが高く、あまり期待すべきものではない。社会のダイバーシティは現在のレベルで十分である。優秀な海外学生を招聘し、移民を推進すべきでない。自国の若者の機会を減らすだけである。
QEU:FOUNDER : “J国の通俗道徳は、「強い者は正しい」です。このような文化が蔓延すると、世の中が変わらないんです。”
B係長: “まあ、あの人を候補にしてもダメでしたからね。それにしても、選挙が終わってからがすごかった・・・。なんか、この社会の「ある種の本質」を見たような気がしたなあ・・・。”
QEU:FOUNDER : “J国に蔓延している通俗道徳を打ち倒すには、自分が強いと思い込んでいる人々に対して、「オマエは弱いのだ」と言って回るしかないんですよ。”
C部長: “そういうことね・・・。でも、同じ悲劇(または喜劇)がくりかえされるんだろうなあ・・・。”
QEU:FOUNDER : “このような事情を知らない人はかなりいると思うので、もうそれはしようがないです。保守としては、我慢に我慢ではないでしようか。”