ptrdvn commited on
Commit
4379666
1 Parent(s): df53ffb

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +522 -0
README.md ADDED
@@ -0,0 +1,522 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - vi
5
+ pipeline_tag: text-generation
6
+ tags:
7
+ - RAG
8
+ ---
9
+ # Kurage
10
+
11
+ <p align="center">
12
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/64b63f8ad57e02621dc93c8b/_SkPhhsg40juscfv9dU4v.jpeg" alt="An anime image of a pink and blue jellyfish surrounded by bubbles" width=500 style="border: 5px solid #3d3c3c"/>
13
+ </p>
14
+
15
+ Kurage is a multipurpose RAG model from [Lightblue](https://huggingface.co/lightblue) based on the Qwen 2 model ([Qwen/Qwen2-7B-Instruct](https://huggingface.co/Qwen/Qwen2-7B-Instruct)).
16
+
17
+ This version of the model has been trained to perform RAG in Vietnamese.
18
+
19
+ Features of these models include:
20
+
21
+ * **Multi-chunk RAG** - Performs RAG using multiple contexts at once.
22
+ * **Single-chunk RAG** - Performs RAG using one context at a time, allowing for parallel computing.
23
+ * **Answer extension** - Prompts the model to write a longer answer to a given question.
24
+ * **Multilingual RAG** - Performs RAG using contexts in languages different to the language of the question.
25
+ * **Q&A generation** - Generates questions and answers from a reference text in order to pre-index a set of texts.
26
+
27
+ Find out how to use these features below.
28
+
29
+ For models in other languages check [our Kurage collection](https://huggingface.co/collections/lightblue/kurage-66e40cbcc3b3a128bdf031f2).
30
+
31
+ This model was trained using a ml.gu7ef.8xlarge-gu100 instance on [Platform For AI](https://www.alibabacloud.com/en/product/machine-learning) from [Alibaba Cloud](https://www.alibabacloud.com/).
32
+
33
+ Note - There is a known issue with the single-chunk RAG mode sometimes saying that it cannot answer a question based on the text when it actually can. This was because our single-chunk training data was 50:50 answers vs cannot answer scenarios, making the model overly conservative. We will address this in a week or two when we re-train using 90:10 data with [the coming release of Qwen 2.5](https://x.com/zhouwenmeng/status/1834899729165304198).
34
+
35
+ # Basic usage
36
+
37
+ To use the model for basic multi-chunk RAG, you can use the following code:
38
+
39
+ NOTE - Change the model name to that of this repository to use this model with Vietnamese questions (e.g. "lightblue/kurage-en" → "lightblue/kurage-vi").
40
+
41
+ ```python
42
+ from vllm import LLM, SamplingParams
43
+
44
+ llm = LLM(model="lightblue/kurage-en")
45
+ sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
46
+
47
+ def create_rag_prompt(contexts, question):
48
+
49
+ context_str = "\n\n".join([f"<<Chunk {i+1}>>\n{x}" for i, x in enumerate(contexts)])
50
+
51
+ str_inputs = f"""{context_str}
52
+
53
+ <<Question>>
54
+ {question}"""
55
+
56
+ chat = [
57
+ {"role": "user", "content": str_inputs},
58
+ ]
59
+
60
+ return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
61
+
62
+ contexts = [
63
+ "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.",
64
+ "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.",
65
+ "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.",
66
+ "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."
67
+ ]
68
+
69
+ question = "What is Japan's primary income balance currently?"
70
+
71
+ inputs = create_rag_prompt(contexts, question)
72
+
73
+ outputs = llm.generate([inputs], sampling_params)
74
+
75
+ print(outputs[0].outputs[0].text)
76
+ # <<References>>
77
+ # 2
78
+ #
79
+ # <<Answer>>
80
+ # 4.4 trillion yen.
81
+ ```
82
+
83
+ # Feature: Multi-chunk RAG
84
+
85
+ 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.
86
+
87
+ <details>
88
+ <summary>Prompt style</summary>
89
+
90
+ ### Input:
91
+ ```markdown
92
+ <<Chunk 1>>
93
+ 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.
94
+ 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.
95
+
96
+ <<Chunk 2>>
97
+ Japan's current account surplus in July was 3.2 trillion yen, the highest monthly surplus on record for the month of July.
98
+ 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.
99
+
100
+ <<Chunk 3>>
101
+ 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.
102
+
103
+ <<Chunk 4>>
104
+ 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.
105
+
106
+ <<Question>>
107
+ What is Japan's primary income balance currently?
108
+ ```
109
+
110
+ ### Output:
111
+
112
+ ```markdown
113
+ <<References>>
114
+ 2
115
+
116
+ <<Answer>>
117
+ 4.4 trillion yen
118
+ ```
119
+
120
+ </details>
121
+
122
+ <details>
123
+ <summary>Python code</summary>
124
+
125
+ ```python
126
+ from vllm import LLM, SamplingParams
127
+
128
+ llm = LLM(model="lightblue/kurage-en")
129
+ sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
130
+
131
+ def create_rag_prompt(contexts, question):
132
+
133
+ context_str = "\n\n".join([f"<<Chunk {i+1}>>\n{x}" for i, x in enumerate(contexts)])
134
+
135
+ str_inputs = f"""{context_str}
136
+
137
+ <<Question>>
138
+ {question}"""
139
+
140
+ chat = [
141
+ {"role": "user", "content": str_inputs},
142
+ ]
143
+
144
+ return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
145
+
146
+ contexts = [
147
+ "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.",
148
+ "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.",
149
+ "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.",
150
+ "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."
151
+ ]
152
+
153
+ question = "What is Japan's primary income balance currently?"
154
+
155
+ inputs = create_rag_prompt(contexts, question)
156
+
157
+ outputs = llm.generate([inputs], sampling_params)
158
+
159
+ print(outputs[0].outputs[0].text)
160
+ # <<References>>
161
+ # 2
162
+ #
163
+ # <<Answer>>
164
+ # 4.4 trillion yen.
165
+
166
+ ```
167
+
168
+ </details>
169
+
170
+ <br/>
171
+
172
+ # Feature: Single-chunk RAG
173
+
174
+ 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.
175
+
176
+ <details>
177
+ <summary>Prompt style</summary>
178
+
179
+
180
+
181
+ ### Irrelevant context input:
182
+ ```markdown
183
+ <<Chunk 1>>
184
+ 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.
185
+ 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.
186
+
187
+ <<Question>>
188
+ What is Japan's primary income balance currently?
189
+ ```
190
+
191
+ ### Irrelevant context output:
192
+
193
+ ```markdown
194
+ <<References>>
195
+ None
196
+ ```
197
+
198
+
199
+ ### Relevant context input:
200
+ ```markdown
201
+ <<Chunk 1>>
202
+ Japan's current account surplus in July was 3.2 trillion yen, the highest monthly surplus on record for the month of July.
203
+ 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.
204
+
205
+ <<Question>>
206
+ What is Japan's primary income balance currently?
207
+ ```
208
+
209
+ ### Relevant context output:
210
+
211
+ ```markdown
212
+ <<References>>
213
+ 1
214
+
215
+ <<Answer>>
216
+ 4.4 trillion yen
217
+ ```
218
+
219
+ </details>
220
+
221
+ <details>
222
+ <summary>Python code</summary>
223
+
224
+ ```python
225
+ from vllm import LLM, SamplingParams
226
+
227
+ llm = LLM(model="lightblue/kurage-en")
228
+ sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
229
+
230
+ def create_rag_prompt(contexts, question):
231
+
232
+ context_str = "\n\n".join([f"<<Chunk {i+1}>>\n{x}" for i, x in enumerate(contexts)])
233
+
234
+ str_inputs = f"""{context_str}
235
+
236
+ <<Question>>
237
+ {question}"""
238
+
239
+ chat = [
240
+ {"role": "user", "content": str_inputs},
241
+ ]
242
+
243
+ return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
244
+
245
+ contexts = [
246
+ "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.",
247
+ "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.",
248
+ "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.",
249
+ "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."
250
+ ]
251
+
252
+ question = "What is Japan's primary income balance currently?"
253
+
254
+ outputs = llm.generate([create_rag_prompt([x], question) for x in contexts], sampling_params)
255
+
256
+ print("\n\n".join([f"{i+1}.\n{o.outputs[0].text}" for i, o in enumerate(outputs)]))
257
+ # 1.
258
+ # <<References>>
259
+ # None
260
+
261
+ # 2.
262
+ # <<References>>
263
+ # 1
264
+ #
265
+ # <<Answer>>
266
+ # 4.4 trillion yen.
267
+
268
+ # 3.
269
+ # <<References>>
270
+ # None
271
+
272
+ # 4.
273
+ # <<References>>
274
+ # None
275
+
276
+ ```
277
+
278
+ </details>
279
+ <br/>
280
+
281
+ # Feature: Answer extension
282
+
283
+ 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.
284
+
285
+ <details>
286
+ <summary>Prompt style</summary>
287
+
288
+ ### Input:
289
+ ```markdown
290
+ <<Chunk 1>>
291
+ Japan's current account surplus in July was 3.2 trillion yen, the highest monthly surplus on record for the month of July.
292
+ 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.
293
+
294
+ <<Question>>
295
+ What is Japan's primary income balance currently? <<Long>>
296
+ ```
297
+
298
+ ### Relevant context output:
299
+
300
+ ```markdown
301
+ <<References>>
302
+ 1
303
+
304
+ <<Answer>>
305
+ 4.4 trillion yen
306
+ ```
307
+
308
+ </details>
309
+
310
+ <details>
311
+ <summary>Python code</summary>
312
+
313
+ ```python
314
+ from vllm import LLM, SamplingParams
315
+
316
+ llm = LLM(model="lightblue/kurage-en")
317
+ sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
318
+
319
+ def create_rag_prompt(contexts, question):
320
+
321
+ context_str = "\n\n".join([f"<<Chunk {i+1}>>\n{x}" for i, x in enumerate(contexts)])
322
+
323
+ str_inputs = f"""{context_str}
324
+
325
+ <<Question>>
326
+ {question}"""
327
+
328
+ chat = [
329
+ {"role": "user", "content": str_inputs},
330
+ ]
331
+
332
+ return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
333
+
334
+ contexts = [
335
+ "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.",
336
+ "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.",
337
+ "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.",
338
+ "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."
339
+ ]
340
+
341
+ question = "What is Japan's primary income balance currently? <<Long>>"
342
+
343
+ inputs = create_rag_prompt(contexts, question)
344
+
345
+ outputs = llm.generate([inputs], sampling_params)
346
+
347
+ print(outputs[0].outputs[0].text)
348
+
349
+ # <<References>>
350
+ # 2
351
+ #
352
+ # <<Answer>>
353
+ # Japan's primary income balance recorded a surplus of 4.4 trillion yen in July.
354
+ ```
355
+
356
+ </details>
357
+ <br/>
358
+
359
+ # Feature: Multilinguality
360
+
361
+ We have trained our model to be able to answer questions in Vietnamese based on texts in other languages too!
362
+
363
+ (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.)
364
+
365
+ <details>
366
+ <summary>Prompt style</summary>
367
+
368
+ ### Input:
369
+ ```markdown
370
+ <<Chunk 1>>
371
+ 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.
372
+ 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.
373
+
374
+ <<Chunk 2>>
375
+ 7月の日本の経常収支は3.2兆円の黒字となり、7月としては過去最高の黒字額を記録した。しかし、黒字に貢献しているのは相変わらず第一次所得収支の黒字で、7月は4.4兆円の黒字を記録し、1カ月の黒字額としては過去最高を記録した。
376
+
377
+ <<Chunk 3>>
378
+ รัฐมนตรีว่าการกระทรวงการคลัง ชุนอิจิ สุซูกิ ได้แต่งตั้ง เค็นจิ สุวาโซโนะ อดีตอธิบดีกรมศุลกากรและภาษีสิ่งนำเข้าแห่งกระทรวงการคลัง เป็นกรรมการบริหารธนาคารแห่งประเทศญี่ปุ่นคนใหม่ มีผลตั้งแต่วันที่ 10 สุวาโซโนะจะมาแทน มาซาอะกิ ไคซูกะ ที่พ้นวาระไปในวันที่ 9 โดยมีวาระ 4 ปี
379
+
380
+ <<Chunk 4>>
381
+ 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.
382
+
383
+ <<Question>>
384
+ What is Japan's primary income balance currently?
385
+ ```
386
+
387
+ ### Output:
388
+
389
+ ```markdown
390
+ <<References>>
391
+ 2
392
+
393
+ <<Answer>>
394
+ 4.4 trillion yen
395
+ ```
396
+
397
+ </details>
398
+
399
+ <details>
400
+ <summary>Python code</summary>
401
+
402
+ ```python
403
+
404
+ from vllm import LLM, SamplingParams
405
+
406
+ llm = LLM(model="lightblue/kurage-en")
407
+ sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
408
+
409
+ def create_rag_prompt(contexts, question):
410
+
411
+ context_str = "\n\n".join([f"<<Chunk {i+1}>>\n{x}" for i, x in enumerate(contexts)])
412
+
413
+ str_inputs = f"""{context_str}
414
+
415
+ <<Question>>
416
+ {question}"""
417
+
418
+ chat = [
419
+ {"role": "user", "content": str_inputs},
420
+ ]
421
+
422
+ return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
423
+
424
+ contexts = [
425
+ "นากากาวะ จุนโกะ สมาชิกคณะกรรมการนโยบายการเงิน ธนาคารแห่งประเทศญี่ปุ่น กล่าวในวันที่ 11 ว่า อัตราดอกเบี้ยที่แท้จริงอยู่ในระดับต่ำมากในปัจจุบัน และกล่าวว่า หากแนวโน้มเศรษฐกิจและราคาของธนาคารกลางญี่ปุ่นเป็นจริงในอนาคต การผ่อนคลายนโยบายการเงินจะถูกปรับโดยพิจารณาจากการบรรลุเป้าหมายด้านราคา",
426
+ "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.",
427
+ "鈴木俊一財務相は10日付で元財務省関税局長の諏訪園健司氏を新しい日銀理事に任命した。9日に任期満了で退任した貝塚正彰前理事の後任で、任期は4年。",
428
+ "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é."
429
+ ]
430
+
431
+ question = "What is Japan's primary income balance currently?"
432
+
433
+ inputs = create_rag_prompt(contexts, question)
434
+
435
+ outputs = llm.generate([inputs], sampling_params)
436
+
437
+ print(outputs[0].outputs[0].text)
438
+ # <<References>>
439
+ # 2
440
+ #
441
+ # <<Answer>>
442
+ # The primary income balance of Japan is currently 4.4 billion yen.
443
+
444
+ ```
445
+
446
+ </details>
447
+ <br/>
448
+
449
+ # Feature: Q&A generation
450
+
451
+ 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.
452
+
453
+ <details>
454
+ <summary>Prompt style</summary>
455
+
456
+ ### Input:
457
+ ```markdown
458
+ <<Q&A Generation Context>>
459
+ Japan's current account surplus in July was 3.2 trillion yen, the highest monthly surplus on record for the month of July.
460
+ 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.
461
+ ```
462
+
463
+ ### Output:
464
+
465
+ ```markdown
466
+ <<Question>>
467
+ What is Japan's current account surplus in July?
468
+
469
+ <<Answer>>
470
+ 3.2 trillion yen
471
+ ```
472
+
473
+ </details>
474
+
475
+ <details>
476
+ <summary>Python code</summary>
477
+
478
+ ```python
479
+ from vllm import LLM, SamplingParams
480
+
481
+ llm = LLM(model="lightblue/kurage-en")
482
+ sampling_params = SamplingParams(temperature=0.2, top_p=0.95, max_tokens=128)
483
+
484
+ 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.",
485
+
486
+ def create_qagen_prompt(context):
487
+
488
+ str_inputs = f"""<<Q&A Generation Context>>
489
+ {context}"""
490
+
491
+ chat = [
492
+ {"role": "user", "content": str_inputs},
493
+ ]
494
+
495
+ return llm.llm_engine.tokenizer.tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
496
+
497
+ outputs = llm.generate([create_qagen_prompt(context)], sampling_params)
498
+
499
+ print("\n\n".join([o.outputs[0].text for o in outputs]))
500
+ # <<Question>>
501
+ # Who was appointed as the new Executive Director of the Bank of Japan by Finance Minister Shunichi Suzuki?
502
+ #
503
+ # <<Answer>>
504
+ # Kenji Suwazono
505
+ ```
506
+
507
+ </details>
508
+
509
+ <br/>
510
+
511
+ # Training data
512
+
513
+ We trained on chunks sourced from the documents in [MADLAD-400](https://huggingface.co/datasets/allenai/MADLAD-400) dataset that
514
+ had been evaluated to contain a higher amount of educational information according to a state-of-the-art LLM.
515
+
516
+ We took chunks of size 250 tokens, 500 tokens, and 1000 tokens randomly for each document.
517
+
518
+ We then used these chunks to generate questions and answers based on this text using a state-of-the-art LLM.
519
+
520
+ Finally, we selected negatives for each chunk using the similarity from the dense embeddings of the [BAAI/bge-m3](https://huggingface.co/BAAI/bge-m3) model.
521
+
522
+ The training data for this model can be found at [lightblue/kurage_training_data](https://huggingface.co/datasets/lightblue/kurage_training_data).