kunishou commited on
Commit
f922c14
·
1 Parent(s): 508b16a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +78 -0
README.md CHANGED
@@ -7,6 +7,84 @@ This dataset was created by automatically translating "OpenAssistant/oasst1" int
7
  The "ng_translation" flag indicates that the translation was not successful, and "1" means that the translation failed.
8
  Therefore, for data with "1", "text" and "text_en" contain the same text.
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  oasst1-ja-89k Repository
11
  https://github.com/kunishou/oasst1-89k-ja
12
 
 
7
  The "ng_translation" flag indicates that the translation was not successful, and "1" means that the translation failed.
8
  Therefore, for data with "1", "text" and "text_en" contain the same text.
9
 
10
+ 以下のコードを用いることで、 Instruction と Output (prompterの命令とassistantの回答)の形式に変換することができます。
11
+
12
+ 変換コード参考
13
+ https://github.com/h2oai/h2o-llmstudio/blob/5ebfd3879e226b4e1afd0a0b45eb632e60412129/app_utils/utils.py#L1888
14
+
15
+ ```python
16
+ pip install huggingface-hub
17
+ pip install datasets
18
+ ```
19
+
20
+ ```python
21
+ from datasets import load_dataset
22
+ import pandas as pd
23
+ import os
24
+ import json
25
+
26
+
27
+ # oasst1のオリジナルデータのロード
28
+ ds = load_dataset("OpenAssistant/oasst1")
29
+ train = ds["train"].to_pandas()
30
+ val = ds["validation"].to_pandas()
31
+
32
+ df_origin = pd.concat([train, val], axis=0).reset_index(drop=True)
33
+
34
+ # oasst1日本語翻訳データの読み込み
35
+ df_ja = pd.read_json("oasst1_ja_89k.json")
36
+
37
+ # oasst1のオリジナルデータと日本語翻訳データのマージ
38
+ df = pd.merge(df_origin, df_ja[["message_id", "text_ja"]], on="message_id", how="left").copy()
39
+ df["text"] = df["text_ja"]
40
+
41
+ df_assistant = df[(df.role == "assistant")].copy()
42
+ df_prompter = df[(df.role == "prompter")].copy()
43
+ df_prompter = df_prompter.set_index("message_id")
44
+ df_assistant["output"] = df_assistant["text"].values
45
+
46
+ inputs = []
47
+ parent_ids = []
48
+ for _, row in df_assistant.iterrows():
49
+ input = df_prompter.loc[row.parent_id]
50
+ inputs.append(input.text)
51
+ parent_ids.append(input.parent_id)
52
+
53
+ df_assistant["instruction"] = inputs
54
+ df_assistant["parent_id"] = parent_ids
55
+
56
+ df_assistant = df_assistant[
57
+ ["instruction", "output", "message_id", "parent_id", "lang", "rank"]
58
+ ].rename(columns={"message_id": "id"})
59
+
60
+
61
+ # 翻訳タスクのみデータに異常があるので除外
62
+ df_assistant2 = df_assistant[~df_assistant["instruction"].str.contains("翻訳")]
63
+
64
+
65
+ # これ以下でjsonファイルへ書き出し---------------
66
+
67
+ learn_datas = []
68
+ input_list = []
69
+
70
+ for n in range(len(df_assistant2)):
71
+ learn_data = {
72
+ "instruction": str(df_assistant2.iloc[n, 0]),
73
+ "input": "",
74
+ "output": ""
75
+ }
76
+
77
+ input_list.append(df_assistant2.iloc[n, 0])
78
+ learn_data["input"] = ""
79
+ learn_data["output"] = str(df_assistant2.iloc[n, 1])
80
+
81
+ learn_datas.append(learn_data)
82
+
83
+ json_learn_data = json.dumps(learn_datas, indent=4, ensure_ascii=False)
84
+ with open('oasst1_ja_51k_converted.json', 'w', encoding="utf-8") as f:
85
+ f.write(json_learn_data)
86
+ ```
87
+
88
  oasst1-ja-89k Repository
89
  https://github.com/kunishou/oasst1-89k-ja
90