Views
No views yet

1from vllm import LLM, SamplingParams
2
3llm = LLM(model="lightblue/kurage-en")
4sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
5
6def create_rag_prompt(contexts, question):
7
8 context_str = "\n\n".join([f"<<Chunk {i+1}>>\n{x}" for i, x in enumerate(contexts)])
9
10 str_inputs = f"""{context_str}
11
12 <<Question>>
13 {question}"""
14
15 chat = [
16 {"role": "user", "content": str_inputs},
17 ]
18
19 return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
20
21contexts = [
22 "Junko Nakagawa, a member of the Bank of Japan's Policy Board, stated on the 11th that real interest rates are currently at an extremely low level. She mentioned that if the BOJ's economic and price outlook materializes in the future, the degree of monetary easing would be adjusted from the perspective of achieving the price target.",
23 "Japan's current account surplus in July was 3.2 trillion yen, the highest monthly surplus on record for the month of July. However, the surplus continues to be driven by the primary income balance, which recorded a surplus of 4.4 trillion yen in July, the highest monthly figure on record.",
24 "Finance Minister Shunichi Suzuki appointed Kenji Suwazono, former Director-General of the Customs and Tariff Bureau at the Ministry of Finance, as the new Executive Director of the Bank of Japan effective the 10th. Suwazono succeeds Masaaki Kaizuka, whose term ended on the 9th, and his term will last for four years.",
25 "In the yen appreciation phase of August, it has become a topic in the foreign exchange market that Japanese institutional investors engaged in the largest-ever outward securities investment."
26]
27
28question = "What is Japan's primary income balance currently?"
29
30inputs = create_rag_prompt(contexts, question)
31
32outputs = llm.generate([inputs], sampling_params)
33
34print(outputs[0].outputs[0].text)
35# <<References>>
36# 2
37#
38# <<Answer>>
39# 4.4 trillion yen.1<<Chunk 1>>
2Junko Nakagawa, a member of the Bank of Japan's Policy Board, stated on the 11th that real interest rates are currently at an extremely low level.
3She mentioned that if the BOJ's economic and price outlook materializes in the future, the degree of monetary easing would be adjusted from the perspective of achieving the price target.
4
5<<Chunk 2>>
6Japan's current account surplus in July was 3.2 trillion yen, the highest monthly surplus on record for the month of July.
7However, the surplus continues to be driven by the primary income balance, which recorded a surplus of 4.4 trillion yen in July, the highest monthly figure on record.
8
9<<Chunk 3>>
10Finance Minister Shunichi Suzuki appointed Kenji Suwazono, former Director-General of the Customs and Tariff Bureau at the Ministry of Finance, as the new Executive Director of the Bank of Japan effective the 10th. Suwazono succeeds Masaaki Kaizuka, whose term ended on the 9th, and his term will last for four years.
11
12<<Chunk 4>>
13In the yen appreciation phase of August, it has become a topic in the foreign exchange market that Japanese institutional investors engaged in the largest-ever outward securities investment.
14
15<<Question>>
16What is Japan's primary income balance currently?1<<References>>
22
3
4<<Answer>>
54.4 trillion yen1from vllm import LLM, SamplingParams
2
3llm = LLM(model="lightblue/kurage-en")
4sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
5
6def create_rag_prompt(contexts, question):
7
8 context_str = "\n\n".join([f"<<Chunk {i+1}>>\n{x}" for i, x in enumerate(contexts)])
9
10 str_inputs = f"""{context_str}
11
12 <<Question>>
13 {question}"""
14
15 chat = [
16 {"role": "user", "content": str_inputs},
17 ]
18
19 return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
20
21contexts = [
22 "Junko Nakagawa, a member of the Bank of Japan's Policy Board, stated on the 11th that real interest rates are currently at an extremely low level. She mentioned that if the BOJ's economic and price outlook materializes in the future, the degree of monetary easing would be adjusted from the perspective of achieving the price target.",
23 "Japan's current account surplus in July was 3.2 trillion yen, the highest monthly surplus on record for the month of July. However, the surplus continues to be driven by the primary income balance, which recorded a surplus of 4.4 trillion yen in July, the highest monthly figure on record.",
24 "Finance Minister Shunichi Suzuki appointed Kenji Suwazono, former Director-General of the Customs and Tariff Bureau at the Ministry of Finance, as the new Executive Director of the Bank of Japan effective the 10th. Suwazono succeeds Masaaki Kaizuka, whose term ended on the 9th, and his term will last for four years.",
25 "In the yen appreciation phase of August, it has become a topic in the foreign exchange market that Japanese institutional investors engaged in the largest-ever outward securities investment."
26]
27
28question = "What is Japan's primary income balance currently?"
29
30inputs = create_rag_prompt(contexts, question)
31
32outputs = llm.generate([inputs], sampling_params)
33
34print(outputs[0].outputs[0].text)
35# <<References>>
36# 2
37#
38# <<Answer>>
39# 4.4 trillion yen.
401<<Chunk 1>>
2Junko Nakagawa, a member of the Bank of Japan's Policy Board, stated on the 11th that real interest rates are currently at an extremely low level.
3She mentioned that if the BOJ's economic and price outlook materializes in the future, the degree of monetary easing would be adjusted from the perspective of achieving the price target.
4
5<<Question>>
6What is Japan's primary income balance currently?1<<References>>
2None1<<Chunk 1>>
2Japan's current account surplus in July was 3.2 trillion yen, the highest monthly surplus on record for the month of July.
3However, the surplus continues to be driven by the primary income balance, which recorded a surplus of 4.4 trillion yen in July, the highest monthly figure on record.
4
5<<Question>>
6What is Japan's primary income balance currently?1<<References>>
21
3
4<<Answer>>
54.4 trillion yen1from vllm import LLM, SamplingParams
2
3llm = LLM(model="lightblue/kurage-en")
4sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
5
6def create_rag_prompt(contexts, question):
7
8 context_str = "\n\n".join([f"<<Chunk {i+1}>>\n{x}" for i, x in enumerate(contexts)])
9
10 str_inputs = f"""{context_str}
11
12 <<Question>>
13 {question}"""
14
15 chat = [
16 {"role": "user", "content": str_inputs},
17 ]
18
19 return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
20
21contexts = [
22 "Junko Nakagawa, a member of the Bank of Japan's Policy Board, stated on the 11th that real interest rates are currently at an extremely low level. She mentioned that if the BOJ's economic and price outlook materializes in the future, the degree of monetary easing would be adjusted from the perspective of achieving the price target.",
23 "Japan's current account surplus in July was 3.2 trillion yen, the highest monthly surplus on record for the month of July. However, the surplus continues to be driven by the primary income balance, which recorded a surplus of 4.4 trillion yen in July, the highest monthly figure on record.",
24 "Finance Minister Shunichi Suzuki appointed Kenji Suwazono, former Director-General of the Customs and Tariff Bureau at the Ministry of Finance, as the new Executive Director of the Bank of Japan effective the 10th. Suwazono succeeds Masaaki Kaizuka, whose term ended on the 9th, and his term will last for four years.",
25 "In the yen appreciation phase of August, it has become a topic in the foreign exchange market that Japanese institutional investors engaged in the largest-ever outward securities investment."
26]
27
28question = "What is Japan's primary income balance currently?"
29
30outputs = llm.generate([create_rag_prompt([x], question) for x in contexts], sampling_params)
31
32print("\n\n".join([f"{i+1}.\n{o.outputs[0].text}" for i, o in enumerate(outputs)]))
33# 1.
34# <<References>>
35# None
36
37# 2.
38# <<References>>
39# 1
40#
41# <<Answer>>
42# 4.4 trillion yen.
43
44# 3.
45# <<References>>
46# None
47
48# 4.
49# <<References>>
50# None
511<<Chunk 1>>
2Japan's current account surplus in July was 3.2 trillion yen, the highest monthly surplus on record for the month of July.
3However, the surplus continues to be driven by the primary income balance, which recorded a surplus of 4.4 trillion yen in July, the highest monthly figure on record.
4
5<<Question>>
6What is Japan's primary income balance currently? <<Long>>1<<References>>
21
3
4<<Answer>>
54.4 trillion yen1from vllm import LLM, SamplingParams
2
3llm = LLM(model="lightblue/kurage-en")
4sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
5
6def create_rag_prompt(contexts, question):
7
8 context_str = "\n\n".join([f"<<Chunk {i+1}>>\n{x}" for i, x in enumerate(contexts)])
9
10 str_inputs = f"""{context_str}
11
12 <<Question>>
13 {question}"""
14
15 chat = [
16 {"role": "user", "content": str_inputs},
17 ]
18
19 return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
20
21contexts = [
22 "Junko Nakagawa, a member of the Bank of Japan's Policy Board, stated on the 11th that real interest rates are currently at an extremely low level. She mentioned that if the BOJ's economic and price outlook materializes in the future, the degree of monetary easing would be adjusted from the perspective of achieving the price target.",
23 "Japan's current account surplus in July was 3.2 trillion yen, the highest monthly surplus on record for the month of July. However, the surplus continues to be driven by the primary income balance, which recorded a surplus of 4.4 trillion yen in July, the highest monthly figure on record.",
24 "Finance Minister Shunichi Suzuki appointed Kenji Suwazono, former Director-General of the Customs and Tariff Bureau at the Ministry of Finance, as the new Executive Director of the Bank of Japan effective the 10th. Suwazono succeeds Masaaki Kaizuka, whose term ended on the 9th, and his term will last for four years.",
25 "In the yen appreciation phase of August, it has become a topic in the foreign exchange market that Japanese institutional investors engaged in the largest-ever outward securities investment."
26]
27
28question = "What is Japan's primary income balance currently? <<Long>>"
29
30inputs = create_rag_prompt(contexts, question)
31
32outputs = llm.generate([inputs], sampling_params)
33
34print(outputs[0].outputs[0].text)
35
36# <<References>>
37# 2
38#
39# <<Answer>>
40# Japan's primary income balance recorded a surplus of 4.4 trillion yen in July.1<<Chunk 1>>
2Junko Nakagawa, a member of the Bank of Japan's Policy Board, stated on the 11th that real interest rates are currently at an extremely low level.
3She mentioned that if the BOJ's economic and price outlook materializes in the future, the degree of monetary easing would be adjusted from the perspective of achieving the price target.
4
5<<Chunk 2>>
67月の日本の経常収支は3.2兆円の黒字となり、7月としては過去最高の黒字額を記録した。しかし、黒字に貢献しているのは相変わらず第一次所得収支の黒字で、7月は4.4兆円の黒字を記録し、1カ月の黒字額としては過去最高を記録した。
7
8<<Chunk 3>>
9รัฐมนตรีว่าการกระทรวงการคลัง ชุนอิจิ สุซูกิ ได้แต่งตั้ง เค็นจิ สุวาโซโนะ อดีตอธิบดีกรมศุลกากรและภาษีสิ่งนำเข้าแห่งกระทรวงการคลัง เป็นกรรมการบริหารธนาคารแห่งประเทศญี่ปุ่นคนใหม่ มีผลตั้งแต่วันที่ 10 สุวาโซโนะจะมาแทน มาซาอะกิ ไคซูกะ ที่พ้นวาระไปในวันที่ 9 โดยมีวาระ 4 ปี
10
11<<Chunk 4>>
12In the yen appreciation phase of August, it has become a topic in the foreign exchange market that Japanese institutional investors engaged in the largest-ever outward securities investment.
13
14<<Question>>
15What is Japan's primary income balance currently?1<<References>>
22
3
4<<Answer>>
54.4 trillion yen1
2from vllm import LLM, SamplingParams
3
4llm = LLM(model="lightblue/kurage-en")
5sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
6
7def create_rag_prompt(contexts, question):
8
9 context_str = "\n\n".join([f"<<Chunk {i+1}>>\n{x}" for i, x in enumerate(contexts)])
10
11 str_inputs = f"""{context_str}
12
13 <<Question>>
14 {question}"""
15
16 chat = [
17 {"role": "user", "content": str_inputs},
18 ]
19
20 return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
21
22contexts = [
23 "นากากาวะ จุนโกะ สมาชิกคณะกรรมการนโยบายการเงิน ธนาคารแห่งประเทศญี่ปุ่น กล่าวในวันที่ 11 ว่า อัตราดอกเบี้ยที่แท้จริงอยู่ในระดับต่ำมากในปัจจุบัน และกล่าวว่า หากแนวโน้มเศรษฐกิจและราคาของธนาคารกลางญี่ปุ่นเป็นจริงในอนาคต การผ่อนคลายนโยบายการเงินจะถูกปรับโดยพิจารณาจากการบรรลุเป้าหมายด้านราคา",
24 "Der Leistungsbilanzüberschuss Japans betrug im Juli 3,2 Billionen Yen, der höchste monatliche Überschuss aller Zeiten für den Monat Juli. Dieser Überschuss wird jedoch weiterhin durch das positive Primäreinkommen unterstützt, das im Juli einen Überschuss von 4,4 Billionen Yen verzeichnete, die höchste monatliche Zahl in der Geschichte.",
25 "鈴木俊一財務相は10日付で元財務省関税局長の諏訪園健司氏を新しい日銀理事に任命した。9日に任期満了で退任した貝塚正彰前理事の後任で、任期は4年。",
26 "Lors de la phase d'appréciation du yen en août, il est devenu un sujet dans le marché des changes que les investisseurs institutionnels japonais ont réalisé la plus grande investissement en titres à l'étranger jamais enregistré."
27]
28
29question = "What is Japan's primary income balance currently?"
30
31inputs = create_rag_prompt(contexts, question)
32
33outputs = llm.generate([inputs], sampling_params)
34
35print(outputs[0].outputs[0].text)
36# <<References>>
37# 2
38#
39# <<Answer>>
40# The primary income balance of Japan is currently 4.4 billion yen.
411<<Q&A Generation Context>>
2Japan's current account surplus in July was 3.2 trillion yen, the highest monthly surplus on record for the month of July.
3However, the surplus continues to be driven by the primary income balance, which recorded a surplus of 4.4 trillion yen in July, the highest monthly figure on record.1<<Question>>
2What is Japan's current account surplus in July?
3
4<<Answer>>
53.2 trillion yen1from vllm import LLM, SamplingParams
2
3llm = LLM(model="lightblue/kurage-en")
4sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
5
6context = "Finance Minister Shunichi Suzuki appointed Kenji Suwazono, former Director-General of the Customs and Tariff Bureau at the Ministry of Finance, as the new Executive Director of the Bank of Japan effective the 10th. Suwazono succeeds Masaaki Kaizuka, whose term ended on the 9th, and his term will last for four years.",
7
8def create_qagen_prompt(context):
9
10 str_inputs = f"""<<Q&A Generation Context>>
11{context}"""
12
13 chat = [
14 {"role": "user", "content": str_inputs},
15 ]
16
17 return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
18
19outputs = llm.generate([create_qagen_prompt(context)], sampling_params)
20
21print("\n\n".join([o.outputs[0].text for o in outputs]))
22# <<Question>>
23# Who was appointed as the new Executive Director of the Bank of Japan by Finance Minister Shunichi Suzuki?
24#
25# <<Answer>>
26# Kenji Suwazono