QEUR23_PHI2SFT27: よりAGIらしく改造する(テキスト生成)
~ 少し、AGIらしいモノを開発してしまった・・・。 ~
QEU:FOUNDER(設定年齢65歳) : “前回までで、かなり良さげな「Question to Questionシステム」が出来たわけですが、ちょっと「欲を出して」、もうちょっとだけ改善しましょう。”
D先生(設定年齢65歳) : “「Question to Questionシステム」なんて、もうそんなに「うざったい言い方」なしで、率直にAGI(自律型AI)と言ったほうがいいんじゃないですか?両者の差異は「モノの価値に対しての考慮」だけでしょう?”
(モノの価値とは)
- (生活が、仕事が)便利になる
- 自分を変えることができる
- モノがあると快適、楽しい
- パーソナリゼーション
QEU:FOUNDER : “まあ、いいや・・・。これからは「簡易AGI」と、これから呼ぶことにしましょう。ちなみに、今回の改造で、さらにAGIに似てきますから・・・。”
# ----
#2022年に始まったロシアとウクライナ間の戦争について論じたい。同時に、この戦争に欧米諸国とユダヤ民族がどのようにかかわっているか、及びこの戦争が与える世界政治と経済への影響を分析したい。
str_concept = "I would like to discuss the war between Russia and Ukraine that began in 2022. At the same time, I would like to analyze how Western countries and the Jewish people are involved in this war, and the impact this war has on world politics and the economy."
#ロシアとウクライナの二国は歴史と文化、経済を大きく共有しており、もともとは戦争する積極的な理由がない。さらには、両国には天然資源、GDPと軍事力の差が圧倒的であり、ウクライナには勝ち目はありません。NATOや西側諸国がウクライナに支援をしているために戦争は続いているが、今後も支援が継続されるかは疑わしい。この戦争は、世界経済に大きな悪影響を及ぼしています。中東諸国やBRICS諸国の中には、この戦争を契機に欧米に対する不信感が増加しているかもしれません。ウクライナは停戦を推進するべきです。ウクライナのゼレンスキー大統領の「抵抗する」という発言に対して、抗戦すればするほど自国民の犠牲が増えると警告します。愛国心は自国民を守る賢明な戦略であるべきです。ウクライナの未来の発展が戦争によって奪われ、犠牲と損害、心の痛みを背負うのはウクライナ国民です。
str_goal = "Russia and Ukraine share much in common in history, culture, and economy, and originally there was no positive reason for war. Furthermore, the two countries have overwhelming differences in natural resources, GDP, and military power, and Ukraine has no chance of winning. The war continues because NATO and Western countries are providing support to Ukraine, but it is doubtful that this will continue. This war has had a huge negative impact on the world economy. Some Middle Eastern and BRICS countries may be experiencing increased distrust of the West as a result of this war. Ukraine should push for a ceasefire. In response to President Zelenskiy's statement that he will 'resist,' he warns that the more he resists, the more his own people will suffer. Patriotism should be a wise strategy to protect one's own people. Ukraine's future development was taken away by the war, and it is the Ukrainian people who bear the burden of sacrifice, damage, and heartache."
D先生: “あれ?今回から「CONCEPT」と「GOAL」を追加しましたね。この2つの概念は、AGIの運用で必要になる情報でしょう?”
QEU:FOUNDER : “(AGIの開発を)やってみればわかるが、この2つの情報が得られれば、基本AGIができるんですよ。それでは、プログラムをドン!!”
# -----
# [プロジェクト初期化用,改造版]Groqを使って、簡単にQuestion to Question を試す
# -----
import os
import re
import math
# ---
import pandas as pd
import numpy as np
from langchain_core.prompts import ChatPromptTemplate
from langchain_groq import ChatGroq
# -----
# 使う前にGroqに登録し、APIコードをもらってね
os.environ["GROQ_API_KEY"] = "gsk_jg自分でAPIコードを取ってね"
# Llama 3 with Groq
#llm = ChatGroq(temperature=0, model_name="llama3-70b-8192")
llm = ChatGroq(temperature=0, model_name="Llama3-8b-8192")
# -----
# AGIによるChain推論を行う
# -----
# システムメッセージの一覧
# -----
sys_message_AIassistant = "You are an AI assistant who is good at providing answers in multiple languages."
#sys_message_translator = "You are translator who is fluent in multiple languages.You will answer appropriately by referring information called 'Reasoning'."
#sys_message_creator = "You are creator who create amazing content with your free ideas. You at-tract readers with your beautiful writing such as novel or advertisement. You will answer appropri-ately by referring information called 'Reasoning'."
#sys_message_logician = "You are an excellent logician and are instructing users on \"thinking pro-cedures for providing better quality reasoning to user-provided questions.\". "
# ---
# 初期設定(パイプライン)
system = sys_message_AIassistant
human = "{text}"
prompt = ChatPromptTemplate.from_messages([("system", system), ("human", human)])
chain = prompt | llm
# ----
str_concept = "I would like to discuss the war between Russia and Ukraine that began in 2022. At the same time, I would like to analyze how Western countries and the Jewish people are involved in this war, and the impact this war has on world politics and the economy."
str_goal = "Russia and Ukraine share much in common in history, culture, and economy, and origi-nally there was no positive reason for war. Furthermore, the two countries have overwhelming dif-ferences in natural resources, GDP, and military power, and Ukraine has no chance of winning. The war continues because NATO and Western countries are providing support to Ukraine, but it is doubtful that this will continue. This war has had a huge negative impact on the world economy. Some Middle Eastern and BRICS countries may be experiencing increased distrust of the West as a result of this war. Ukraine should push for a ceasefire. In response to President Zelenskiy's statement that he will 'resist,' he warns that the more he resists, the more his own people will suffer. Patriotism should be a wise strategy to protect one's own people. Ukraine's future development was taken away by the war, and it is the Ukrainian people who bear the burden of sacrifice, damage, and heartache."
# INSTRUCTIONの生成
# 以下のコンセプト(「CONCEPT」)と結論(「GOAL」)を掲げて論文を書きたい。論文の各章のタイトルを生成してください。その論文の章の数は 10 である必要があります。論文の章タイトルは疑問文でなければなりません。10つの疑問文を出力する形式は「[],[],...」というリスト型式である必要があります。
str_instruction = f"""I would like to write a paper with the following concept ("CONCEPT") and conclusion ("GOAL"). Generate titles for each chapter of your paper. The number of chapters in the paper must be 10. The chapter titles of the dissertation must be interrogative sentences. The format for outputting 10 questions must be a format of \"['Question1'],['Question2'],...\"".
CONCEPT```
{str_concept}
```
GOAL```
{str_goal}
```
"""
# ---
print(str_instruction)
# ---
# 推論する(STEP0) - Question(Step1)を生成する
# ---
response = chain.invoke({"text": str_instruction})
#print(response.content)
# ----
# Question(Step1)リストを抽出する
# 正規表現パターンを定義
pattern = r'\[\'(.*?)\'\]'
# 正規表現を使ってarr_questionから疑問文を抽出
arr_questions = re.findall(pattern, response.content)
# 抽出した疑問文をリストで表示
print(arr_questions)
# ---
# 推論する(STEP1) - Answer(Step1) : Question(Step1)への簡単な回答
# ---
num_df = len(arr_questions)
arr_output_no1 = []
for i in range(num_df): # len(df)
str_instruction = f"""
Please answer the following 'QUESTION'. After thinking in different languages you have already known, summarize your thoughts, and write your final answer in English. Please an-swer the summarized answer in English only.
QUESTION```
{arr_questions[i]}
```
"""
#print(arr_questions[i])
response = chain.invoke({"text": str_instruction})
temp_response = response.content
#temp_response = temp_response.split(":\n\n")[1]
str_response = temp_response.replace("**", "")
arr_output_no1.append(str_response)
print(str_response)
# ---
print("--- 以下は、Answer(Step1)の一覧です ---")
print(arr_output_no1)
# ---
# 推論する(STEP2) - Answer(Step1)をもとにQuestion(Step2)を生成
# ---
arr_output_no2 = []
for i in range(num_df): # len(df)
#str_instruction = "以下の情報をもとにして、より議論を深めることができる5つの質問を生成してください。生成された5つの質問は、'[Question1],[Question2]...'の型式で出力してください。"
str_instruction = f"""Use the information('CONTENT' and 'CONCEPT') below to generate five questions that can further deepen the discussion.
Please output the five generated questions in the format of \"['Question1'],['Question2'],...\".
CONCEPT```
{str_concept}
```
CONTENT```
{arr_output_no1[i]}
```
Please response in English.
"""
print(arr_output_no1[i])
response = chain.invoke({"text": f"{str_instruction}"})
str_response = response.content
str_response = str_response.replace("""?',
'""","?'], ['")
arr_output_no2.append(str_response)
print(str_response)
# ---
print("--- 以下は、Question(Step2)の一覧です ---")
print(arr_output_no2)
# ---
# Question(Step2)の質問(結果)を加工する
# ---
# 2次元リストを生成する
acc_questions = [["NG"]*5 for i in range(num_df)]
#print(acc_questions)
# ---
for i in range(num_df): # len(df)
str_questions = arr_output_no2[i]
# ----
# Question(Step1)リストを抽出する
# 正規表現パターンを定義
#pattern = r'\[\'(.*?)\'\]'
# 正規表現を使ってarr_questionから疑問文を抽出
arr_questions_no2 = re.findall(pattern, str_questions)
#print(arr_questions_no2)
# ----
len_question_no2 = len(arr_questions_no2)
for j in range(len_question_no2):
acc_questions[i][j] = arr_questions_no2[j]
#print(arr_questions_no2[j])
# ----
# numpy配列化
acc_questions = np.array(acc_questions)
#print(acc_questions)
# ----
# データフレームを生成する
arr_columns = ['Q1','Q2','Q3','Q4','Q5']
df = pd.DataFrame(acc_questions, columns=arr_columns)
df
# ----
# 結果の出力
df_out = df.copy()
df_out.loc[:,"Question(Step1)"] = arr_questions
df_out.loc[:,"Answer(Step1)"] = arr_output_no1
df_out.loc[:,"Question(Step2)"] = arr_output_no2
df_out
# ---
# データフレームからExcelファイルを作成する
df_out.to_excel("qq_for_UR_step1_output.xlsx")
D先生: “llama3のレベルでは多言語の実力が追い付かないと思い、E語で推論してから別途翻訳をやっています。もちろん、他のやり方を使ってJ語をいきなり出力してもいいです。どうです?今回の出来栄えは?Step2の質問は、前回のトライアルより断然に深くなったでしょ?”
QEU:FOUNDER : “もちろん。ついでに、前回で紹介したプログラムを使って要約をしましょう。。”
--- 以下、Step1の概要文です ---
質問に対する回答を 7 つの段落にまとめたものは次のとおりです。
2022 年にロシアとウクライナの間で戦争が勃発したのは、歴史的、政治的、地政学的な要因が複雑に絡み合った結果です。 この紛争は、歴史的緊張、クリミア併合、ウクライナ東部で進行中の紛争、ロシアの軍備増強、外交的失敗によって煽られた。 紛争への西側諸国とユダヤ人の関与は大きく、双方とも自らの行動や政策を通じて紛争の永続に貢献している。
ロシアとウクライナの歴史的、文化的、経済的関係は深く絡み合っており、複雑です。 両国は、ウクライナが東方正教会とキリル文字の発祥の地であるという共通の遺産を共有しています。 両国には文学と芸術の交流の長い伝統があり、言語も密接な関係があります。 両国はパイプライン、鉄道、高速道路のネットワークでも結ばれており、貿易と商業が促進されています。
国家的、地政学的、国内的要因が複雑に絡み合ったために、明らかに不利な状況にもかかわらず、ウクライナ戦争は続いた。 独立と主権を維持するというウクライナの決意が紛争継続の原動力となったが、国際的な支援や地政学的な考慮も役割を果たした。
NATOは、1991年のウクライナ独立以来、ウクライナ支援において重要な役割を果たしてきました。NATO同盟は、ウクライナがロシアの侵略に対抗できるよう軍事援助、訓練、能力開発プログラムを提供してきました。 NATO の支援は、軍事援助、訓練と能力開発、政治的支援、経済的支援を含むさまざまな手段を通じて維持されてきました。
戦争は世界経済に大きな影響を与え、サプライチェーン、貿易、投資に広範な混乱を引き起こしました。 その影響は、エネルギー価格の上昇、サプライチェーンの混乱、投資家の信頼の低下、大規模な人道危機など、広範囲かつ多面的です。
中東紛争における西側諸国の行動は、中東諸国やBRICS諸国からの不信感を高める一因となっている。 西側諸国の偽善と二重基準の認識は、不信感と憤りの増大につながっています。 戦争による人的コストは多面的かつ広範囲に及び、個人、家族、地域社会全体に影響を及ぼします。
停戦は特定の紛争シナリオでは実行可能な解決策となる可能性があり、暴力の削減、対話の機会の創出、人道支援の提供など、いくつかの利点がもたらされます。 しかし、解決策として停戦を追求する前に、停戦の状況と停戦の潜在的な結果を注意深く検討することが不可欠です。 ウクライナの将来には計り知れない可能性が秘められているが、経済改革、制度強化、インフラ開発、教育とイノベーション、地域協力、紛争解決、汚職撲滅の取り組みに重点を置くことで、現在の課題に取り組み、発展軌道を取り戻すことが同国にとって極めて重要である。
D先生: “これだけで小論文になっているんじゃないですか?すでに、この段階でこのプログラムはAGIになっているとは言えます。もちろん、もうちょっと内容を深めたいですね。次は、Step2の質問を評価・選択・回答し、Step3の質問につなげたいですね。簡易AGIシステムの評価モジュールも、今回の改造とともに変わったんですか?”
QEU:FOUNDER : “GOALが明示されたので、これをもとにプロジェクトの進捗が評価できるようになります。次に評価システムを改造しましょう。カンパをお願いします。よろしくお願いします。”
>寄付のお願い(click here for buy me a cup of coffee)<
D先生: “このシステム、いいですよ・・・。解説系のYoutuberが使うと、すぐにコンセプトがまとまって便利だと思います。”
~ まとめ ~
・・・ 前回のつづきです ・・・
C部長 : “いままでの話をA国にもどすと、「ユニコーン企業(Unicorn company)」とはC国における食客であり、J国の失敗事例でいうと「ボランティアの管理」ですね。はぁ~・・・。J国はかわるんですかねぇ・・・?”
QEU:FOUNDER : “C国から数千万人来ればかわるんじゃない?J国人の高い適応能力(↓)をすぐに発揮して、すぐに世の中が変わっていきます。実は、1990年代に変化する機会があったんじゃないかと思います。今を思えば・・・。”
C部長 : “そんな大チャンスがあったんですか?”
QEU:FOUNDER : “あのころ、経営学の分野ではNPOの経営がテーマになっていたはずです。スタートアップ企業って、その本質がNPOに極めて類似しているはずだから、その成果が社会的に展開されていれば面白いことになっていたはずだよ。”
C部長 : “私は、その点には半信半疑ですが・・・。”
QEU:FOUNDER : “それは分からんでもない。・・・でも、生き残るためにはやらねばならない。自国の文化にないのであれば、演繹的に必要と判断して、むりやり外から導入するしかないでしょ?J国って、人文系の学問をひたすら「虐待」するでしょ?”
QEU:FOUNDER : “一番、役に立たない分野(↑)を除き・・・・。”
C部長 : “いやいや・・・。立派な人もいますので・・・。”
QEU:FOUNDER : “そもそも、A国から体に悪いモン(↑)を持ってきたから、体を壊したわけで・・・。”
C部長 : “あれ?「ネトウヨのアイドル」が翻訳している本もありますよ。”
QEU:FOUNDER : “でもね、出版元のA国の読者からもボロクソですからね。こんなにおかしな考え方を、バ〇が「ありがたがって」A国から持ってきたから、世の中がおかしくなったんです。”
C部長 : “今は「季節の変わり目」です。まあ、今後はどうなることやら・・・。”
コメント
コメントを投稿