Update README.md
Browse files
README.md
CHANGED
@@ -28,18 +28,53 @@ Find out how to use these features below.
|
|
28 |
|
29 |
For models in other languages check [our Kurage collection]. A multilingual model is coming soon!
|
30 |
|
31 |
-
#
|
32 |
|
33 |
-
|
34 |
|
35 |
```python
|
36 |
from vllm import LLM, SamplingParams
|
37 |
|
38 |
-
llm = LLM(model="lightblue/kurage-
|
39 |
-
sampling_params = SamplingParams(temperature=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
```
|
41 |
|
42 |
-
|
43 |
|
44 |
This model can take multiple contexts and a question as input, and it will first output the references of the relevant contexts before outputting an answer to the question.
|
45 |
|
@@ -82,14 +117,10 @@ What is Japan's primary income balance currently?
|
|
82 |
<summary>Python code</summary>
|
83 |
|
84 |
```python
|
85 |
-
|
86 |
-
"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.",
|
87 |
-
"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.",
|
88 |
-
"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.",
|
89 |
-
"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."
|
90 |
-
]
|
91 |
|
92 |
-
|
|
|
93 |
|
94 |
def create_rag_prompt(contexts, question):
|
95 |
|
@@ -106,19 +137,32 @@ def create_rag_prompt(contexts, question):
|
|
106 |
|
107 |
return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
108 |
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
-
|
112 |
|
113 |
outputs = llm.generate([inputs], sampling_params)
|
114 |
|
115 |
print(outputs[0].outputs[0].text)
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
```
|
117 |
|
118 |
</details>
|
119 |
|
120 |
|
121 |
-
|
122 |
|
123 |
This model can also take a single context and a question as input, and it will determine whether it can answer the question based on the context, outputting an answer if it can. This allows for parallel computing of multiple contexts at the same time.
|
124 |
|
@@ -171,14 +215,10 @@ What is Japan's primary income balance currently?
|
|
171 |
<summary>Python code</summary>
|
172 |
|
173 |
```python
|
174 |
-
|
175 |
-
"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.",
|
176 |
-
"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.",
|
177 |
-
"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.",
|
178 |
-
"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."
|
179 |
-
]
|
180 |
|
181 |
-
|
|
|
182 |
|
183 |
def create_rag_prompt(contexts, question):
|
184 |
|
@@ -195,14 +235,42 @@ def create_rag_prompt(contexts, question):
|
|
195 |
|
196 |
return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
197 |
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
-
print("\n\n".join([o.outputs[0].text for o in outputs]))
|
201 |
```
|
202 |
|
203 |
</details>
|
204 |
|
205 |
-
|
206 |
|
207 |
By default, this model is trained to output the shortest possible answer to a question. However, if you require a longer answer, you can prompt the model to write a longer answer by writing " <<Long>>" after your question.
|
208 |
|
@@ -235,14 +303,10 @@ What is Japan's primary income balance currently? <<Long>>
|
|
235 |
<summary>Python code</summary>
|
236 |
|
237 |
```python
|
238 |
-
|
239 |
-
"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.",
|
240 |
-
"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.",
|
241 |
-
"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.",
|
242 |
-
"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."
|
243 |
-
]
|
244 |
|
245 |
-
|
|
|
246 |
|
247 |
def create_rag_prompt(contexts, question):
|
248 |
|
@@ -259,16 +323,34 @@ def create_rag_prompt(contexts, question):
|
|
259 |
|
260 |
return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
261 |
|
262 |
-
|
|
|
|
|
|
|
|
|
|
|
263 |
|
264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
```
|
266 |
|
267 |
</details>
|
268 |
|
269 |
-
|
270 |
|
271 |
-
We have trained our model to be able to answer questions in
|
|
|
272 |
|
273 |
<details>
|
274 |
<summary>Prompt style</summary>
|
@@ -308,14 +390,11 @@ What is Japan's primary income balance currently?
|
|
308 |
<summary>Python code</summary>
|
309 |
|
310 |
```python
|
311 |
-
contexts = [
|
312 |
-
"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.",
|
313 |
-
"7月の日本の経常収支は3.2兆円の黒字となり、7月としては過去最高の黒字額を記録した。しかし、黒字に貢献しているのは相変わらず第一次所得収支の黒字で、7月は4.4兆円の黒字を記録し、1カ月の黒字額としては過去最高を記録した。",
|
314 |
-
"รัฐมนตรีว่าการกระทรวงการคลัง ชุนอิจิ สุซูกิ ได้แต่งตั้ง เค็นจิ สุวาโซโนะ อดีตอธิบดีกรมศุลกากรและภาษีสิ่งนำเข้าแห่งกระทรวงการคลัง เป็นกรรมการบริหารธนาคารแห่งประเทศญี่ปุ่นคนใหม่ มีผลตั้งแต่วันที่ 10 สุวาโซโนะจะมาแทน มาซาอะกิ ไคซูกะ ที่พ้นวาระไปในวันที่ 9 โดยมีวาระ 4 ปี",
|
315 |
-
"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."
|
316 |
-
]
|
317 |
|
318 |
-
|
|
|
|
|
|
|
319 |
|
320 |
def create_rag_prompt(contexts, question):
|
321 |
|
@@ -332,18 +411,31 @@ def create_rag_prompt(contexts, question):
|
|
332 |
|
333 |
return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
334 |
|
335 |
-
|
|
|
|
|
|
|
|
|
|
|
336 |
|
337 |
-
|
|
|
|
|
338 |
|
339 |
outputs = llm.generate([inputs], sampling_params)
|
340 |
|
341 |
print(outputs[0].outputs[0].text)
|
|
|
|
|
|
|
|
|
|
|
|
|
342 |
```
|
343 |
|
344 |
</details>
|
345 |
|
346 |
-
|
347 |
|
348 |
This model can also generate questions and answers based on a piece of text. This can be useful for pre-indexing a database or fine-tuning IR models that will then be used for RAG.
|
349 |
|
@@ -373,14 +465,12 @@ What is Japan's current account surplus in July?
|
|
373 |
<summary>Python code</summary>
|
374 |
|
375 |
```python
|
376 |
-
|
377 |
-
"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.",
|
378 |
-
"7月の日本の経常収支は3.2兆円の黒字となり、7月としては過去最高の黒字額を記録した。しかし、黒字に貢献しているのは相変わらず第一次所得収支の黒字で、7月は4.4兆円の黒字を記録し、1カ月の黒字額としては過去最高を記録した。",
|
379 |
-
"รัฐมนตรีว่าการกระทรวงการคลัง ชุนอิจิ สุซูกิ ได้แต่งตั้ง เค็นจิ สุวาโซโนะ อดีตอธิบดีกรมศุลกากรและภาษีสิ่งนำเข้าแห่งกระทรวงการคลัง เป็นกรรมการบริหารธนาคารแห่งประเทศญี่ปุ่นคนใหม่ มีผลตั้งแต่วันที่ 10 สุวาโซโนะจะมาแทน มาซาอะกิ ไคซูกะ ที่พ้นวาระไปในวันที่ 9 โดยมีวาระ 4 ปี",
|
380 |
-
"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."
|
381 |
-
]
|
382 |
|
383 |
-
|
|
|
|
|
|
|
384 |
|
385 |
def create_qagen_prompt(context):
|
386 |
|
@@ -393,11 +483,14 @@ def create_qagen_prompt(context):
|
|
393 |
|
394 |
return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
395 |
|
396 |
-
|
397 |
-
|
398 |
-
outputs = llm.generate(inputs, sampling_params)
|
399 |
|
400 |
print("\n\n".join([o.outputs[0].text for o in outputs]))
|
|
|
|
|
|
|
|
|
|
|
401 |
```
|
402 |
|
403 |
</details>
|
|
|
28 |
|
29 |
For models in other languages check [our Kurage collection]. A multilingual model is coming soon!
|
30 |
|
31 |
+
# Basic usage
|
32 |
|
33 |
+
To use the model for basic multi-chunk RAG, you can use the following code:
|
34 |
|
35 |
```python
|
36 |
from vllm import LLM, SamplingParams
|
37 |
|
38 |
+
llm = LLM(model="lightblue/kurage-en")
|
39 |
+
sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
|
40 |
+
|
41 |
+
def create_rag_prompt(contexts, question):
|
42 |
+
|
43 |
+
context_str = "\n\n".join([f"<<Chunk {i+1}>>\n{x}" for i, x in enumerate(contexts)])
|
44 |
+
|
45 |
+
str_inputs = f"""{context_str}
|
46 |
+
|
47 |
+
<<Question>>
|
48 |
+
{question}"""
|
49 |
+
|
50 |
+
chat = [
|
51 |
+
{"role": "user", "content": str_inputs},
|
52 |
+
]
|
53 |
+
|
54 |
+
return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
55 |
+
|
56 |
+
contexts = [
|
57 |
+
"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.",
|
58 |
+
"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.",
|
59 |
+
"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.",
|
60 |
+
"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."
|
61 |
+
]
|
62 |
+
|
63 |
+
question = "What is Japan's primary income balance currently?"
|
64 |
+
|
65 |
+
inputs = create_rag_prompt(contexts, question)
|
66 |
+
|
67 |
+
outputs = llm.generate([inputs], sampling_params)
|
68 |
+
|
69 |
+
print(outputs[0].outputs[0].text)
|
70 |
+
# <<References>>
|
71 |
+
# 2
|
72 |
+
#
|
73 |
+
# <<Answer>>
|
74 |
+
# 4.4 trillion yen.
|
75 |
```
|
76 |
|
77 |
+
# Feature: Multi-chunk RAG
|
78 |
|
79 |
This model can take multiple contexts and a question as input, and it will first output the references of the relevant contexts before outputting an answer to the question.
|
80 |
|
|
|
117 |
<summary>Python code</summary>
|
118 |
|
119 |
```python
|
120 |
+
from vllm import LLM, SamplingParams
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
+
llm = LLM(model="lightblue/kurage-en")
|
123 |
+
sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
|
124 |
|
125 |
def create_rag_prompt(contexts, question):
|
126 |
|
|
|
137 |
|
138 |
return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
139 |
|
140 |
+
contexts = [
|
141 |
+
"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.",
|
142 |
+
"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.",
|
143 |
+
"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.",
|
144 |
+
"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."
|
145 |
+
]
|
146 |
+
|
147 |
+
question = "What is Japan's primary income balance currently?"
|
148 |
|
149 |
+
inputs = create_rag_prompt(contexts, question)
|
150 |
|
151 |
outputs = llm.generate([inputs], sampling_params)
|
152 |
|
153 |
print(outputs[0].outputs[0].text)
|
154 |
+
# <<References>>
|
155 |
+
# 2
|
156 |
+
#
|
157 |
+
# <<Answer>>
|
158 |
+
# 4.4 trillion yen.
|
159 |
+
|
160 |
```
|
161 |
|
162 |
</details>
|
163 |
|
164 |
|
165 |
+
# Feature: Single-chunk RAG
|
166 |
|
167 |
This model can also take a single context and a question as input, and it will determine whether it can answer the question based on the context, outputting an answer if it can. This allows for parallel computing of multiple contexts at the same time.
|
168 |
|
|
|
215 |
<summary>Python code</summary>
|
216 |
|
217 |
```python
|
218 |
+
from vllm import LLM, SamplingParams
|
|
|
|
|
|
|
|
|
|
|
219 |
|
220 |
+
llm = LLM(model="lightblue/kurage-en")
|
221 |
+
sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
|
222 |
|
223 |
def create_rag_prompt(contexts, question):
|
224 |
|
|
|
235 |
|
236 |
return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
237 |
|
238 |
+
contexts = [
|
239 |
+
"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.",
|
240 |
+
"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.",
|
241 |
+
"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.",
|
242 |
+
"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."
|
243 |
+
]
|
244 |
+
|
245 |
+
question = "What is Japan's primary income balance currently?"
|
246 |
+
|
247 |
+
outputs = llm.generate([create_rag_prompt([x], question) for x in contexts], sampling_params)
|
248 |
+
|
249 |
+
print("\n\n".join([f"{i+1}.\n{o.outputs[0].text}" for i, o in enumerate(outputs)]))
|
250 |
+
# 1.
|
251 |
+
# <<References>>
|
252 |
+
# None
|
253 |
+
|
254 |
+
# 2.
|
255 |
+
# <<References>>
|
256 |
+
# 1
|
257 |
+
#
|
258 |
+
# <<Answer>>
|
259 |
+
# 4.4 trillion yen.
|
260 |
+
|
261 |
+
# 3.
|
262 |
+
# <<References>>
|
263 |
+
# None
|
264 |
+
|
265 |
+
# 4.
|
266 |
+
# <<References>>
|
267 |
+
# None
|
268 |
|
|
|
269 |
```
|
270 |
|
271 |
</details>
|
272 |
|
273 |
+
# Feature: Answer extension
|
274 |
|
275 |
By default, this model is trained to output the shortest possible answer to a question. However, if you require a longer answer, you can prompt the model to write a longer answer by writing " <<Long>>" after your question.
|
276 |
|
|
|
303 |
<summary>Python code</summary>
|
304 |
|
305 |
```python
|
306 |
+
from vllm import LLM, SamplingParams
|
|
|
|
|
|
|
|
|
|
|
307 |
|
308 |
+
llm = LLM(model="lightblue/kurage-en")
|
309 |
+
sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
|
310 |
|
311 |
def create_rag_prompt(contexts, question):
|
312 |
|
|
|
323 |
|
324 |
return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
325 |
|
326 |
+
contexts = [
|
327 |
+
"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.",
|
328 |
+
"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.",
|
329 |
+
"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.",
|
330 |
+
"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."
|
331 |
+
]
|
332 |
|
333 |
+
question = "What is Japan's primary income balance currently? <<Long>>"
|
334 |
+
|
335 |
+
inputs = create_rag_prompt(contexts, question)
|
336 |
+
|
337 |
+
outputs = llm.generate([inputs], sampling_params)
|
338 |
+
|
339 |
+
print(outputs[0].outputs[0].text)
|
340 |
+
|
341 |
+
# <<References>>
|
342 |
+
# 2
|
343 |
+
#
|
344 |
+
# <<Answer>>
|
345 |
+
# Japan's primary income balance recorded a surplus of 4.4 trillion yen in July.
|
346 |
```
|
347 |
|
348 |
</details>
|
349 |
|
350 |
+
# Feature: Multilinguality
|
351 |
|
352 |
+
We have trained our model to be able to answer questions in English based on texts in other languages too!
|
353 |
+
(Note - this is still giving variable results depending on the question and the language of the correct reference. Stay tuned for further improvements in the future.)
|
354 |
|
355 |
<details>
|
356 |
<summary>Prompt style</summary>
|
|
|
390 |
<summary>Python code</summary>
|
391 |
|
392 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
393 |
|
394 |
+
from vllm import LLM, SamplingParams
|
395 |
+
|
396 |
+
llm = LLM(model="lightblue/kurage-en")
|
397 |
+
sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
|
398 |
|
399 |
def create_rag_prompt(contexts, question):
|
400 |
|
|
|
411 |
|
412 |
return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
413 |
|
414 |
+
contexts = [
|
415 |
+
"นากากาวะ จุนโกะ สมาชิกคณะกรรมการนโยบายการเงิน ธนาคารแห่งประเทศญี่ปุ่น กล่าวในวันที่ 11 ว่า อัตราดอกเบี้ยที่แท้จริงอยู่ในระดับต่ำมากในปัจจุบัน และกล่าวว่า หากแนวโน้มเศรษฐกิจและราคาของธนาคารกลางญี่ปุ่นเป็นจริงในอนาคต การผ่อนคลายนโยบายการเงินจะถูกปรับโดยพิจารณาจากการบรรลุเป้าหมายด้านราคา",
|
416 |
+
"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.",
|
417 |
+
"鈴木俊一財務相は10日付で元財務省関税局長の諏訪園健司氏を新しい日銀理事に任命した。9日に任期満了で退任した貝塚正彰前理事の後任で、任期は4年。",
|
418 |
+
"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é."
|
419 |
+
]
|
420 |
|
421 |
+
question = "What is Japan's primary income balance currently?"
|
422 |
+
|
423 |
+
inputs = create_rag_prompt(contexts, question)
|
424 |
|
425 |
outputs = llm.generate([inputs], sampling_params)
|
426 |
|
427 |
print(outputs[0].outputs[0].text)
|
428 |
+
# <<References>>
|
429 |
+
# 2
|
430 |
+
#
|
431 |
+
# <<Answer>>
|
432 |
+
# The primary income balance of Japan is currently 4.4 billion yen.
|
433 |
+
|
434 |
```
|
435 |
|
436 |
</details>
|
437 |
|
438 |
+
# Feature: Q&A generation
|
439 |
|
440 |
This model can also generate questions and answers based on a piece of text. This can be useful for pre-indexing a database or fine-tuning IR models that will then be used for RAG.
|
441 |
|
|
|
465 |
<summary>Python code</summary>
|
466 |
|
467 |
```python
|
468 |
+
from vllm import LLM, SamplingParams
|
|
|
|
|
|
|
|
|
|
|
469 |
|
470 |
+
llm = LLM(model="lightblue/kurage-en")
|
471 |
+
sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
|
472 |
+
|
473 |
+
context = "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.",
|
474 |
|
475 |
def create_qagen_prompt(context):
|
476 |
|
|
|
483 |
|
484 |
return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
485 |
|
486 |
+
outputs = llm.generate([create_qagen_prompt(context)], sampling_params)
|
|
|
|
|
487 |
|
488 |
print("\n\n".join([o.outputs[0].text for o in outputs]))
|
489 |
+
# <<Question>>
|
490 |
+
# Who was appointed as the new Executive Director of the Bank of Japan by Finance Minister Shunichi Suzuki?
|
491 |
+
#
|
492 |
+
# <<Answer>>
|
493 |
+
# Kenji Suwazono
|
494 |
```
|
495 |
|
496 |
</details>
|