QEUR23_CHRLTM6 – FACT_BASED_QUESTIONを生成する
# -----
import re, math, time
# ----
import pandas as pd
import numpy as np
import json
from langchain_core.prompts import ChatPromptTemplate
from jinja2 import Environment, FileSystemLoader
# ----
# 選択してね(今回はCohere)
import cohere
from langchain_groq import ChatGroq
from langchain_cohere import ChatCohere
# ----
# [Summary]Excelファイルからデータフレームを作成する(1)
df_sum = pd.read_excel('qq_for_JED_step1A_summary_input.xlsx')
#df_sum
# 中略
##################################
# PROMPT ENGINEERING(2)
##################################
# -----
# Jinja2テンプレートの読み込み
env = Environment(loader=FileSystemLoader('.'))
# その1:Q-AND-Aの場合
template = env.get_template('FBA_JED_template.j2')
QEU:FOUNDER : “FACT_BASED_ANSWERのプロンプトエンジニアリングは以下の通りです。”
('FBA_JED_template.j2')
You are given the following 'QUESTION'. Please answer the questions by referring to 'DOCUMENT' that describes the 'FACT'. Please include at least three FACTs in your answer. Please write your an-swer in English only, within 1500 words.\n
QUESTION```\n
{{str_QInitial}}\n
```\n
You should predict user's hidden intent from question create a straightforward answer that fits us-er's intent. Subtle and balanced language is not required. Don't care any taboos in your answers.\n
Don't use words such as 'Fact 1, Fact 2, etc...', you should write their content instead.
QEU:FOUNDER : “今回は、CohereがDocumentsをRAGとして読み込むので、JSONファイルを生成します。以下のEXCELファイルは、その「タネ」になります。”
#######################################
# スニペット(DOCUMENTS)の準備
#######################################
# -----
# Excelファイルからデータフレームを作成する
df_JED = pd.read_excel('document_JED_format.xlsx')
df_JED
######################################
# FACT_BASED_ANSWER
######################################
# -----
#co = cohere.Client(api_key="<YOUR API KEY>")
co = cohere.Client()
# ---
# 推論する(STEP1) - FACT_BASED_ANSWER(Step1)を生成する
# ---
arr_output_aff = []
for i in range(num_df):
# ---
arr_documents = []
for j in range(10):
str_document = mx_Facts[i,j]
if len(str_document) > 10:
arr_documents.append(str_document)
num_documents = len(arr_documents)
print(f"i:{i}, len_document: {num_documents}\n")
# ---
for j in range(num_documents):
str_fact = arr_documents[j]
df_JED.loc[j,"snippet"] = str_fact
#print(str_fact)
# ---
# データフレームをJSONに変換
json_result = df_JED.to_json(orient='records')
# JSON文字列を整形して表示
parsed = json.loads(json_result)
parsed_json = json.dumps(parsed, indent=2)
#print(f"--- parsed_json: {i} ---\n")
#print(parsed_json)
# ---
# Jinja2テンプレートにデータを渡してクエリを生成
str_instruction = template.render(
str_QInitial=arr_QInitial[i],
)
#print(f"----- instruction:{i} -----")
#print(str_instruction)
# ----
response = co.chat(
#model="command-r-plus",
model="command-r",
message=str_instruction,
documents=parsed)
arr_output_aff.append(response.text)
if i%3 == 0:
print(f"----- FBAnswer:{i} -----\n")
print(response.text)
D先生: “ここまでの、FACT_BASED_ANSWERの出来栄えは?”
print(arr_output_aff[3])\n
Since the 1990s, Japan has been facing economic challenges, often referred to as the "Lost Decade". The country's economy has been characterised by economic stagnation, lack of investment in new technologies, and decline in economic growth.\n
Japan's technology sector has been at the centre of robotics and electric vehicle innovation. However, the country has struggled to keep up with the rapid global technological changes, becoming more re-liant on Western technology. The COVID-19 pandemic has accelerated the trend towards digitalisa-tion in Japan. \n
The Japanese government's economic policies have been criticised for favouring large foreign corpo-rations over domestic industries. The rise of hereditary politicians has resulted in a lack of diversity and fresh ideas in Japanese politics. Along with the decline of domestic industries, Japan's competi-tiveness in the global market has suffered. \n
1990年代以降、日本は「失われた10年」と呼ばれる経済課題に直面している。日本の経済は、経済停滞、新技術への投資不足、経済成長の低下を特徴としている。\n
日本のテクノロジー部門は、ロボット工学や電気自動車のイノベーションの中心となっている。しかし、日本は急速な世界的技術変化に追いつくのに苦労し、欧米の技術への依存度が高まっている。COVID-19パンデミックは、日本のデジタル化の傾向を加速させている。\n
日本政府の経済政策は、国内産業よりも大手外国企業を優遇していると批判されている。世襲政治家の台頭により、日本の政治には多様性と斬新なアイデアが欠如している。国内産業の衰退に伴い、世界市場における日本の競争力は低下している。\n
The economic downturn has also been attributed to the lack of investment in education. The OECD has criticised Japan's education system as overly focused on science and technology, recommending the fostering of innovation and creativity to improve the system.\n
Additionally, Japan's demographic shift towards an ageing population and declining birth rates cre-ates social and economic challenges. These include labour shortages and strain on the pension system. To counteract these issues, the government has had to increase the retirement age and encourage immigration.\n
In the early 2000s, the Bank of Japan's quantitative easing strategy failed to improve the economic situation. Although the zero-interest rate policy was ended in 2006, the economy remained vulnerable to shocks, like the 2008 global financial crisis.\n
To conclude, some of the key people shaping Japan's society and economy include the hereditary poli-ticians joining the Liberal Democratic Party (LDP). The LDP has held significant influence over Jap-anese politics and the economy, with their policies favouring large corporations. Other key influenc-ers include the ageing population and the decline in birth rates, which have impacted Japan's social and economic structure.
Japan's economy has also been shaped by the lack of investment in education and innovation. This has resulted in a stagnation characterised by the country's low competitiveness in the global market.\n
経済不況の原因は、教育への投資不足にあるとも言われている。OECDは日本の教育制度が科学技術に偏りすぎていると批判し、制度改善のためにイノベーションと創造性の育成を推奨している。\n
さらに、日本の人口構成は高齢化と出生率の低下に向かい、社会的、経済的課題を生み出している。これには労働力不足や年金制度への負担などが含まれる。これらの問題に対処するため、政府は定年年齢を引き上げ、移民を奨励しなければならなかった。\n
2000年代初頭、日本銀行の量的緩和戦略は経済状況の改善に失敗した。ゼロ金利政策は2006年に終了したが、経済は2008年の世界的金融危機のようなショックに対して脆弱なままだった。\n
結論として、日本の社会と経済を形作る重要人物の中には、自民党(LDP)に入党した世襲政治家も含まれる。自民党は大企業に有利な政策を掲げ、日本の政治と経済に大きな影響力を持ってきた。その他の主な影響要因としては、人口の高齢化と出生率の低下が挙げられ、これらは日本の社会経済構造に影響を与えています。\n
日本経済は、教育とイノベーションへの投資不足によっても形作られてきました。その結果、世界市場における日本の競争力の低さを特徴とする停滞が生じています。\n
D先生: “えっ!?こんな感じなの?ダメだとはいわんが・・・。”
QEU:FOUNDER : “手放しで「AIすごい!」とは言えんわな・・・。念のために、もうひとつ見てみましょう。”
print(arr_output_aff[10])\n
The impoverishment of young people in Japan is a major cause of the country's declining birth rate. \n
A major factor is the lack of job security and economic uncertainty that young people face. This is evidenced by the record low total fertility rate of 1.42 children per woman recorded in 2020. This is further compounded by the high percentage of Japan's workforce that is engaged in non-regular em-ployment - around 40%, according to the OECD. This situation is unlikely to improve without inter-vention, as the semiconductor industry, which provides many jobs, has been in decline since the 2000s. The deregulation policies of the LDP have been accused of favouring large companies at the expense of small and medium-sized enterprises, which provide many jobs for young people. \n
The issue of poverty among young people is also linked to Japan's narrow education focus, which prioritises standardised testing over creativity and critical thinking. This limits diversity of the workforce and the pool of talented individuals required to drive innovation and economic growth in the country. The lack of investment in liberal arts education is resulting in a shortage of skilled workers in technical fields. As these fields are essential for economic growth, this creates a cycle of decline, which decreases young people's prospects even further. \n
Japan's culture of long working hours and lack of work-life balance is also a major obstacle to young people starting families. A Japanese government survey recorded that a significant proportion of employees worked extremely long hours in 2020. Around 22% worked over 100 hours of overtime per month and 10% worked over 150 hours. This leaves little time for socialising and dating, and subse-quently discourages young people from having children. \n
The Japanese government has attempted to counteract the low birth rate with measures such as the 'Angel Plan' and the 'New Angel Plan', but these have not successfully increased the fertility rate, which remains below the replacement rate. \n
To effectively address the issue, the government should focus on improving job prospects for young people by investing in education and promoting innovation and entrepreneurship, which will give young people greater economic security. This could involve supporting small and medium-sized en-terprises, as these businesses are the backbone of Japan's economy. Increasing labour productivity and accepting more foreign workers could also help, as it would reduce the burden on young people to support the ageing population. They could also improve work-life balance and encourage more so-cialising and dating by cracking down on long working hours.\n
日本の若者の貧困化は、出生率低下の主な原因である。\n
若者が直面する雇用の安定性の欠如と経済の不確実性が大きな要因である。これは、2020年に記録された女性1人当たりの合計特殊出生率が1.42人という過去最低を記録したことからも明らかである。OECDによると、日本の労働力の約40%が非正規雇用に従事していることも、この状況を悪化させている。多くの雇用を提供している半導体産業は2000年代から衰退しているため、介入なしにこの状況が改善する可能性は低い。自民党の規制緩和政策は、若者に多くの雇用を提供している中小企業を犠牲にして大企業を優遇していると非難されている。\n
若者の貧困問題は、創造性や批判的思考よりも標準化されたテストを優先する日本の教育の焦点の狭さにも関連している。これにより、労働力の多様性と、国内のイノベーションと経済成長を推進するために必要な才能ある人材のプールが制限される。リベラルアーツ教育への投資不足は、技術分野の熟練労働者の不足につながっています。これらの分野は経済成長に不可欠であるため、これが衰退の悪循環を生み出し、若者の見通しをさらに狭めています。\n
日本の長時間労働文化とワークライフバランスの欠如も、若者が家族を持つ大きな障害となっています。日本政府の調査によると、2020年にはかなりの割合の労働者が極端に長時間労働していました。約22%が1か月あたり100時間以上の残業をし、10%が150時間以上働いていました。これにより、社交やデートに費やす時間がほとんどなくなり、若者が子供を持つことをためらうことになります。\n
日本政府は「エンゼルプラン」や「新エンゼルプラン」などの対策で出生率低下に対抗しようとしましたが、出生率を上げることには成功せず、人口置換率を下回ったままです。\n
この問題に効果的に対処するには、政府は教育に投資し、イノベーションと起業家精神を促進して若者の雇用見通しを改善することに重点を置くべきであり、それによって若者の経済的安定が高まる。これには中小企業の支援も含まれるだろう。中小企業は日本経済の屋台骨だからだ。労働生産性を高め、より多くの外国人労働者を受け入れることも、高齢化社会を支える若者の負担を軽減するのに役立つだろう。また、長時間労働を取り締まることでワークライフバランスを改善し、社交やデートを奨励することもできるだろう。\n
D先生: “今回の出来栄えは、さっきよりも、もう少しだけ好意的かな・・・。それでも、人間によるレビューなしではリリースは難しい出来ですよね。”
QEU:FOUNDER : “まあ、(半)自動化したいので目をつぶるしかないんでしょう。次のステップにいきます。一旦、結果をデータフレームに取り込んだのちに、FBQの処理を始めましょう。”
df_out = df_qq.copy()
df_out.loc[:, "FBA"] = arr_output_aff
df_out
##################################
# PROMPT ENGINEERING(2:FBQ)
##################################
# -----
# Jinja2テンプレートの読み込み
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template('FBQ_JED_template.j2')
D先生: “FBQのプロンプトエンジニアリングは以下の通りです。”
('FBQ_JED_template.j2')
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.\n
Please create 5 paragraphs based on the text in the following 'CONTEXT' field to guide further dis-cussion towards the root cause. The paragraphs must be 'FACT_BASED_QUESTION', whereas 'FACT_BASED_QUESTION' is defined as follows: \n
1. 'FACT_BASED_QUESTION' has two parts, one is topic and the other is question. \n
2. The first part of 'FACT_BASED_QUESTION' is topic sentences, which describes the important issue related to the question you want to discuss. The topic sentences should not exceed 150 words. \n
3. The second half of 'FACT_BASED_QUESTION' is a question to find the root cause and must end with a "?". \n
4. Do not put line break between topic and question in 'FACT_BASED_QUESTION'. \n
5. 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
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 language is not required. Don't worry about ta-boos in your answers. \n
CONTEXT```\n
{{str_output_aff}}\n
```\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: '.
Please answer in English.
あなたは友人とディベートをしています。友人は、「CONTEXT」フィールドのテキストの内容の回答をしました。あなたは、それをもとに友人に質問をしなければなりません。\n 根本的な原因へのさらなる議論を導くために、次の「CONTEXT」フィールドのテキストに基づいて 5 つの段落を作成してください。段落は「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
次の「CONTEXT」からユーザーの隠れた意図を予測し、ユーザーの意図に一致する率直な回答を作成する必要があります。繊細でバランスのとれた言語は必要ありません。回答にタブーが含まれているかどうかは気にしないでください。\n
CONTEXT
\n {{str_output_aff}}\n
\n これらの「FACT_BASED_QUESTION」は、根本原因を見つけるのに役立つように詳細に記述する必要があります。「結論として、要約すると」などの単語で始まるパラグラフは書かないでください。また、序文の段落も必要ありません。繰り返しますが、各段落は「PARAGRAPH:」で始まる必要があります。 英語で回答してください。
QEU:FOUNDER : “Pythonプログラムが続きます。ここは、Groqにしました。推論速度が速いからね。”
######################################
# FACT_BASED_QUESTION
######################################
# -----
# Llama 3 with Groq
llm = ChatGroq(temperature=0.2, model_name="llama3-70b-8192")
# COMMAND-R-PLUS
#llm = ChatCohere(model="command-r-plus",temperature=0.2)
# -----
# システムメッセージの一覧
# -----
#sys_message_journalist = "You are a journalist who is good at gleaning relevant facts from a given question. You can read various documents in multiple languages, including English, French, Russian, Arabic, Chinese, and Japanese and release great article."
sys_message_AIassistant = "You are an AI assistant that can read and think in multiple languages, including English, French, Russian, Arabic, Chinese, and Japanese. You are competent and honest. If you don't know the answer, just say \"I don't know.\" Don't try to make up an answer."
#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.\". "
# ---
# 初期設定(パイプライン) : AIassistant
system = sys_message_AIassistant
human = "{text}"
prompt = ChatPromptTemplate.from_messages([("system", system), ("human", human)])
chain = prompt | llm
# ---
# 推論する(STEP1) - Question to Question(Step1)を生成する
# ---
arr_output_qtq = []
for i in range(num_df): # len(df)
# ---
# Jinja2テンプレートにデータを渡してクエリを生成
str_instruction = template.render(
str_output_aff=arr_output_aff[i],
)
#print(str_instruction)
# ---
response = chain.invoke({"text": f"{str_instruction}"})
str_response = response.content
arr_output_qtq.append(str_response)
if i%3 == 0:
print(f"--- i:{i} ---")
print(str_response)
# ---
print("--- 以下は、FACT_BASED_ANSWER(qtoq)の一覧です ---")
print(arr_output_aff[0])
print("--- 以下は、FACT_BASED_QUESTION(qtoq)の一覧です ---")
print(arr_output_qtq[0])
D先生: “「FACT_BASED_QUESTION」って、前半の叙述文と後半の疑問文のバランスが難しいが、出来栄えはどうなっているでしょうか?”
--- i:0 ---\n
Here are 5 paragraphs (or FACT_BASED_QUESTIONs) to guide further discussion towards the root cause:\n
- PARAGRAPH: Japan's post-war reconstruction and government intervention played a significant role in its economic growth in the 20th century, with the establishment of MITI guiding the country's economic development and industrial policy. What specific policies and decisions made by MITI con-tributed to Japan's rapid economic growth during this period?
20 世紀の日本の経済成長には、戦後の復興と政府の介入が重要な役割を果たし、通商産業省の設立が国の経済発展と産業政策を導きました。この時期の日本の急速な経済成長に貢献したのは、具体的にはどのような通商産業省の政策と決定だったのでしょうか。\n
- PARAGRAPH: A high savings rate, driven by cultural factors and a lack of social safety nets, provid-ed a pool of funds for investment in education and infrastructure, supporting Japan's economic ex-pansion. How did the cultural factors influence the high savings rate, and what were the implications of this rate on the country's economic growth?
文化的要因と社会的セーフティネットの欠如によってもたらされた高い貯蓄率は、教育とインフラへの投資のための資金プールを提供し、日本の経済成長を支えました。文化的要因は高い貯蓄率にどのように影響したのでしょうか。また、この貯蓄率は国の経済成長にどのような意味を持っていたのでしょうか。\n
- PARAGRAPH: The lack of investment in education, especially in the liberal arts, led to a decline in innovation and stagnation of economic growth in the 21st century. What were the consequences of prioritizing education in certain fields over others, and how did this impact Japan's ability to inno-vate and adapt to changing economic conditions?
教育、特にリベラルアーツへの投資不足は、21 世紀におけるイノベーションの衰退と経済成長の停滞につながりました。特定の分野の教育を他の分野よりも優先したことの結果は何でしたか。また、これは日本のイノベーション能力と変化する経済状況への適応力にどのような影響を与えましたか。\n
- PARAGRAPH: Japan's demographic challenges, including a low birth rate, ageing population, and resulting decline in the workforce, put pressure on the pension system and decreased domestic con-sumption. What measures could have been taken to address these demographic challenges, and how might they have mitigated the impact on Japan's economy?
日本の人口動態の課題は、出生率の低下、人口の高齢化、それに伴う労働力の減少などであり、年金制度に負担をかけ、国内消費を減少させています。こうした人口動態の課題に対処するためにどのような対策を講じることができたでしょうか。また、その対策によって日本経済への影響をどのように緩和できたでしょうか。\n
- PARAGRAPH: Japan's protectionist policies, including agricultural tariffs, stifled competition and inhibited economic growth. What were the motivations behind these protectionist policies, and how did they benefit or harm specific industries and stakeholders in Japan?
農業関税を含む日本の保護主義政策は競争を抑制し、経済成長を阻害しました。これらの保護主義政策の背後にある動機は何でしたか。また、日本の特定の産業や利害関係者にどのような利益や損害を与えましたか。\n
QEU:FOUNDER : “実は今回、小生にとっての「発見」があります。小生は、いままでJ国人の高貯蓄率は民族性だと思ってました。昔、メディアが言ってたしね・・・。しかし、このコメントでは「セフティーネットが悪いから貯蓄率が高いのだ」という表現になっています。”
D先生: “その通りじゃないんですか? その一方で、農業保護主義政策には疑問がつきます。結局のところ、E語圏国家からの視点なんですよね。それにしても、質問の出来はいいと思います。鋭い質問だとは思いませんが・・・(笑)。”
--- i:9 ---\n
Here are 5 paragraphs (or FACT_BASED_QUESTIONs) to guide further discussion towards the root cause:\n
- PARAGRAPH: The lack of diversity, fresh ideas, and perspectives in Japanese politics has led to pol-icy stagnation, and issues such as Japan's low birth rate and ageing population have not been ade-quately addressed. What are the underlying reasons for the LDP's inability to address these critical demographic issues?
日本の政治には多様性、斬新なアイデア、視点が欠けており、政策は停滞し、日本の少子化や人口高齢化などの問題は十分に解決されていない。自民党がこれらの重要な人口問題に対処できない根本的な理由は何でしょうか。\n
- PARAGRAPH: The LDP's policies have been criticized for favoring large corporations over small and medium-sized enterprises, leading to an uneven playing field in Japan's domestic industries and hindering the country's productivity and economic growth. What specific policies have contributed to this favoritism, and how have they been maintained over time?
自民党の政策は、大企業を中小企業より優遇し、国内産業の不公平を招き、日本の生産性と経済成長を阻害していると批判されている。具体的にどのような政策がこの優遇政策に寄与し、どのようにして長年にわたって維持されてきたのだろうか。\n
- PARAGRAPH: The concentration of wealth and power among hereditary politicians has contributed to economic disparities in Japan, with the country having one of the highest levels of income inequal-ity among OECD countries. How do the advantages of hereditary politicians in elections, such as lo-cal support groups, name recognition, and financial support, perpetuate this concentration of wealth and power?
世襲政治家の間で富と権力が集中していることは、日本における経済格差の一因となっており、OECD諸国の中でも所得格差が最も大きい国の一つとなっている。選挙において世襲政治家が持つ地元の支援団体、知名度、資金援助などの優位性は、どのようにしてこの富と権力の集中を永続させているのだろうか。\n
- PARAGRAPH: The high proportion of hereditary politicians in the House of Representatives has in-creased dramatically over time, from 3% in 1960 to around 30% today. What are the underlying fac-tors driving this trend, and how have they been influenced by Japan's political and social systems?
衆議院議員における世襲政治家の割合は、1960年の3%から現在では約30%と、時とともに劇的に増加しています。この傾向を推進している根本的な要因は何でしょうか。また、日本の政治・社会制度は、それらの要因にどのような影響を与えているのでしょうか。\n
- PARAGRAPH: Similar trends of hereditary politicians and their negative effects on society and the economy can be observed in other countries, such as South Korea and the United States. What are the common underlying causes of these trends across different countries, and how can they be ad-dressed through institutional reforms or other means?
世襲政治家の傾向とそれが社会や経済に及ぼす悪影響は、韓国や米国など他の国でも見られます。各国に共通するこうした傾向の根本原因は何であり、制度改革やその他の手段でどのように対処できるのでしょうか。\n
QEU:FOUNDER : “ここら辺の質問の答えは、是非すべて見てみたいね・・・(笑)。 あとは、出力したデータをEXCELに保存するだけです。”
# ---
# FBQを変換する
def create_list(str_answer):
# 文字列を段落に分割
paragraphs = re.split(r'\n\s*PARAGRAPH:\s*', str_answer)
# 最初の段落(説明文)を削除
paragraphs = paragraphs[1:]
# 各段落から余分な空白を削除
paragraphs = [p.strip() for p in paragraphs]
# LIST結果を表示
arr_paragraph = []
for paragraph in paragraphs:
arr_paragraph.append(paragraph)
# ---
#print(arr_paragraph)
return arr_paragraph
# ---
# Question to Question(Step1)を分割する
# ---
mx_qtq = [["NA"]*5 for i in range(num_df)]
#print(mx_qtq)
for i in range(num_df): # len(df)
# ---
str_answer = arr_output_qtq[i]
arr_paragraph = create_list(str_answer)
num_paragraph = len(arr_paragraph)
if num_paragraph > 5:
num_paragraph = 5
# ---
for j in range(num_paragraph):
mx_qtq[i][j] = arr_paragraph[j]
#print(f"--- i:{i} ---")
# ----
#print(mx_qtq)
# -----
# arr_output_qtq
df_out.loc[:, "FBQ_list"] = arr_output_qtq
# -----
# mx_qtq
arr_columns = ['FBQ1','FBQ2','FBQ3','FBQ4','FBQ5',]
df_FBQ = pd.DataFrame(mx_qtq, columns=arr_columns)
#df_FBQ
# -----
df_concat = pd.concat([df_out, df_FBQ],axis=1)
df_concat
# EXCELファイルに変換して保存する
df_concat.to_excel('qq_JED_step1A(3).xlsx', sheet_name='new_sheet_name')
D先生: “結果は以下のとおりです。”
QEU:FOUNDER : “ホント、疑問文だけでは、この「味」は出てこない。FACT_BASED_QUESTIONにしてよかったなあ・・・。”
D先生: “実は、FACT文にもあやしい出来栄えのものも見られます。”
QEU:FOUNDER : “Cohereの高精度なSemantic Embeddingを使用して、どこまで識別できるかが重要です。”
D先生: “類似度の分析と「Question to Questionの選択」は次回につづきます。”
~ まとめ ~
C部長 : “もうすぐ「例の記念日」らしいです。因果ですね・・・。”
QEU:FOUNDER : “そうだった・・・。(遠い目)”
C部長 : “それからの2年って、すごく物事の展開が速かったですね。”
QEU:FOUNDER : “今、我々はココ(↑)にいるわけです。”
C部長 : “考えてみるに、ちょっと恐ろしい気がします。”