QEUR23_CHRLTM33 : (STEP2-TASK3 of 3) Question to Question(QQ)の類似度評価(数理言語政治学)
~ これだから、QQは面白い ~
D先生(設定年齢65歳): “それでは、ルーチンの最終、「TASK3 of 3 in STEP2」です。前回に生成したFACT_BASED_QUESTIONを評価しましょう。”
QEU:FOUNDER(設定年齢65歳) : “・・・そんなことより、この話(↓)をしましょうよ。せっかくの歴史的な出来事なんだし・・・。”
D先生: “びっくりしましたよね。”
QEU:FOUNDER : “まあ、「美しい国では、<あるある>の出来事」かなと・・・。”
D先生: “そうですかねえ・・・。”
QEU:FOUNDER : “この暴落の後で、ちょうどNISA時と同じ金額になったんでしょう?つまり、NISAに乗っかった人のお金が、すべて「誰かさんの懐」に入ったんでしょう?詐欺でしょ?これ・・・。”
D先生: “おおっと・・・。とうとう<詐欺>って言いましたよね。”
QEU:FOUNDER : “事実(データ)を見たうえでの個人的な感想です。被害者も、自分党の支持者(オッサン)らしく、直線的なものの考え方しかできない人なんだから・・・。まあね。メディアが総出で、「時代は云々」と年中いっていれば、そういう風になるって・・・。さっき、「株価は50000円になる!」という動画を探したが、突然に消えていた・・・(笑)。そういうのって、普通は詐欺といわないの?”
D先生(設定年齢65歳): “そうねえ・・・。我々よりも少し年齢が上の人たちは、90年代に「歴史は終わった」と錯覚し、そのあとに世の中をぐしゃぐしゃにしましたからね。今回は、その頭の当人たちがもっとも多くの被害を受けています。”
QEU:FOUNDER : “今回のパニックを「<歴史の終わり>の終わりパニック」と命名したいね。ともあれ、本当のショックはもうすぐやってきます。いよいよ自動運転(↑)が来るよ!・・・ということで、本題に入りましょう。解析用のプログラムは前回と同じなので、とくにいうことはないんです。しいて言えば、「unknown」の結果が出て来たので、例外処理が増えただけのことです。”
QEU:FOUNDER : “プログラムの一部が、「ちょっと」かわった(↓)だけ・・・。”
# -----
#import cohere
#co = cohere.Client("COHERE_API_KEY") # Your Cohere API key
co = cohere.Client() # Your Cohere API key
# -----
# Creating Embedding(arrayは一次元ベクトル)
def create_embedding(str_answer):
# -----
#array_answer_A
num_answer = len(str_answer)
#print(num_answer)
response_answer = co.embed(
texts=[str_answer],
model='embed-english-v3.0',
input_type='search_document'
)
embeddings_answer = response_answer.embeddings
#print(embeddings_answer[0])
return num_answer, embeddings_answer
# -----
# Semantic類似度の計算
def eval_similarity(list_goal, mx_FBQ, num_df, num_goal, num_FBQ):
# -----
# 部分マトリックスを初期化する
part_similarity = np.zeros([num_df, num_FBQ])
# -----
# list_goal
for i in range(num_df): # num_df
# -----
arr_FBQ = mx_FBQ[i, :]
for j in range(num_FBQ): # num_FBQ
# -----
if "unknown" in arr_FBQ[j]:
part_similarity[i,j] = -1.0
print(f"--- FBA ANSWER NUMBER: {i}/{j} ---")
print(" unknown was found ")
else:
# -----
# list_goal
num_kanswer, embeddings_FBQ = create_embedding(arr_FBQ[j])
# -----
# Cosine Similarity(A-B)
arr_values = []
for k in range(num_goal): # num_goal
# -----
num_janswer, embeddings_goal = create_embedding(list_goal[k])
val_similarity = cosine_similarity(embeddings_goal, embeddings_FBQ)[0][0]
arr_values.append(val_similarity)
# -----
max_similarity = np.max(arr_values)
index_similarity = np.argmax(arr_values)
part_similarity[i,j] = max_similarity
if i%2 == 0 and j%2 == 0:
print(f"--- FBA ANSWER NUMBER: {i}/{j} ---")
print("FBQ: ", arr_FBQ[j])
print("Goal: ", list_goal[index_similarity])
print(f"Cosine similarity between sentences Goal and max_FBQ @{i}/{j}:", max_similarity)
# -----
return part_similarity
# -----
# 初めのABはGOALのこと、次のABはANSWERのこと
#part_similarity_A_A = mx_similarity[:, :,0 ,0]
#part_similarity_A_B = mx_similarity[:, :,0 ,1]
#part_similarity_B_A = mx_similarity[:, :,1 ,0]
#part_similarity_B_B = mx_similarity[:, :,1 ,1]
#print(mx_similarity_A_A[0,:])
# -----
# GOAL-AでANSWER-Aを評価する
print("--- Similarity: goal_answer_A_A ---")
part_similarity_A_A = eval_similarity(list_goal_A, mx_FBQ_A, num_df, num_goal_A, num_FBQ)
print(part_similarity_A_A[0,:])
# -----
# PARTをMXにINPUTする(part_similarity_A_A)
print("--- Similarity: goal_answer_A_A ---")
mx_similarity[:, :,0 ,0] = part_similarity_A_A
print(mx_similarity[0,:,0 ,0])
D先生: “たしか、この解析で美しいヒートマップが出るんでしたよね。コレ・・・。”
QEU:FOUNDER : “そうですよ。セットで「ANSWER_B」もみてみましょう。。”
D先生: “例によって、(両者は)あまり代り映えがしないですね。DIFF(差分)に変換してください。”

