hiroki-rad commited on
Commit
f8090e0
·
verified ·
1 Parent(s): a3d7d26

final version

Browse files
Files changed (1) hide show
  1. README.md +30 -18
README.md CHANGED
@@ -7,7 +7,7 @@ base_model:
7
  - llm-jp/llm-jp-3-13b
8
  ---
9
  ```python
10
- !pip install -U transformers vllm triton --q
11
 
12
  # GitHubをclone
13
  !git clone https://github.com/y-hiroki-radiotech/llm-final-task.git
@@ -21,23 +21,36 @@ import pandas as pd
21
  from vllm import LLM
22
  from tqdm import tqdm
23
  import json
 
 
 
 
24
 
25
  # JSONLファイルを読み込む
26
  file_path = 'elyza-tasks-100-TV_0.jsonl'
27
  data = pd.read_json(file_path, lines=True)
28
 
 
 
 
 
 
 
29
 
30
- def set_seed(seed):
31
- random.seed(seed)
32
- os.environ["PYTHONHASHSEED"] = str(seed)
33
- np.random.seed(seed)
34
- torch.manual_seed(seed)
35
- torch.cuda.manual_seed(seed)
36
- torch.cuda.manual_seed_all(seed)
37
- torch.backends.cudnn.deterministic = True
38
- torch.backends.cudnn.benchmark = False
39
 
40
- set_seed(42)
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  # vllmを使う
43
  model_name = "hiroki-rad/llm-jp-llm-jp-3-13b-128-ft-3000"
@@ -46,18 +59,17 @@ llm = LLM(model=model_name)
46
  # 2回考えるように推論するクラスをインスタンス化
47
  from two_stage_think import TwoStageThinking
48
 
 
49
  thinking_generator = TwoStageThinking(llm)
50
 
51
- # データフレームでの使用例
52
  results = []
53
- for row in tqdm(data.itertuples(), desc="生成中"):
54
- first, second = thinking_generator.generate_complete_response(row)
55
- results.append(second)
56
-
57
 
 
58
  jsonl_data = []
59
-
60
- # Iterate through the data and outputs
61
  for i in range(len(data)):
62
  task_id = data.iloc[i]["task_id"] # Access task_id using the index
63
  output = results[i]
 
7
  - llm-jp/llm-jp-3-13b
8
  ---
9
  ```python
10
+ !pip install -U langchain-community langchain-huggingface vllm triton wandb weave langchain-huggingface langchain-chroma datasets --q
11
 
12
  # GitHubをclone
13
  !git clone https://github.com/y-hiroki-radiotech/llm-final-task.git
 
21
  from vllm import LLM
22
  from tqdm import tqdm
23
  import json
24
+ from datasets import
25
+
26
+ from custom_few_shot_prompt_template import CustomFewShotPromptTemplate
27
+
28
 
29
  # JSONLファイルを読み込む
30
  file_path = 'elyza-tasks-100-TV_0.jsonl'
31
  data = pd.read_json(file_path, lines=True)
32
 
33
+ # example selector用のデータ
34
+ df = load_dataset("elyza/ELYZA-tasks-100", split="test")
35
+ df = df.to_pandas()
36
+ examples = []
37
+ for row in df.itertuples():
38
+ examples.append({"input": row.input, "output": row.output})
39
 
 
 
 
 
 
 
 
 
 
40
 
41
+ few_shot = CustomFewShotPromptTemplate(examples)
42
+ # few-shot-selector
43
+ few_shot_list = []
44
+ for row in tqdm(data.itertuples(), desc="生成中"):
45
+ few_shot_list.append(few_shot.format(row.input))
46
+
47
+ # 一度キャッシュを削除する
48
+ if torch.cuda.is_available():
49
+ print("Clearing CUDA cache...")
50
+ torch.cuda.empty_cache()
51
+ print("CUDA cache cleared.")
52
+ else:
53
+ print("CUDA is not available on this system.")
54
 
55
  # vllmを使う
56
  model_name = "hiroki-rad/llm-jp-llm-jp-3-13b-128-ft-3000"
 
59
  # 2回考えるように推論するクラスをインスタンス化
60
  from two_stage_think import TwoStageThinking
61
 
62
+
63
  thinking_generator = TwoStageThinking(llm)
64
 
65
+ # 最終的に1回推論の回答を使うことにした
66
  results = []
67
+ for row, few_shot in tqdm(zip(data.itertuples(), few_shot_list), desc="生成中"):
68
+ first = thinking_generator.generate_complete_response(row, few_shot)
69
+ results.append(first)
 
70
 
71
+ # データの格納
72
  jsonl_data = []
 
 
73
  for i in range(len(data)):
74
  task_id = data.iloc[i]["task_id"] # Access task_id using the index
75
  output = results[i]