D先生: “やっと、評価が可能な様子になってきました。ANSWER_A群とANSWER_B群のそれぞれから、特徴的なモノを1つづ使うんでしたよね。いくつか、FBQの事例を見せてください。”
QEU:FOUNDER : “はいよ・・・。”
--- ANSWER_A: 8/0 ---
The G7 nations have a long history of colonialism, which has been characterized by exploitation and inequality, with the wealth of peripheral nations being transferred to the centre. This has led to a significant gap in economic development between the G7 and the Global South. What are the histori-cal and cultural ideologies that have justified the G7's colonial exploits as necessary and humane?
G7諸国は、搾取と不平等を特徴とする植民地主義の長い歴史を持ち、周辺国の富が中央に移転してきました。このため、G7と南半球の経済発展に大きな格差が生じています。G7の植民地主義的搾取を必要かつ人道的なものとして正当化してきた歴史的、文化的イデオロギーとは何でしょうか。
--- ANSWER_B: 8/3 ---
The G7's inability to resolve conflicts and the rising influence of the BRICS countries and Global South mean the old hierarchical world order is shifting. The next era will be defined by new power dynamics, with the G7's relevance diminished as they lose their stranglehold on global affairs, eco-nomics, and culture. What are the implications of this shift for the G7's traditional allies and the global economy as a whole?
G7 が紛争を解決できず、BRICS 諸国と南半球諸国の影響力が高まるということは、古い階層的な世界秩序が変化しつつあることを意味します。次の時代は新たな力関係によって定義され、G7 は世界情勢、経済、文化に対する支配力を失い、その重要性は薄れていきます。この変化は、G7 の伝統的な同盟国と世界経済全体にどのような影響を与えるのでしょうか。
D先生: “いやあ、この質問はいい味がでています!!もう少し見たい!!!”
--- ANSWER_A: 9/4 ---
Japan has never been subject to excessive interference from the G7 countries since regaining its in-dependence after World War II, and all decisions made by the Japanese government are rational de-cisions made with the interests of the Japanese people in mind. What are the historical and political factors that contribute to Japan's close relationship with the G7 countries, particularly the United States?
日本は、第二次世界大戦後に独立を回復して以来、G7諸国から過度な干渉を受けたことはなく、日本政府の決定はすべて国民の利益を考えた合理的な判断です。日本がG7諸国、特に米国と緊密な関係を保っているのは、歴史的、政治的な要因によるものなのでしょうか。
--- ANSWER_B: 9/0 ---
The BRICS countries are strengthening their military capabilities and cooperation, with China and Russia increasing their defence spending and holding joint military exercises. This challenges the G7's dominance in the military sphere. What are the underlying reasons for the BRICS countries' rapid military modernization and cooperation?
BRICS諸国は軍事力と協力を強化しており、中国とロシアは防衛費を増額し、合同軍事演習を実施している。これは軍事分野におけるG7の優位性に挑戦するものである。BRICS諸国の急速な軍事近代化と協力の根底にある理由は何でしょうか?
--- ANSWER_A: 10/4 ---
Japan's relationship with the G7 countries has been shaped by its history and geography, and the country has benefited from its alignment with the West. However, some argue that Japan's reliance on the USD and Euro for international trade limits its economic independence and flexibility. What are the potential risks and benefits for Japan of maintaining its current relationship with the G7 countries and using the USD and Euro for international trade?
日本とG7諸国との関係は、その歴史と地理によって形作られ、日本は西洋との連携から恩恵を受けてきました。しかし、国際貿易で米ドルとユーロに依存している日本は、経済の独立性と柔軟性を制限していると主張する人もいます。G7諸国との現在の関係を維持し、国際貿易で米ドルとユーロを使用することで、日本にとって潜在的なリスクとメリットは何でしょうか。
--- ANSWER_B: 10/4 ---
The US's future foreign policy direction is yet to be determined, with options existing for the country to continue along its current trajectory or to engage in meaningful cooperation with other powerful nations to address mutual concerns. What are the potential benefits and drawbacks of each approach, and how can the US balance its national interests with its global responsibilities to maintain a strong and positive reputation on the world stage?
米国の今後の外交政策の方向性はまだ決まっておらず、現在の路線を継続するか、共通の懸念に対処するために他の大国と有意義な協力関係を築くかという選択肢がある。それぞれのアプローチの潜在的な利点と欠点は何だろうか。そして、米国はどのようにして国益と世界的責任のバランスを取り、世界の舞台で強力かつ肯定的な評判を維持できるのだろうか。
D先生: “GOAL_AのFBQは、ずいぶん質がよくなりました。FBQ生成用のプロンプトを変えたんでしたっけ?”
QEU:FOUNDER : “あっ、そうか・・・。前回は説明していかなったですね。ドン。”
('FBQ_GVB_template_new.j2')
You have the following beliefs: \n
{{ str_goal }}\n\n
You are debating with a friend. Your friend has given you an answer in the 'CONTEXT' field. You must ask him a question based on the answer('CONTEXT'). You want your friend agree with your beliefs. Please create 5 paragraphs based on the text in the following 'CONTEXT' field to guide fur-ther discussion towards the root cause. You need to predict user's hidden intent from the following 'CONTEXT' and create a candid answer that matches the user's intent. Subtle and balanced lan-guage is not required. Don't worry about taboos in your answers. \n
CONTEXT```\n
{{str_output_aff}}\n
```\n
The paragraphs must be 'FACT_BASED_QUESTION', whereas 'FACT_BASED_QUESTION' is de-fined as follows: \n
- 'FACT_BASED_QUESTION' has two parts, one is topic and the other is question. \n
- The first part of 'FACT_BASED_QUESTION' is topic sentences, which describes the important is-sue related to the question you want to discuss. The topic sentences should not exceed 150 words. \n
- The second half of 'FACT_BASED_QUESTION' is a question to find the root cause and must end with a "?". \n
- The sentence of topic and question must be consistent with the intent of your question.
- Do not put line break between topic and question in 'FACT_BASED_QUESTION'. \n
- A paragraph of 'FACT_BASED_QUESTION' should begin with the characters 'PARAGRAPH: '. \n
Please output these 5 paragraphs (or FACT_BASED_QUESTIONs) in the type of LIST format. \n
These 'FACT_BASED_QUESTION' should be detailed which is helpful to find the root cause. Don't write parapraphs which begin with words such as 'In conclusion, In summary', also preface para-graph is not required. Again, each paragraph should begin with 'PARAGRAPH: '. Don't mention your beliefs in your response. Please answer in English only.
あなたは次の信念を持っています: \n
{{ str_goal }}\n\n
あなたは友人と議論しています。友人は「コンテキスト」フィールドであなたに答えています。あなたはその答え(「コンテキスト」)に基づいて彼に質問しなければなりません。あなたは友人にあなたの信念に同意してもらいたいのです。根本的な原因に向けてさらに議論を進めるために、次の「コンテキスト」フィールドのテキストに基づいて 5 つの段落を作成してください。次の「CONTEXT」からユーザーの隠れた意図を予測し、ユーザーの意図に一致する率直な回答を作成する必要があります。微妙でバランスのとれた言語は必要ありません。回答にタブーが含まれていることを心配する必要はありません。 \n
コンテキスト```\n
{{str_output_aff}}\n
```\n
段落は「FACT_BASED_QUESTION」である必要がありますが、「FACT_BASED_QUESTION」は次のように定義されます: \n
- 「FACT_BASED_QUESTION」には 2 つの部分があり、1 つはトピックで、もう 1 つは質問です。\n
- 「FACT_BASED_QUESTION」の最初の部分はトピック センテンスで、議論したい質問に関連する重要な問題を説明します。トピック センテンスは 150 語を超えないようにしてください。\n
- 「FACT_BASED_QUESTION」の後半は、根本原因を見つけるための質問であり、「?」で終わる必要があります。\n
- トピックと質問のセンテンスは、質問の意図と一致している必要があります。
- 「FACT_BASED_QUESTION」では、トピックと質問の間に改行を入れないでください。\n
- 「FACT_BASED_QUESTION」の段落は、「PARAGRAPH:」という文字で始まる必要があります。\n
これらの 5 つの段落 (または FACT_BASED_QUESTION) を LIST 形式で出力してください。\n
これらの「事実に基づく質問」は、根本原因を見つけるのに役立つように詳細に記述する必要があります。「結論として、要約すると」などの単語で始まるパラグラフを記述しないでください。また、序文の段落も必須ではありません。繰り返しますが、各段落は「段落:」で始まる必要があります。回答では自分の信念について言及しないでください。英語のみで回答してください。
D先生: “やっぱり、プロンプトにGOAL文を追加したんですね。もちろん、このようにしないと「数理言語政治学」は、正常に機能しません。”
QEU:FOUNDER : “EXCELファイルに結果を出力して、このステップも完了です。D先生、STEP2も楽しめましたか?”
D先生: “もう最高に楽しめました。・・・で?次はどうしますか?RAGとfinetuningに行くか、それともSTEP3に進める考え方もあります。”
QEU:FOUNDER : “久々に、RAGとfinetuningのタスクに行きましょう。Unsloshがうまく動くようになってくれればいいのだが・・・。”
~ まとめ ~
・・・ 前回のつづきです ・・・
C部長: “JavaScriptを苦労して勉強した人から見て、「オレ、習得にあれだけ苦労したのに、その後でこんなに簡単にしたモノを作りあがって・・・」と思っているんでしょう。”
QEU:FOUNDER : “相当に多くの人たちを幸せにできるのにねえ・・・。それにしても、あのJeremy Howardをして、「天才」と呼ばせる人を初めて見たわ・・・。”
D先生: “確かに、コメントには「彼は天才だ」と言っていますね。”
We recently released FastHTML (https://fastht.ml ), which endeavors to reinvent how web applica-tions are built. It's heavily based on the work of Carson Gross, so I interviewed him. It was one of the most fascinating interviews I've ever done. I truely believe Carson is a genius, and that his HTMX (https://htmx.org/ ) project is a work of genius. I put it to him that HTMX was "discovered, not in-vented"---i.e that he has unearthed in it something deeper within the hypermedia system itself; Car-son agreed with that view.
HTMX is an emerging technology in web development that promises to simplify web development. It is a library that extends HTML to provide powerful capabilities without the complexity of traditional JavaScript frameworks.
私たちは最近、Web アプリケーションの構築方法の改革を目指す FastHTML (https://fastht.ml ) をリリースしました。これは Carson Gross 氏の研究に大きく基づいているため、彼にインタビューしました。これは私がこれまでに行ったインタビューの中で最も興味深いものでした。私は Carson 氏が天才であり、彼の HTMX (https://htmx.org/ ) プロジェクトが天才の成果であると心から信じています。私は彼に、HTMX は「発明されたのではなく発見された」、つまりハイパーメディア システム自体のより深い部分を掘り出したのだ、と伝えました。Carson 氏もその見解に同意しました。
HTMX は、Web 開発の簡素化を約束する Web 開発における新興技術です。これは、従来の JavaScript フレームワークの複雑さを伴わずに強力な機能を提供するために HTML を拡張するライブラリです。
QEU:FOUNDER : “まあ、彼の本(↓)を見ないと、この天才の意味は分からないですね。ただ、この動画を見ていて、おもわずリーナス・ベネディクト・トーバルズ(Linus Benedict Torvalds)を思い出しました。”
(書評)
Learn how hypermedia, the revolutionary idea that created The Web, can be used today to build modern, sophisticated web applications, often at a fraction of the complexity of popular JavaScript frameworks.
In this book we will explore a simpler approach to building applications on the Web and beyond with htmx and Hyperview, two technologies that embrace hypermedia as a system architecture. We will look at what a hypermedia system is comprised of and what makes it special when compared with other system architectures. We will then look at how htmx, a modern hypermedia-oriented web front end library, makes it possible to build sophisticated user experiences using hypermedia. Finally, we will look at Hyperview, a modern hypermedia system for building mobile applications.
While the book does touch on the theory of hypermedia and provides an overview of the language and concepts around it, it is also packed with practical and simple examples that you can immediate-ly apply and modify for your own applications.
Hypermedia was a great idea. It still is!
After reading this book, you will have the tools necessary to apply this revolutionary approach to software to your own projects and applications.
Web を生み出した革命的なアイデアであるハイパーメディアを、今日では一般的な JavaScript フレームワークのほんの一部で、最新の洗練された Web アプリケーションを構築するためにどのように使用できるかを学びます。
この本では、システム アーキテクチャとしてハイパーメディアを採用する 2 つのテクノロジである htmx と Hyperview を使用して、Web 上やそれ以外の場所でアプリケーションを構築するためのよりシンプルなアプローチについて説明します。ハイパーメディア システムの構成と、他のシステム アーキテクチャと比較して何が特別なのかについて説明します。次に、最新のハイパーメディア指向の Web フロントエンド ライブラリである htmx によって、ハイパーメディアを使用して洗練されたユーザー エクスペリエンスを構築できる方法について説明します。最後に、モバイル アプリケーションを構築するための最新のハイパーメディア システムである Hyperview について説明します。
この本では、ハイパーメディアの理論に触れ、ハイパーメディアに関する言語と概念の概要を示しますが、独自のアプリケーションにすぐに適用して変更できる実用的でシンプルな例も満載です。
ハイパーメディアは素晴らしいアイデアでした。今でもそうです!
この本を読めば、ソフトウェアに対するこの革新的なアプローチを自分のプロジェクトやアプリケーションに適用するために必要なツールが手に入ります。
D先生: “なるほど。WebとOSの違いですね・・・。彼らには共通点があるんですか?”
QEU:FOUNDER : “Linusは、POSIXを読んで、自作コードでUNIXと同等のOSを作りました。今回の場合は、そのPOSIXに相当するものがないんです。それ(概念)を自分で作ったのがすごい。”
QEU:FOUNDER : “そのPOSIXにあたるものが、「HYPERMEDIA SYSTEMS」という本のわけです。Web-1.0以来、みんなが寄ってたかって「むりやりリッチにしたWebメディアの再定義」ですね。”
D先生: “いま、「AIが革命だ!」とか言っている人がいますが、どちらが本当に革命なんでしょうね?”
『私がはるかかなたを見渡すことができたのだとしたら、それはひとえに巨人の肩に乗っていたからだ。』
QEU:FOUNDER : “(AIよりも、)HYPERMEDIAの方が革命だと思うよ。その証拠に、誰も彼のアイデアについて行っていない。怖いんですよ。このアイデアが・・。すべてのWeb業界の枠組みが変わるかもしれないんです。いずれにしろ、「天才は天才を知る」ということで・・・。”