dh-mc commited on
Commit
0f06270
1 Parent(s): 1fea497

analyzed llama-3-8b rpp1.0

Browse files
.gitattributes CHANGED
@@ -67,3 +67,15 @@ results/mac-results_fine_tuned.csv filter=lfs diff=lfs merge=lfs -text
67
  results/mac-results_greedy_decoding_metrics.csv filter=lfs diff=lfs merge=lfs -text
68
  results/mac-results_few_shots_metrics.csv filter=lfs diff=lfs merge=lfs -text
69
  results/mac-results_fine_tuned_metrics.csv filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  results/mac-results_greedy_decoding_metrics.csv filter=lfs diff=lfs merge=lfs -text
68
  results/mac-results_few_shots_metrics.csv filter=lfs diff=lfs merge=lfs -text
69
  results/mac-results_fine_tuned_metrics.csv filter=lfs diff=lfs merge=lfs -text
70
+ notebooks/02_Fine_Tune_OpenAI.ipynb filter=lfs diff=lfs merge=lfs -text
71
+ notebooks/02a_Fine_Tune_GPT-4o.ipynb filter=lfs diff=lfs merge=lfs -text
72
+ notebooks/03b_RAPGeT_v2_Data[[:space:]]Analysis_Generic_Prompt.ipynb filter=lfs diff=lfs merge=lfs -text
73
+ notebooks/00e_Data[[:space:]]Analysis_Fine_Tuned_RPP_MNT_2048.ipynb filter=lfs diff=lfs merge=lfs -text
74
+ notebooks/00b4080_Data[[:space:]]Analysis_Few_Shots.ipynb filter=lfs diff=lfs merge=lfs -text
75
+ notebooks/01b_Few-shot_Prompting_RTX4080.ipynb filter=lfs diff=lfs merge=lfs -text
76
+ notebooks/01c_Few-shot_Prompting_OpenAI.ipynb filter=lfs diff=lfs merge=lfs -text
77
+ notebooks/00b_Data[[:space:]]Analysis_Few_Shots.ipynb filter=lfs diff=lfs merge=lfs -text
78
+ notebooks/00c_Data[[:space:]]Analysis_Fine_Tuned.ipynb filter=lfs diff=lfs merge=lfs -text
79
+ notebooks/00d_Data[[:space:]]Analysis_Fine_Tuned_RPP.ipynb filter=lfs diff=lfs merge=lfs -text
80
+ notebooks/00f_Data[[:space:]]Analysis_Fine_Tuned_RPP_Generic_Prompt.ipynb filter=lfs diff=lfs merge=lfs -text
81
+ notebooks/03a_RAPGeT_v2_Data[[:space:]]Analysis_Chat_Template.ipynb filter=lfs diff=lfs merge=lfs -text
app.py CHANGED
@@ -1,11 +1,71 @@
 
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  """
5
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
  """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
 
 
 
 
 
8
 
 
9
 
10
  def respond(
11
  message,
@@ -16,6 +76,7 @@ def respond(
16
  top_p,
17
  ):
18
  messages = [{"role": "system", "content": system_message}]
 
19
 
20
  for val in history:
21
  if val[0]:
@@ -23,30 +84,72 @@ def respond(
23
  if val[1]:
24
  messages.append({"role": "assistant", "content": val[1]})
25
 
26
- messages.append({"role": "user", "content": message})
27
 
28
- response = ""
29
 
 
30
  for message in client.chat_completion(
31
  messages,
32
  max_tokens=max_tokens,
33
  stream=True,
34
  temperature=temperature,
 
 
35
  top_p=top_p,
 
36
  ):
37
- token = message.choices[0].delta.content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
- response += token
40
- yield response
41
 
 
42
 
43
  """
44
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
  """
46
  demo = gr.ChatInterface(
47
  respond,
 
 
 
48
  additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
  gr.Slider(
 
1
+ import os
2
+ import sys
3
+ import evaluate
4
  import gradio as gr
5
  from huggingface_hub import InferenceClient
6
+ from dotenv import find_dotenv, load_dotenv
7
+
8
+ found_dotenv = find_dotenv(".env")
9
+
10
+ if len(found_dotenv) == 0:
11
+ found_dotenv = find_dotenv(".env.example")
12
+ print(f"loading env vars from: {found_dotenv}")
13
+ load_dotenv(found_dotenv, override=False)
14
+
15
+ path = os.path.dirname(found_dotenv)
16
+ print(f"Adding {path} to sys.path")
17
+ sys.path.append(path)
18
+
19
+ from llm_toolkit.llm_utils import *
20
+ from llm_toolkit.translation_utils import *
21
+ from eval_modules.calc_repetitions_v2d import detect_repetitions
22
+
23
+ model_name = os.getenv("MODEL_NAME") or "microsoft/Phi-3.5-mini-instruct"
24
+ num_shots = int(os.getenv("NUM_SHOTS", 10))
25
+ data_path = os.getenv("DATA_PATH")
26
+
27
+ comet = evaluate.load("comet", config_name="Unbabel/wmt22-cometkiwi-da", gpus=1)
28
+ meteor = evaluate.load("meteor")
29
+ bleu = evaluate.load("bleu")
30
+ rouge = evaluate.load("rouge")
31
+
32
+
33
+ def calc_perf_scores(prediction, source, reference, debug=False):
34
+ if debug:
35
+ print("prediction:", prediction)
36
+ print("source:", source)
37
+ print("reference:", reference)
38
+
39
+ if reference:
40
+ bleu_scores = bleu.compute(
41
+ predictions=[prediction], references=[reference], max_order=1
42
+ )
43
+ rouge_scores = rouge.compute(predictions=[prediction], references=[reference])
44
+ rouge_scores = rouge.compute(predictions=[prediction], references=[reference])
45
+ meteor_scores = meteor.compute(predictions=[prediction], references=[reference])
46
+
47
+ comet_metric = comet.compute(
48
+ predictions=[prediction], sources=[source], references=[reference]
49
+ )
50
+
51
+ result = {"bleu_scores": bleu_scores, "rouge_scores": rouge_scores, "meteor_scores":meteor_scores, "comet_scores": comet_metric}
52
+
53
+ if debug:
54
+ print("result:", result)
55
+
56
+ return result
57
 
58
  """
59
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
60
  """
61
+ # client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
62
+ client = InferenceClient(model_name)
63
+
64
+ datasets = load_translation_dataset(data_path)
65
+ print_row_details(datasets["test"].to_pandas())
66
+ translation_prompt = get_few_shot_prompt(datasets["train"], num_shots)
67
 
68
+ examples = [[row["chinese"]] for row in datasets["test"]][:5]
69
 
70
  def respond(
71
  message,
 
76
  top_p,
77
  ):
78
  messages = [{"role": "system", "content": system_message}]
79
+ source = message
80
 
81
  for val in history:
82
  if val[0]:
 
84
  if val[1]:
85
  messages.append({"role": "assistant", "content": val[1]})
86
 
87
+ messages.append({"role": "user", "content": translation_prompt.format(input=message)})
88
 
89
+ partial_text = ""
90
 
91
+ finish_reason = None
92
  for message in client.chat_completion(
93
  messages,
94
  max_tokens=max_tokens,
95
  stream=True,
96
  temperature=temperature,
97
+ frequency_penalty=None, # frequency_penalty,
98
+ presence_penalty=None, # presence_penalty,
99
  top_p=top_p,
100
+ seed=42,
101
  ):
102
+ finish_reason = message.choices[0].finish_reason
103
+ # print("finish_reason:", finish_reason)
104
+
105
+ if finish_reason is None:
106
+ new_text = message.choices[0].delta.content
107
+ partial_text += new_text
108
+ yield partial_text
109
+ else:
110
+ break
111
+
112
+ answer = partial_text
113
+ (whitespace_score, repetition_score, total_repetitions) = detect_repetitions(answer, debug=True)
114
+ partial_text += "\n\nRepetition Metrics:\n"
115
+ partial_text += f"1. Whitespace Score: {whitespace_score:.3f}\n"
116
+ partial_text += f"1. Repetition Score: {repetition_score:.3f}\n"
117
+ partial_text += f"1. Total Repetitions: {total_repetitions:.3f}\n"
118
+ partial_text += (
119
+ f"1. Non-Repetitive Ratio: {1 - total_repetitions / len(answer):.3f}\n"
120
+ )
121
+
122
+ partial_text += "\n\n Performance Metrics:\n"
123
+
124
+ if [source] in examples:
125
+ idx = examples.index([source])
126
+ reference = datasets["test"]["english"][idx]
127
+ else:
128
+ reference = ""
129
+
130
+ scores = calc_perf_scores(answer, source, reference, debug=True)
131
+
132
+ partial_text += f'1. COMET: {scores["comet_scores"]["mean_score"]:.3f}\n'
133
+ if reference:
134
+ partial_text += f'1. METEOR: {scores["meteor_scores"]["meteor"]:.3f}\n'
135
+ partial_text += f'1. BLEU-1: {scores["bleu_scores"]["bleu"]:.3f}\n'
136
+ partial_text += f'1. RougeL: {scores["rouge_scores"]["rougeL"]:.3f}\n'
137
+ partial_text += f"\n\nGround truth: {reference}\n"
138
 
139
+ partial_text += f"\n\nThe text generation has ended because: {finish_reason}\n"
 
140
 
141
+ yield partial_text
142
 
143
  """
144
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
145
  """
146
  demo = gr.ChatInterface(
147
  respond,
148
+ examples=examples,
149
+ cache_examples=False,
150
+ textbox=gr.Textbox(placeholder="Enter your Chinese sentence for translation"),
151
  additional_inputs=[
152
+ gr.Textbox(value="You are a helpful assistant that translates Chinese to English.", label="System message"),
153
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
154
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
155
  gr.Slider(
notebooks/00b4080_Data Analysis_Few_Shots.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
notebooks/00b_Data Analysis_Few_Shots.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
notebooks/00c_Data Analysis_Fine_Tuned.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
notebooks/00d_Data Analysis_Fine_Tuned_RPP.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
notebooks/00e_Data Analysis_Fine_Tuned_RPP_MNT_2048.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
notebooks/00f_Data Analysis_Fine_Tuned_RPP_Generic_Prompt.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
notebooks/01b_Few-shot_Prompting_RTX4080.ipynb CHANGED
@@ -1,1415 +1,3 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": 1,
6
- "metadata": {
7
- "executionInfo": {
8
- "elapsed": 476,
9
- "status": "ok",
10
- "timestamp": 1720679526275,
11
- "user": {
12
- "displayName": "HUANG DONGHAO _",
13
- "userId": "00977795705617022768"
14
- },
15
- "user_tz": -480
16
- },
17
- "id": "uWKRSV6eZsCn"
18
- },
19
- "outputs": [],
20
- "source": [
21
- "%load_ext autoreload\n",
22
- "%autoreload 2"
23
- ]
24
- },
25
- {
26
- "cell_type": "code",
27
- "execution_count": 2,
28
- "metadata": {
29
- "application/vnd.databricks.v1+cell": {
30
- "cellMetadata": {
31
- "byteLimit": 2048000,
32
- "rowLimit": 10000
33
- },
34
- "inputWidgets": {},
35
- "nuid": "6d394937-6c99-4a7c-9d32-7600a280032f",
36
- "showTitle": false,
37
- "title": ""
38
- },
39
- "colab": {
40
- "base_uri": "https://localhost:8080/"
41
- },
42
- "executionInfo": {
43
- "elapsed": 5,
44
- "status": "ok",
45
- "timestamp": 1720679529345,
46
- "user": {
47
- "displayName": "HUANG DONGHAO _",
48
- "userId": "00977795705617022768"
49
- },
50
- "user_tz": -480
51
- },
52
- "id": "G5pNu3zgZBrL",
53
- "outputId": "160a554f-fb08-4aa0-bc00-0422fb7c1fac"
54
- },
55
- "outputs": [
56
- {
57
- "name": "stdout",
58
- "output_type": "stream",
59
- "text": [
60
- "workding dir: d:\\code\\projects\\rapget-translation\n"
61
- ]
62
- }
63
- ],
64
- "source": [
65
- "import os\n",
66
- "import sys\n",
67
- "from pathlib import Path\n",
68
- "\n",
69
- "# check if workding_dir is in local variables\n",
70
- "if \"workding_dir\" not in locals():\n",
71
- " workding_dir = str(Path.cwd().parent)\n",
72
- "\n",
73
- "os.chdir(workding_dir)\n",
74
- "sys.path.append(workding_dir)\n",
75
- "print(\"workding dir:\", workding_dir)"
76
- ]
77
- },
78
- {
79
- "cell_type": "code",
80
- "execution_count": 3,
81
- "metadata": {
82
- "application/vnd.databricks.v1+cell": {
83
- "cellMetadata": {
84
- "byteLimit": 2048000,
85
- "rowLimit": 10000
86
- },
87
- "inputWidgets": {},
88
- "nuid": "9f67ec60-2f24-411c-84eb-0dd664b44775",
89
- "showTitle": false,
90
- "title": ""
91
- },
92
- "colab": {
93
- "base_uri": "https://localhost:8080/"
94
- },
95
- "executionInfo": {
96
- "elapsed": 3,
97
- "status": "ok",
98
- "timestamp": 1720679529345,
99
- "user": {
100
- "displayName": "HUANG DONGHAO _",
101
- "userId": "00977795705617022768"
102
- },
103
- "user_tz": -480
104
- },
105
- "id": "hPCC-6m7ZBrM",
106
- "outputId": "c7aa2c96-5e99-440a-c148-201d79465ff9"
107
- },
108
- "outputs": [
109
- {
110
- "name": "stdout",
111
- "output_type": "stream",
112
- "text": [
113
- "loading env vars from: d:\\code\\projects\\rapget-translation\\.env\n"
114
- ]
115
- },
116
- {
117
- "data": {
118
- "text/plain": [
119
- "True"
120
- ]
121
- },
122
- "execution_count": 3,
123
- "metadata": {},
124
- "output_type": "execute_result"
125
- }
126
- ],
127
- "source": [
128
- "from dotenv import find_dotenv, load_dotenv\n",
129
- "\n",
130
- "found_dotenv = find_dotenv(\".env\")\n",
131
- "\n",
132
- "if len(found_dotenv) == 0:\n",
133
- " found_dotenv = find_dotenv(\".env.example\")\n",
134
- "print(f\"loading env vars from: {found_dotenv}\")\n",
135
- "load_dotenv(found_dotenv, override=True)"
136
- ]
137
- },
138
- {
139
- "cell_type": "code",
140
- "execution_count": 4,
141
- "metadata": {
142
- "application/vnd.databricks.v1+cell": {
143
- "cellMetadata": {
144
- "byteLimit": 2048000,
145
- "rowLimit": 10000
146
- },
147
- "inputWidgets": {},
148
- "nuid": "f1597656-8042-4878-9d3b-9ebfb8dd86dc",
149
- "showTitle": false,
150
- "title": ""
151
- },
152
- "colab": {
153
- "base_uri": "https://localhost:8080/"
154
- },
155
- "executionInfo": {
156
- "elapsed": 3,
157
- "status": "ok",
158
- "timestamp": 1720679529345,
159
- "user": {
160
- "displayName": "HUANG DONGHAO _",
161
- "userId": "00977795705617022768"
162
- },
163
- "user_tz": -480
164
- },
165
- "id": "1M3IraVtZBrM",
166
- "outputId": "29ab35f6-2970-4ade-d85d-3174acf8cda0"
167
- },
168
- "outputs": [
169
- {
170
- "name": "stdout",
171
- "output_type": "stream",
172
- "text": [
173
- "01-ai/Yi-1.5-9B-Chat None True datasets/mac/mac.tsv results/mac-results_few_shots_4bit.csv False 300\n"
174
- ]
175
- }
176
- ],
177
- "source": [
178
- "import os\n",
179
- "\n",
180
- "model_name = os.getenv(\"MODEL_NAME\")\n",
181
- "adapter_name_or_path = os.getenv(\"ADAPTER_NAME_OR_PATH\")\n",
182
- "load_in_4bit = os.getenv(\"LOAD_IN_4BIT\") == \"true\"\n",
183
- "data_path = os.getenv(\"DATA_PATH\")\n",
184
- "results_path = os.getenv(\"RESULTS_PATH\")\n",
185
- "use_english_datasets = os.getenv(\"USE_ENGLISH_DATASETS\") == \"true\"\n",
186
- "max_new_tokens = int(os.getenv(\"MAX_NEW_TOKENS\", 2048))\n",
187
- "\n",
188
- "print(\n",
189
- " model_name,\n",
190
- " adapter_name_or_path,\n",
191
- " load_in_4bit,\n",
192
- " data_path,\n",
193
- " results_path,\n",
194
- " use_english_datasets,\n",
195
- " max_new_tokens,\n",
196
- ")"
197
- ]
198
- },
199
- {
200
- "cell_type": "code",
201
- "execution_count": 5,
202
- "metadata": {
203
- "application/vnd.databricks.v1+cell": {
204
- "cellMetadata": {
205
- "byteLimit": 2048000,
206
- "rowLimit": 10000
207
- },
208
- "inputWidgets": {},
209
- "nuid": "b2a43943-9324-4839-9a47-cfa72de2244b",
210
- "showTitle": false,
211
- "title": ""
212
- },
213
- "colab": {
214
- "base_uri": "https://localhost:8080/"
215
- },
216
- "executionInfo": {
217
- "elapsed": 564,
218
- "status": "ok",
219
- "timestamp": 1720679529907,
220
- "user": {
221
- "displayName": "HUANG DONGHAO _",
222
- "userId": "00977795705617022768"
223
- },
224
- "user_tz": -480
225
- },
226
- "id": "UgMvt6dIZBrM",
227
- "outputId": "ce37581c-fd26-46c2-ad87-d933d99f68f7"
228
- },
229
- "outputs": [
230
- {
231
- "name": "stdout",
232
- "output_type": "stream",
233
- "text": [
234
- "Python 3.11.9\n",
235
- "Name: torch\n",
236
- "Version: 2.4.0+cu124\n",
237
- "Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration\n",
238
- "Home-page: https://pytorch.org/\n",
239
- "Author: PyTorch Team\n",
240
- "Author-email: packages@pytorch.org\n",
241
- "License: BSD-3\n",
242
- "Location: C:\\Users\\dongh\\.conda\\envs\\rapget\\Lib\\site-packages\n",
243
- "Requires: filelock, fsspec, jinja2, networkx, sympy, typing-extensions\n",
244
- "Required-by: accelerate, bitsandbytes, peft, torchaudio, torchvision\n",
245
- "---\n",
246
- "Name: transformers\n",
247
- "Version: 4.43.3\n",
248
- "Summary: State-of-the-art Machine Learning for JAX, PyTorch and TensorFlow\n",
249
- "Home-page: https://github.com/huggingface/transformers\n",
250
- "Author: The Hugging Face team (past and future) with the help of all our contributors (https://github.com/huggingface/transformers/graphs/contributors)\n",
251
- "Author-email: transformers@huggingface.co\n",
252
- "License: Apache 2.0 License\n",
253
- "Location: C:\\Users\\dongh\\.conda\\envs\\rapget\\Lib\\site-packages\n",
254
- "Requires: filelock, huggingface-hub, numpy, packaging, pyyaml, regex, requests, safetensors, tokenizers, tqdm\n",
255
- "Required-by: peft\n",
256
- "CPU times: total: 0 ns\n",
257
- "Wall time: 6.94 s\n"
258
- ]
259
- }
260
- ],
261
- "source": [
262
- "%%time\n",
263
- "os.environ[\"TOKENIZERS_PARALLELISM\"] = \"true\"\n",
264
- "\n",
265
- "!python --version\n",
266
- "!pip show torch transformers"
267
- ]
268
- },
269
- {
270
- "cell_type": "code",
271
- "execution_count": 6,
272
- "metadata": {
273
- "colab": {
274
- "base_uri": "https://localhost:8080/"
275
- },
276
- "executionInfo": {
277
- "elapsed": 1685,
278
- "status": "ok",
279
- "timestamp": 1720679531591,
280
- "user": {
281
- "displayName": "HUANG DONGHAO _",
282
- "userId": "00977795705617022768"
283
- },
284
- "user_tz": -480
285
- },
286
- "id": "ZuS_FsLyZBrN",
287
- "outputId": "2cba0105-c505-4395-afbd-2f2fee6581d0"
288
- },
289
- "outputs": [
290
- {
291
- "name": "stderr",
292
- "output_type": "stream",
293
- "text": [
294
- "c:\\Users\\dongh\\.conda\\envs\\rapget\\Lib\\site-packages\\threadpoolctl.py:1214: RuntimeWarning: \n",
295
- "Found Intel OpenMP ('libiomp') and LLVM OpenMP ('libomp') loaded at\n",
296
- "the same time. Both libraries are known to be incompatible and this\n",
297
- "can cause random crashes or deadlocks on Linux when loaded in the\n",
298
- "same Python program.\n",
299
- "Using threadpoolctl may cause crashes or deadlocks. For more\n",
300
- "information and possible workarounds, please see\n",
301
- " https://github.com/joblib/threadpoolctl/blob/master/multiple_openmp.md\n",
302
- "\n",
303
- " warnings.warn(msg, RuntimeWarning)\n",
304
- "[nltk_data] Downloading package wordnet to\n",
305
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
306
- "[nltk_data] Package wordnet is already up-to-date!\n",
307
- "[nltk_data] Downloading package punkt to\n",
308
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
309
- "[nltk_data] Package punkt is already up-to-date!\n",
310
- "[nltk_data] Downloading package omw-1.4 to\n",
311
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
312
- "[nltk_data] Package omw-1.4 is already up-to-date!\n"
313
- ]
314
- },
315
- {
316
- "name": "stdout",
317
- "output_type": "stream",
318
- "text": [
319
- "loading: d:\\code\\projects\\rapget-translation\\eval_modules\\calc_repetitions.py\n",
320
- "loading d:\\code\\projects\\rapget-translation\\llm_toolkit\\translation_utils.py\n"
321
- ]
322
- },
323
- {
324
- "name": "stderr",
325
- "output_type": "stream",
326
- "text": [
327
- "[nltk_data] Downloading package wordnet to\n",
328
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
329
- "[nltk_data] Package wordnet is already up-to-date!\n",
330
- "[nltk_data] Downloading package punkt to\n",
331
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
332
- "[nltk_data] Package punkt is already up-to-date!\n",
333
- "[nltk_data] Downloading package omw-1.4 to\n",
334
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
335
- "[nltk_data] Package omw-1.4 is already up-to-date!\n"
336
- ]
337
- },
338
- {
339
- "name": "stdout",
340
- "output_type": "stream",
341
- "text": [
342
- "CUDA is available, we have found 1 GPU(s)\n",
343
- "NVIDIA GeForce RTX 4080 Laptop GPU\n",
344
- "CUDA version: 12.4\n"
345
- ]
346
- }
347
- ],
348
- "source": [
349
- "from llm_toolkit.llm_utils import *\n",
350
- "from llm_toolkit.translation_utils import *\n",
351
- "\n",
352
- "device = check_gpu()"
353
- ]
354
- },
355
- {
356
- "cell_type": "code",
357
- "execution_count": 7,
358
- "metadata": {},
359
- "outputs": [
360
- {
361
- "name": "stdout",
362
- "output_type": "stream",
363
- "text": [
364
- "loading model: 01-ai/Yi-1.5-9B-Chat with adapter: None\n"
365
- ]
366
- },
367
- {
368
- "data": {
369
- "application/vnd.jupyter.widget-view+json": {
370
- "model_id": "16faabb1083d4662b639c035b54844de",
371
- "version_major": 2,
372
- "version_minor": 0
373
- },
374
- "text/plain": [
375
- "tokenizer_config.json: 0%| | 0.00/1.67k [00:00<?, ?B/s]"
376
- ]
377
- },
378
- "metadata": {},
379
- "output_type": "display_data"
380
- },
381
- {
382
- "name": "stderr",
383
- "output_type": "stream",
384
- "text": [
385
- "c:\\Users\\dongh\\.conda\\envs\\rapget\\Lib\\site-packages\\huggingface_hub\\file_download.py:159: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\\Users\\dongh\\.cache\\huggingface\\hub\\models--01-ai--Yi-1.5-9B-Chat. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.\n",
386
- "To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to see activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development\n",
387
- " warnings.warn(message)\n"
388
- ]
389
- },
390
- {
391
- "data": {
392
- "application/vnd.jupyter.widget-view+json": {
393
- "model_id": "3316d03bf00d49c59537caf4fa45d683",
394
- "version_major": 2,
395
- "version_minor": 0
396
- },
397
- "text/plain": [
398
- "tokenizer.model: 0%| | 0.00/1.03M [00:00<?, ?B/s]"
399
- ]
400
- },
401
- "metadata": {},
402
- "output_type": "display_data"
403
- },
404
- {
405
- "data": {
406
- "application/vnd.jupyter.widget-view+json": {
407
- "model_id": "8ad82b2bf7224459a56668b0b34660f6",
408
- "version_major": 2,
409
- "version_minor": 0
410
- },
411
- "text/plain": [
412
- "tokenizer.json: 0%| | 0.00/3.60M [00:00<?, ?B/s]"
413
- ]
414
- },
415
- "metadata": {},
416
- "output_type": "display_data"
417
- },
418
- {
419
- "data": {
420
- "application/vnd.jupyter.widget-view+json": {
421
- "model_id": "654d3c4a90fe4011bee581af81770e36",
422
- "version_major": 2,
423
- "version_minor": 0
424
- },
425
- "text/plain": [
426
- "special_tokens_map.json: 0%| | 0.00/567 [00:00<?, ?B/s]"
427
- ]
428
- },
429
- "metadata": {},
430
- "output_type": "display_data"
431
- },
432
- {
433
- "data": {
434
- "application/vnd.jupyter.widget-view+json": {
435
- "model_id": "bdb46ebad4fe48e3b17e44b372f4c33b",
436
- "version_major": 2,
437
- "version_minor": 0
438
- },
439
- "text/plain": [
440
- "config.json: 0%| | 0.00/661 [00:00<?, ?B/s]"
441
- ]
442
- },
443
- "metadata": {},
444
- "output_type": "display_data"
445
- },
446
- {
447
- "data": {
448
- "application/vnd.jupyter.widget-view+json": {
449
- "model_id": "f5bf514086a34a99a3e83d8e3f6bf99e",
450
- "version_major": 2,
451
- "version_minor": 0
452
- },
453
- "text/plain": [
454
- "model.safetensors.index.json: 0%| | 0.00/35.8k [00:00<?, ?B/s]"
455
- ]
456
- },
457
- "metadata": {},
458
- "output_type": "display_data"
459
- },
460
- {
461
- "data": {
462
- "application/vnd.jupyter.widget-view+json": {
463
- "model_id": "2c63583627a14301949f4696a0777dbd",
464
- "version_major": 2,
465
- "version_minor": 0
466
- },
467
- "text/plain": [
468
- "Downloading shards: 0%| | 0/4 [00:00<?, ?it/s]"
469
- ]
470
- },
471
- "metadata": {},
472
- "output_type": "display_data"
473
- },
474
- {
475
- "data": {
476
- "application/vnd.jupyter.widget-view+json": {
477
- "model_id": "8c56c07a67ac477194351791eddc8069",
478
- "version_major": 2,
479
- "version_minor": 0
480
- },
481
- "text/plain": [
482
- "model-00001-of-00004.safetensors: 0%| | 0.00/4.93G [00:00<?, ?B/s]"
483
- ]
484
- },
485
- "metadata": {},
486
- "output_type": "display_data"
487
- },
488
- {
489
- "data": {
490
- "application/vnd.jupyter.widget-view+json": {
491
- "model_id": "cccfaf200fe340628649245e87205e5a",
492
- "version_major": 2,
493
- "version_minor": 0
494
- },
495
- "text/plain": [
496
- "model-00002-of-00004.safetensors: 0%| | 0.00/4.98G [00:00<?, ?B/s]"
497
- ]
498
- },
499
- "metadata": {},
500
- "output_type": "display_data"
501
- },
502
- {
503
- "data": {
504
- "application/vnd.jupyter.widget-view+json": {
505
- "model_id": "780839610e2245a99a2044f7108dce4a",
506
- "version_major": 2,
507
- "version_minor": 0
508
- },
509
- "text/plain": [
510
- "model-00003-of-00004.safetensors: 0%| | 0.00/4.97G [00:00<?, ?B/s]"
511
- ]
512
- },
513
- "metadata": {},
514
- "output_type": "display_data"
515
- },
516
- {
517
- "data": {
518
- "application/vnd.jupyter.widget-view+json": {
519
- "model_id": "12df1cda8a4c445cb7c96ccbe8c34921",
520
- "version_major": 2,
521
- "version_minor": 0
522
- },
523
- "text/plain": [
524
- "model-00004-of-00004.safetensors: 0%| | 0.00/2.78G [00:00<?, ?B/s]"
525
- ]
526
- },
527
- "metadata": {},
528
- "output_type": "display_data"
529
- },
530
- {
531
- "data": {
532
- "application/vnd.jupyter.widget-view+json": {
533
- "model_id": "a37aa5117f044c49806ae9cac830d440",
534
- "version_major": 2,
535
- "version_minor": 0
536
- },
537
- "text/plain": [
538
- "Loading checkpoint shards: 0%| | 0/4 [00:00<?, ?it/s]"
539
- ]
540
- },
541
- "metadata": {},
542
- "output_type": "display_data"
543
- },
544
- {
545
- "data": {
546
- "application/vnd.jupyter.widget-view+json": {
547
- "model_id": "61ea7704789942ce9ef72ec3f6f1d9be",
548
- "version_major": 2,
549
- "version_minor": 0
550
- },
551
- "text/plain": [
552
- "generation_config.json: 0%| | 0.00/132 [00:00<?, ?B/s]"
553
- ]
554
- },
555
- "metadata": {},
556
- "output_type": "display_data"
557
- },
558
- {
559
- "name": "stderr",
560
- "output_type": "stream",
561
- "text": [
562
- "Some parameters are on the meta device device because they were offloaded to the cpu.\n"
563
- ]
564
- }
565
- ],
566
- "source": [
567
- "model, tokenizer = load_model(model_name)"
568
- ]
569
- },
570
- {
571
- "cell_type": "code",
572
- "execution_count": 10,
573
- "metadata": {},
574
- "outputs": [
575
- {
576
- "name": "stdout",
577
- "output_type": "stream",
578
- "text": [
579
- "loading d:\\code\\projects\\rapget-translation\\llm_toolkit\\translation_utils.py\n"
580
- ]
581
- },
582
- {
583
- "name": "stderr",
584
- "output_type": "stream",
585
- "text": [
586
- "[nltk_data] Downloading package wordnet to\n",
587
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
588
- "[nltk_data] Package wordnet is already up-to-date!\n",
589
- "[nltk_data] Downloading package punkt to\n",
590
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
591
- "[nltk_data] Package punkt is already up-to-date!\n",
592
- "[nltk_data] Downloading package omw-1.4 to\n",
593
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
594
- "[nltk_data] Package omw-1.4 is already up-to-date!\n"
595
- ]
596
- },
597
- {
598
- "name": "stdout",
599
- "output_type": "stream",
600
- "text": [
601
- "loading train/test data files\n"
602
- ]
603
- },
604
- {
605
- "data": {
606
- "application/vnd.jupyter.widget-view+json": {
607
- "model_id": "f37f3ccde5c541f5a5c9eeb2df64613c",
608
- "version_major": 2,
609
- "version_minor": 0
610
- },
611
- "text/plain": [
612
- "Map: 0%| | 0/4528 [00:00<?, ? examples/s]"
613
- ]
614
- },
615
- "metadata": {},
616
- "output_type": "display_data"
617
- },
618
- {
619
- "data": {
620
- "application/vnd.jupyter.widget-view+json": {
621
- "model_id": "d0cd7340999e45179a7ead59e426b7f7",
622
- "version_major": 2,
623
- "version_minor": 0
624
- },
625
- "text/plain": [
626
- "Map: 0%| | 0/1133 [00:00<?, ? examples/s]"
627
- ]
628
- },
629
- "metadata": {},
630
- "output_type": "display_data"
631
- },
632
- {
633
- "name": "stdout",
634
- "output_type": "stream",
635
- "text": [
636
- "DatasetDict({\n",
637
- " train: Dataset({\n",
638
- " features: ['chinese', 'english', 'text', 'prompt'],\n",
639
- " num_rows: 4528\n",
640
- " })\n",
641
- " test: Dataset({\n",
642
- " features: ['chinese', 'english', 'text', 'prompt'],\n",
643
- " num_rows: 1133\n",
644
- " })\n",
645
- "})\n"
646
- ]
647
- }
648
- ],
649
- "source": [
650
- "dataset = load_translation_dataset(data_path, tokenizer=tokenizer, num_shots=5)"
651
- ]
652
- },
653
- {
654
- "cell_type": "code",
655
- "execution_count": 11,
656
- "metadata": {},
657
- "outputs": [
658
- {
659
- "data": {
660
- "text/plain": [
661
- "('那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。',\n",
662
- " '后来她不挣扎了,对我说,混蛋,你要把我怎么办。')"
663
- ]
664
- },
665
- "execution_count": 11,
666
- "metadata": {},
667
- "output_type": "execute_result"
668
- }
669
- ],
670
- "source": [
671
- "dataset[\"test\"][\"chinese\"][260], dataset[\"test\"][\"chinese\"][908]"
672
- ]
673
- },
674
- {
675
- "cell_type": "code",
676
- "execution_count": 12,
677
- "metadata": {},
678
- "outputs": [],
679
- "source": [
680
- "eval_dataset = dataset[\"test\"].select([260, 908])"
681
- ]
682
- },
683
- {
684
- "cell_type": "code",
685
- "execution_count": 13,
686
- "metadata": {},
687
- "outputs": [
688
- {
689
- "name": "stdout",
690
- "output_type": "stream",
691
- "text": [
692
- "--------------------------------------------------\n",
693
- "chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
694
- "--------------------------------------------------\n",
695
- "english: When Grannie Liu heard Xi-feng talk about 'difficulties' she concluded that there was no hope. Her delight and the way in which her face lit up with pleasure when she heard that she was, after all, to be given twenty taels of silver can be imagined. 'We knew you had your troubles,' she said, 'but as the saying goes, 'A starved camel is bigger than a fat horse.'\n",
696
- "--------------------------------------------------\n",
697
- "text: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
698
- "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
699
- "\n",
700
- "Example Translations:\n",
701
- "Chinese: 全仗着狐仙搭救。\n",
702
- "English: Because I was protected by a fox fairy.\n",
703
- "Chinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\n",
704
- "English: He was the director, the cousin later told them. He had studied abroad and was also a screenwriter; in fact he had written and directed the scene they had earlier seen being filmed.\n",
705
- "Chinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\n",
706
- "English: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\n",
707
- "Chinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\n",
708
- "English: The three old Red Guards stood in front of Ye in a row—just like they had stood against Ye Zhetai—trying to recapture their long-forgotten dignity. But the demonic spiritual energy that had once propelled them was gone.\n",
709
- "Chinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\n",
710
- "English: Mr. Cheng accepted their toast with equanimity and a 'thank you.' Then, turning to Wang Qiyao, he asked if she had anything to say.\n",
711
- "\n",
712
- "Chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
713
- "English:<|im_end|>\n",
714
- "<|im_start|>assistant\n",
715
- "When Grannie Liu heard Xi-feng talk about 'difficulties' she concluded that there was no hope. Her delight and the way in which her face lit up with pleasure when she heard that she was, after all, to be given twenty taels of silver can be imagined. 'We knew you had your troubles,' she said, 'but as the saying goes, 'A starved camel is bigger than a fat horse.'<|im_end|>\n",
716
- "--------------------------------------------------\n",
717
- "prompt: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
718
- "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
719
- "\n",
720
- "Example Translations:\n",
721
- "Chinese: 全仗着狐仙搭救。\n",
722
- "English: Because I was protected by a fox fairy.\n",
723
- "Chinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\n",
724
- "English: He was the director, the cousin later told them. He had studied abroad and was also a screenwriter; in fact he had written and directed the scene they had earlier seen being filmed.\n",
725
- "Chinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\n",
726
- "English: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\n",
727
- "Chinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\n",
728
- "English: The three old Red Guards stood in front of Ye in a row—just like they had stood against Ye Zhetai—trying to recapture their long-forgotten dignity. But the demonic spiritual energy that had once propelled them was gone.\n",
729
- "Chinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\n",
730
- "English: Mr. Cheng accepted their toast with equanimity and a 'thank you.' Then, turning to Wang Qiyao, he asked if she had anything to say.\n",
731
- "\n",
732
- "Chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
733
- "English:<|im_end|>\n",
734
- "<|im_start|>assistant\n",
735
- "\n",
736
- "--------------------------------------------------\n",
737
- "chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
738
- "--------------------------------------------------\n",
739
- "english: After a while, she no longer struggled and said, You bastard! What are you going to do with me?\n",
740
- "--------------------------------------------------\n",
741
- "text: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
742
- "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
743
- "\n",
744
- "Example Translations:\n",
745
- "Chinese: 全仗着狐仙搭救。\n",
746
- "English: Because I was protected by a fox fairy.\n",
747
- "Chinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\n",
748
- "English: He was the director, the cousin later told them. He had studied abroad and was also a screenwriter; in fact he had written and directed the scene they had earlier seen being filmed.\n",
749
- "Chinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\n",
750
- "English: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\n",
751
- "Chinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\n",
752
- "English: The three old Red Guards stood in front of Ye in a row—just like they had stood against Ye Zhetai—trying to recapture their long-forgotten dignity. But the demonic spiritual energy that had once propelled them was gone.\n",
753
- "Chinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\n",
754
- "English: Mr. Cheng accepted their toast with equanimity and a 'thank you.' Then, turning to Wang Qiyao, he asked if she had anything to say.\n",
755
- "\n",
756
- "Chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
757
- "English:<|im_end|>\n",
758
- "<|im_start|>assistant\n",
759
- "After a while, she no longer struggled and said, You bastard! What are you going to do with me?<|im_end|>\n",
760
- "--------------------------------------------------\n",
761
- "prompt: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
762
- "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
763
- "\n",
764
- "Example Translations:\n",
765
- "Chinese: 全仗着狐仙搭救。\n",
766
- "English: Because I was protected by a fox fairy.\n",
767
- "Chinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\n",
768
- "English: He was the director, the cousin later told them. He had studied abroad and was also a screenwriter; in fact he had written and directed the scene they had earlier seen being filmed.\n",
769
- "Chinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\n",
770
- "English: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\n",
771
- "Chinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\n",
772
- "English: The three old Red Guards stood in front of Ye in a row—just like they had stood against Ye Zhetai—trying to recapture their long-forgotten dignity. But the demonic spiritual energy that had once propelled them was gone.\n",
773
- "Chinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\n",
774
- "English: Mr. Cheng accepted their toast with equanimity and a 'thank you.' Then, turning to Wang Qiyao, he asked if she had anything to say.\n",
775
- "\n",
776
- "Chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
777
- "English:<|im_end|>\n",
778
- "<|im_start|>assistant\n",
779
- "\n"
780
- ]
781
- }
782
- ],
783
- "source": [
784
- "print_row_details(eval_dataset.to_pandas(), range(len(eval_dataset)))"
785
- ]
786
- },
787
- {
788
- "cell_type": "code",
789
- "execution_count": 14,
790
- "metadata": {},
791
- "outputs": [
792
- {
793
- "name": "stderr",
794
- "output_type": "stream",
795
- "text": [
796
- " 0%| | 0/2 [00:00<?, ?it/s]c:\\Users\\dongh\\.conda\\envs\\rapget\\Lib\\site-packages\\transformers\\models\\llama\\modeling_llama.py:603: UserWarning: 1Torch was not compiled with flash attention. (Triggered internally at C:\\actions-runner\\_work\\pytorch\\pytorch\\builder\\windows\\pytorch\\aten\\src\\ATen\\native\\transformers\\cuda\\sdp_utils.cpp:555.)\n",
797
- " attn_output = torch.nn.functional.scaled_dot_product_attention(\n",
798
- " 50%|█████ | 1/2 [12:18<12:18, 738.30s/it]"
799
- ]
800
- },
801
- {
802
- "name": "stdout",
803
- "output_type": "stream",
804
- "text": [
805
- "Batch output: ['The task is to translate a given Chinese sentence into English. If the sentence is incomplete or unclear, the translation should be the same as the input text without any additional explanation or reasoning.\\n\\nHere\\'s how to use the guidelines to find the answer:\\n\\nChinese: 那刘姥姥先听见告艰苦, 只当是没想头了, 又听见给他二十两银子, 喜的眉开眼笑道: “我们也知道艰难的, 但只俗语说的: ‘瘦死的骆驼比马还大’呢。\\n\\n1. Read the Chinese sentence carefully.\\n2. Identify any incomplete or unclear parts of the sentence.\\n3. If the sentence is complete and clear, translate it into English following the context and meaning.\\n4. If the sentence is incomplete or unclear, simply copy the input text as your output.\\n\\nIn this case, the sentence is complete and clear, so we will translate it into English:\\n\\nEnglish: The Dao-hsi first heard that they were reporting difficulties, thinking there was no hope, and then heard that they would give her twenty silver dollars. She was overjoyed, smiling broadly and saying, \"We know the difficulties, but as the saying goes, \\'A camel that\\'s lost its fat is still bigger than a horse.\\'\"']\n"
806
- ]
807
- },
808
- {
809
- "name": "stderr",
810
- "output_type": "stream",
811
- "text": [
812
- "100%|██████████| 2/2 [24:19<00:00, 729.62s/it]\n"
813
- ]
814
- }
815
- ],
816
- "source": [
817
- "predictions = eval_model(\n",
818
- " model, tokenizer, eval_dataset, device=device, max_new_tokens=max_new_tokens\n",
819
- ")"
820
- ]
821
- },
822
- {
823
- "cell_type": "code",
824
- "execution_count": 15,
825
- "metadata": {},
826
- "outputs": [
827
- {
828
- "name": "stdout",
829
- "output_type": "stream",
830
- "text": [
831
- "loading d:\\code\\projects\\rapget-translation\\llm_toolkit\\translation_utils.py\n"
832
- ]
833
- },
834
- {
835
- "name": "stderr",
836
- "output_type": "stream",
837
- "text": [
838
- "[nltk_data] Downloading package wordnet to\n",
839
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
840
- "[nltk_data] Package wordnet is already up-to-date!\n",
841
- "[nltk_data] Downloading package punkt to\n",
842
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
843
- "[nltk_data] Package punkt is already up-to-date!\n",
844
- "[nltk_data] Downloading package omw-1.4 to\n",
845
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
846
- "[nltk_data] Package omw-1.4 is already up-to-date!\n"
847
- ]
848
- },
849
- {
850
- "name": "stdout",
851
- "output_type": "stream",
852
- "text": [
853
- "['The task is to translate a given Chinese sentence into English. If the sentence is incomplete or unclear, the translation should be the same as the input text without any additional explanation or reasoning.\\n\\nHere\\'s how to use the guidelines to find the answer:\\n\\nChinese: 那刘姥姥先听见告艰苦, 只当是没想头了, 又听见给他二十两银子, 喜的眉开眼笑道: “我们也知道艰难的, 但只俗语说的: ‘瘦死的骆驼比马还大’呢。\\n\\n1. Read the Chinese sentence carefully.\\n2. Identify any incomplete or unclear parts of the sentence.\\n3. If the sentence is complete and clear, translate it into English following the context and meaning.\\n4. If the sentence is incomplete or unclear, simply copy the input text as your output.\\n\\nIn this case, the sentence is complete and clear, so we will translate it into English:\\n\\nEnglish: The Dao-hsi first heard that they were reporting difficulties, thinking there was no hope, and then heard that they would give her twenty silver dollars. She was overjoyed, smiling broadly and saying, \"We know the difficulties, but as the saying goes, \\'A camel that\\'s lost its fat is still bigger than a horse.\\'\"', 'Later, she stopped struggling and asked me, \"Asshole, what are you going to do with me?\"']\n"
854
- ]
855
- }
856
- ],
857
- "source": [
858
- "print(predictions)"
859
- ]
860
- },
861
- {
862
- "cell_type": "code",
863
- "execution_count": 16,
864
- "metadata": {},
865
- "outputs": [
866
- {
867
- "name": "stdout",
868
- "output_type": "stream",
869
- "text": [
870
- "loading d:\\code\\projects\\rapget-translation\\llm_toolkit\\translation_utils_v1.py\n"
871
- ]
872
- },
873
- {
874
- "name": "stderr",
875
- "output_type": "stream",
876
- "text": [
877
- "[nltk_data] Downloading package wordnet to\n",
878
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
879
- "[nltk_data] Package wordnet is already up-to-date!\n",
880
- "[nltk_data] Downloading package punkt to\n",
881
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
882
- "[nltk_data] Package punkt is already up-to-date!\n",
883
- "[nltk_data] Downloading package omw-1.4 to\n",
884
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
885
- "[nltk_data] Package omw-1.4 is already up-to-date!\n"
886
- ]
887
- },
888
- {
889
- "name": "stdout",
890
- "output_type": "stream",
891
- "text": [
892
- "loading train/test data files\n"
893
- ]
894
- },
895
- {
896
- "data": {
897
- "application/vnd.jupyter.widget-view+json": {
898
- "model_id": "9b93dc2e072345bab26e7dc4b1170e13",
899
- "version_major": 2,
900
- "version_minor": 0
901
- },
902
- "text/plain": [
903
- "Map: 0%| | 0/4528 [00:00<?, ? examples/s]"
904
- ]
905
- },
906
- "metadata": {},
907
- "output_type": "display_data"
908
- },
909
- {
910
- "data": {
911
- "application/vnd.jupyter.widget-view+json": {
912
- "model_id": "a9adb136bd474eba99a718a6bef0b953",
913
- "version_major": 2,
914
- "version_minor": 0
915
- },
916
- "text/plain": [
917
- "Map: 0%| | 0/1133 [00:00<?, ? examples/s]"
918
- ]
919
- },
920
- "metadata": {},
921
- "output_type": "display_data"
922
- },
923
- {
924
- "name": "stdout",
925
- "output_type": "stream",
926
- "text": [
927
- "DatasetDict({\n",
928
- " train: Dataset({\n",
929
- " features: ['chinese', 'english', 'text', 'prompt'],\n",
930
- " num_rows: 4528\n",
931
- " })\n",
932
- " test: Dataset({\n",
933
- " features: ['chinese', 'english', 'text', 'prompt'],\n",
934
- " num_rows: 1133\n",
935
- " })\n",
936
- "})\n"
937
- ]
938
- }
939
- ],
940
- "source": [
941
- "from llm_toolkit.translation_utils_v1 import (\n",
942
- " load_translation_dataset as load_translation_dataset_v1,\n",
943
- ")\n",
944
- "\n",
945
- "dataset_v1 = load_translation_dataset_v1(data_path, tokenizer=tokenizer)"
946
- ]
947
- },
948
- {
949
- "cell_type": "code",
950
- "execution_count": 17,
951
- "metadata": {},
952
- "outputs": [
953
- {
954
- "name": "stdout",
955
- "output_type": "stream",
956
- "text": [
957
- "--------------------------------------------------\n",
958
- "chinese: 老耿端起枪,眯缝起一只三角眼,一搂扳机响了枪,冰雹般的金麻雀劈哩啪啦往下落,铁砂子在柳枝间飞迸着,嚓嚓有声。\n",
959
- "--------------------------------------------------\n",
960
- "english: Old Geng picked up his shotgun, squinted, and pulled the trigger. Two sparrows crashed to the ground like hailstones as shotgun pellets tore noisily through the branches.\n",
961
- "--------------------------------------------------\n",
962
- "text: You are an expert in translating Chinese to English.<|im_start|>user\n",
963
- "Please translate the following Chinese text into English and provide only the translated content, nothing else.\n",
964
- "老耿端起枪,眯缝起一只三角眼,一搂扳机响了枪,冰雹般的金麻雀劈哩啪啦往下落,铁砂子在柳枝间飞迸着,嚓嚓有声。<|im_end|>\n",
965
- "<|im_start|>assistant\n",
966
- "Old Geng picked up his shotgun, squinted, and pulled the trigger. Two sparrows crashed to the ground like hailstones as shotgun pellets tore noisily through the branches.<|im_end|>\n",
967
- "--------------------------------------------------\n",
968
- "prompt: You are an expert in translating Chinese to English.<|im_start|>user\n",
969
- "Please translate the following Chinese text into English and provide only the translated content, nothing else.\n",
970
- "老耿端起枪,眯缝起一只三角眼,一搂扳机响了枪,冰雹般的金麻雀劈哩啪啦往下落,铁砂子在柳枝间飞迸着,嚓嚓有声。<|im_end|>\n",
971
- "<|im_start|>assistant\n",
972
- "\n"
973
- ]
974
- }
975
- ],
976
- "source": [
977
- "print_row_details(dataset_v1[\"test\"].to_pandas())"
978
- ]
979
- },
980
- {
981
- "cell_type": "code",
982
- "execution_count": 25,
983
- "metadata": {},
984
- "outputs": [
985
- {
986
- "data": {
987
- "text/plain": [
988
- "{'meteor': 0.5158944459316517,\n",
989
- " 'bleu_scores': {'bleu': 0.08754836694338668,\n",
990
- " 'precisions': [0.23318385650224216,\n",
991
- " 0.09502262443438914,\n",
992
- " 0.0639269406392694,\n",
993
- " 0.041474654377880185],\n",
994
- " 'brevity_penalty': 1.0,\n",
995
- " 'length_ratio': 2.207920792079208,\n",
996
- " 'translation_length': 223,\n",
997
- " 'reference_length': 101},\n",
998
- " 'rouge_scores': {'rouge1': 0.4382566585956416,\n",
999
- " 'rouge2': 0.2634032634032634,\n",
1000
- " 'rougeL': 0.387409200968523,\n",
1001
- " 'rougeLsum': 0.4170702179176755},\n",
1002
- " 'accuracy': 0.0}"
1003
- ]
1004
- },
1005
- "execution_count": 25,
1006
- "metadata": {},
1007
- "output_type": "execute_result"
1008
- }
1009
- ],
1010
- "source": [
1011
- "calc_metrics(eval_dataset[\"english\"], predictions)"
1012
- ]
1013
- },
1014
- {
1015
- "cell_type": "code",
1016
- "execution_count": 18,
1017
- "metadata": {},
1018
- "outputs": [
1019
- {
1020
- "name": "stderr",
1021
- "output_type": "stream",
1022
- "text": [
1023
- " 50%|█████ | 1/2 [11:04<11:04, 664.47s/it]"
1024
- ]
1025
- },
1026
- {
1027
- "name": "stdout",
1028
- "output_type": "stream",
1029
- "text": [
1030
- "Batch output: ['First, I\\'ll identify the key phrases and words in the Chinese text:\\n\\n1. 那刘姥姥 (that Diao Huarou) - a character\\'s name in a classic Chinese novel, \"Dream of the Red Chamber\"\\n2. 先听见告艰苦 (first heard of the hardship)\\n3. 只当是没想头了 (just thought it was nonsense)\\n4. 又听见给他二十两银子 (then heard that he received twenty silver pieces)\\n5. 喜的眉开眼笑 (very happy, smiling broadly)\\n6. “我们也知道艰难的 (we also know the difficulties)\\n7. 但只俗语说的 (but as the saying goes)\\n8. ‘瘦死的骆驼比马还大’呢 (a camel that has lost weight is still larger than a horse)\\n\\nNow, I\\'ll translate the text into English, maintaining the original meaning and tone:\\n\\nFirst, Diao Huarou heard that there was hardship mentioned, and she thought it was nonsense. Then, she heard that he received twenty silver pieces, and she was very happy, smiling broadly, saying, \"We also know the difficulties. But as the saying goes, \\'A camel that has lost weight is still larger than a horse.\\'\"']\n"
1031
- ]
1032
- },
1033
- {
1034
- "name": "stderr",
1035
- "output_type": "stream",
1036
- "text": [
1037
- "100%|██████████| 2/2 [22:04<00:00, 662.38s/it]\n"
1038
- ]
1039
- },
1040
- {
1041
- "data": {
1042
- "text/plain": [
1043
- "['First, I\\'ll identify the key phrases and words in the Chinese text:\\n\\n1. 那刘姥姥 (that Diao Huarou) - a character\\'s name in a classic Chinese novel, \"Dream of the Red Chamber\"\\n2. 先听见告艰苦 (first heard of the hardship)\\n3. 只当是没想头了 (just thought it was nonsense)\\n4. 又听见给他二十两银子 (then heard that he received twenty silver pieces)\\n5. 喜的眉开眼笑 (very happy, smiling broadly)\\n6. “我们也知道艰难的 (we also know the difficulties)\\n7. 但只俗语说的 (but as the saying goes)\\n8. ‘瘦死的骆驼比马还大’呢 (a camel that has lost weight is still larger than a horse)\\n\\nNow, I\\'ll translate the text into English, maintaining the original meaning and tone:\\n\\nFirst, Diao Huarou heard that there was hardship mentioned, and she thought it was nonsense. Then, she heard that he received twenty silver pieces, and she was very happy, smiling broadly, saying, \"We also know the difficulties. But as the saying goes, \\'A camel that has lost weight is still larger than a horse.\\'\"',\n",
1044
- " 'Later, she stopped struggling and said to me, \"Son of a bitch, what are you going to do with me?\"']"
1045
- ]
1046
- },
1047
- "execution_count": 18,
1048
- "metadata": {},
1049
- "output_type": "execute_result"
1050
- }
1051
- ],
1052
- "source": [
1053
- "eval_dataset_v1 = dataset_v1[\"test\"].select([260, 908])\n",
1054
- "predictions_v1 = eval_model(\n",
1055
- " model, tokenizer, eval_dataset_v1, device=device, max_new_tokens=max_new_tokens\n",
1056
- ")\n",
1057
- "predictions_v1"
1058
- ]
1059
- },
1060
- {
1061
- "cell_type": "code",
1062
- "execution_count": 19,
1063
- "metadata": {},
1064
- "outputs": [
1065
- {
1066
- "name": "stdout",
1067
- "output_type": "stream",
1068
- "text": [
1069
- "['First, I\\'ll identify the key phrases and words in the Chinese text:\\n\\n1. 那刘姥姥 (that Diao Huarou) - a character\\'s name in a classic Chinese novel, \"Dream of the Red Chamber\"\\n2. 先听见告艰苦 (first heard of the hardship)\\n3. 只当是没想头了 (just thought it was nonsense)\\n4. 又听见给他二十两银子 (then heard that he received twenty silver pieces)\\n5. 喜的眉开眼笑 (very happy, smiling broadly)\\n6. “我们也知道艰难的 (we also know the difficulties)\\n7. 但只俗语说的 (but as the saying goes)\\n8. ‘瘦死的骆驼比马还大’呢 (a camel that has lost weight is still larger than a horse)\\n\\nNow, I\\'ll translate the text into English, maintaining the original meaning and tone:\\n\\nFirst, Diao Huarou heard that there was hardship mentioned, and she thought it was nonsense. Then, she heard that he received twenty silver pieces, and she was very happy, smiling broadly, saying, \"We also know the difficulties. But as the saying goes, \\'A camel that has lost weight is still larger than a horse.\\'\"', 'Later, she stopped struggling and said to me, \"Son of a bitch, what are you going to do with me?\"']\n"
1070
- ]
1071
- }
1072
- ],
1073
- "source": [
1074
- "print(predictions_v1)"
1075
- ]
1076
- },
1077
- {
1078
- "cell_type": "code",
1079
- "execution_count": 20,
1080
- "metadata": {},
1081
- "outputs": [
1082
- {
1083
- "name": "stdout",
1084
- "output_type": "stream",
1085
- "text": [
1086
- "--------------------------------------------------\n",
1087
- "chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
1088
- "--------------------------------------------------\n",
1089
- "english: When Grannie Liu heard Xi-feng talk about 'difficulties' she concluded that there was no hope. Her delight and the way in which her face lit up with pleasure when she heard that she was, after all, to be given twenty taels of silver can be imagined. 'We knew you had your troubles,' she said, 'but as the saying goes, 'A starved camel is bigger than a fat horse.'\n",
1090
- "--------------------------------------------------\n",
1091
- "text: You are an expert in translating Chinese to English.<|im_start|>user\n",
1092
- "Please translate the following Chinese text into English and provide only the translated content, nothing else.\n",
1093
- "那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。<|im_end|>\n",
1094
- "<|im_start|>assistant\n",
1095
- "When Grannie Liu heard Xi-feng talk about 'difficulties' she concluded that there was no hope. Her delight and the way in which her face lit up with pleasure when she heard that she was, after all, to be given twenty taels of silver can be imagined. 'We knew you had your troubles,' she said, 'but as the saying goes, 'A starved camel is bigger than a fat horse.'<|im_end|>\n",
1096
- "--------------------------------------------------\n",
1097
- "prompt: You are an expert in translating Chinese to English.<|im_start|>user\n",
1098
- "Please translate the following Chinese text into English and provide only the translated content, nothing else.\n",
1099
- "那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。<|im_end|>\n",
1100
- "<|im_start|>assistant\n",
1101
- "\n",
1102
- "--------------------------------------------------\n",
1103
- "chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
1104
- "--------------------------------------------------\n",
1105
- "english: After a while, she no longer struggled and said, You bastard! What are you going to do with me?\n",
1106
- "--------------------------------------------------\n",
1107
- "text: You are an expert in translating Chinese to English.<|im_start|>user\n",
1108
- "Please translate the following Chinese text into English and provide only the translated content, nothing else.\n",
1109
- "后来她不挣扎了,对我说,混蛋,你要把我怎么办。<|im_end|>\n",
1110
- "<|im_start|>assistant\n",
1111
- "After a while, she no longer struggled and said, You bastard! What are you going to do with me?<|im_end|>\n",
1112
- "--------------------------------------------------\n",
1113
- "prompt: You are an expert in translating Chinese to English.<|im_start|>user\n",
1114
- "Please translate the following Chinese text into English and provide only the translated content, nothing else.\n",
1115
- "后来她不挣扎了,对我说,混蛋,你要把我怎么办。<|im_end|>\n",
1116
- "<|im_start|>assistant\n",
1117
- "\n"
1118
- ]
1119
- }
1120
- ],
1121
- "source": [
1122
- "print_row_details(eval_dataset_v1.to_pandas(), range(len(eval_dataset_v1)))"
1123
- ]
1124
- },
1125
- {
1126
- "cell_type": "code",
1127
- "execution_count": 26,
1128
- "metadata": {},
1129
- "outputs": [
1130
- {
1131
- "data": {
1132
- "text/plain": [
1133
- "{'meteor': 0.5153317672515252,\n",
1134
- " 'bleu_scores': {'bleu': 0.08097031799100003,\n",
1135
- " 'precisions': [0.21397379912663755,\n",
1136
- " 0.09691629955947137,\n",
1137
- " 0.057777777777777775,\n",
1138
- " 0.03587443946188341],\n",
1139
- " 'brevity_penalty': 1.0,\n",
1140
- " 'length_ratio': 2.267326732673267,\n",
1141
- " 'translation_length': 229,\n",
1142
- " 'reference_length': 101},\n",
1143
- " 'rouge_scores': {'rouge1': 0.4401123990165086,\n",
1144
- " 'rouge2': 0.26690746045584757,\n",
1145
- " 'rougeL': 0.38707411310151035,\n",
1146
- " 'rougeLsum': 0.40533895328415875},\n",
1147
- " 'accuracy': 0.0}"
1148
- ]
1149
- },
1150
- "execution_count": 26,
1151
- "metadata": {},
1152
- "output_type": "execute_result"
1153
- }
1154
- ],
1155
- "source": [
1156
- "calc_metrics(eval_dataset_v1[\"english\"], predictions_v1)"
1157
- ]
1158
- },
1159
- {
1160
- "cell_type": "code",
1161
- "execution_count": 21,
1162
- "metadata": {},
1163
- "outputs": [
1164
- {
1165
- "name": "stdout",
1166
- "output_type": "stream",
1167
- "text": [
1168
- "loading train/test data files\n"
1169
- ]
1170
- },
1171
- {
1172
- "data": {
1173
- "application/vnd.jupyter.widget-view+json": {
1174
- "model_id": "22e0eed1c971459497f30cf1141317f2",
1175
- "version_major": 2,
1176
- "version_minor": 0
1177
- },
1178
- "text/plain": [
1179
- "Map: 0%| | 0/4528 [00:00<?, ? examples/s]"
1180
- ]
1181
- },
1182
- "metadata": {},
1183
- "output_type": "display_data"
1184
- },
1185
- {
1186
- "data": {
1187
- "application/vnd.jupyter.widget-view+json": {
1188
- "model_id": "3925ff53b4c34183a8427d900f2f51f3",
1189
- "version_major": 2,
1190
- "version_minor": 0
1191
- },
1192
- "text/plain": [
1193
- "Map: 0%| | 0/1133 [00:00<?, ? examples/s]"
1194
- ]
1195
- },
1196
- "metadata": {},
1197
- "output_type": "display_data"
1198
- },
1199
- {
1200
- "name": "stdout",
1201
- "output_type": "stream",
1202
- "text": [
1203
- "DatasetDict({\n",
1204
- " train: Dataset({\n",
1205
- " features: ['chinese', 'english', 'text', 'prompt'],\n",
1206
- " num_rows: 4528\n",
1207
- " })\n",
1208
- " test: Dataset({\n",
1209
- " features: ['chinese', 'english', 'text', 'prompt'],\n",
1210
- " num_rows: 1133\n",
1211
- " })\n",
1212
- "})\n"
1213
- ]
1214
- }
1215
- ],
1216
- "source": [
1217
- "dataset_v2 = load_translation_dataset(data_path, tokenizer=tokenizer, num_shots=0)"
1218
- ]
1219
- },
1220
- {
1221
- "cell_type": "code",
1222
- "execution_count": 22,
1223
- "metadata": {},
1224
- "outputs": [
1225
- {
1226
- "name": "stderr",
1227
- "output_type": "stream",
1228
- "text": [
1229
- " 50%|█████ | 1/2 [11:33<11:33, 693.07s/it]"
1230
- ]
1231
- },
1232
- {
1233
- "name": "stdout",
1234
- "output_type": "stream",
1235
- "text": [
1236
- "Batch output: ['That Dukai first heard about the hardship, thinking it was pointless, but then heard that he received twenty silver pieces, and was so happy that his eyebrows and eyes opened wide as he said, \"We know the difficulties, but as the saying goes, \\'Even a lean camel is bigger than a horse.\\'\"']\n"
1237
- ]
1238
- },
1239
- {
1240
- "name": "stderr",
1241
- "output_type": "stream",
1242
- "text": [
1243
- "100%|██████████| 2/2 [22:34<00:00, 677.33s/it]\n"
1244
- ]
1245
- },
1246
- {
1247
- "data": {
1248
- "text/plain": [
1249
- "['That Dukai first heard about the hardship, thinking it was pointless, but then heard that he received twenty silver pieces, and was so happy that his eyebrows and eyes opened wide as he said, \"We know the difficulties, but as the saying goes, \\'Even a lean camel is bigger than a horse.\\'\"',\n",
1250
- " '后来她不挣扎了, 对我说, 混蛋, 你要把我怎么办。\\nBased on the given instructions, since the input is a complete Chinese sentence and there is no need for additional explanation or reasoning, the output is the same as the input:\\n\\nEnglish: 后来她不挣扎了, 对我说, 混蛋, 你要把我怎么办。']"
1251
- ]
1252
- },
1253
- "execution_count": 22,
1254
- "metadata": {},
1255
- "output_type": "execute_result"
1256
- }
1257
- ],
1258
- "source": [
1259
- "eval_dataset_v2 = dataset_v2[\"test\"].select([260, 908])\n",
1260
- "predictions_v2 = eval_model(\n",
1261
- " model, tokenizer, eval_dataset_v2, device=device, max_new_tokens=max_new_tokens\n",
1262
- ")\n",
1263
- "predictions_v2"
1264
- ]
1265
- },
1266
- {
1267
- "cell_type": "code",
1268
- "execution_count": 23,
1269
- "metadata": {},
1270
- "outputs": [
1271
- {
1272
- "name": "stdout",
1273
- "output_type": "stream",
1274
- "text": [
1275
- "['That Dukai first heard about the hardship, thinking it was pointless, but then heard that he received twenty silver pieces, and was so happy that his eyebrows and eyes opened wide as he said, \"We know the difficulties, but as the saying goes, \\'Even a lean camel is bigger than a horse.\\'\"', '后来她不挣扎了, 对我说, 混蛋, 你要把我怎么办。\\nBased on the given instructions, since the input is a complete Chinese sentence and there is no need for additional explanation or reasoning, the output is the same as the input:\\n\\nEnglish: 后来她不挣扎了, 对我说, 混蛋, 你要把我怎么办。']\n"
1276
- ]
1277
- }
1278
- ],
1279
- "source": [
1280
- "print(predictions_v2)"
1281
- ]
1282
- },
1283
- {
1284
- "cell_type": "code",
1285
- "execution_count": 24,
1286
- "metadata": {},
1287
- "outputs": [
1288
- {
1289
- "name": "stdout",
1290
- "output_type": "stream",
1291
- "text": [
1292
- "--------------------------------------------------\n",
1293
- "chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
1294
- "--------------------------------------------------\n",
1295
- "english: When Grannie Liu heard Xi-feng talk about 'difficulties' she concluded that there was no hope. Her delight and the way in which her face lit up with pleasure when she heard that she was, after all, to be given twenty taels of silver can be imagined. 'We knew you had your troubles,' she said, 'but as the saying goes, 'A starved camel is bigger than a fat horse.'\n",
1296
- "--------------------------------------------------\n",
1297
- "text: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
1298
- "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
1299
- "\n",
1300
- "Chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
1301
- "English:<|im_end|>\n",
1302
- "<|im_start|>assistant\n",
1303
- "When Grannie Liu heard Xi-feng talk about 'difficulties' she concluded that there was no hope. Her delight and the way in which her face lit up with pleasure when she heard that she was, after all, to be given twenty taels of silver can be imagined. 'We knew you had your troubles,' she said, 'but as the saying goes, 'A starved camel is bigger than a fat horse.'<|im_end|>\n",
1304
- "--------------------------------------------------\n",
1305
- "prompt: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
1306
- "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
1307
- "\n",
1308
- "Chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
1309
- "English:<|im_end|>\n",
1310
- "<|im_start|>assistant\n",
1311
- "\n",
1312
- "--------------------------------------------------\n",
1313
- "chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
1314
- "--------------------------------------------------\n",
1315
- "english: After a while, she no longer struggled and said, You bastard! What are you going to do with me?\n",
1316
- "--------------------------------------------------\n",
1317
- "text: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
1318
- "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
1319
- "\n",
1320
- "Chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
1321
- "English:<|im_end|>\n",
1322
- "<|im_start|>assistant\n",
1323
- "After a while, she no longer struggled and said, You bastard! What are you going to do with me?<|im_end|>\n",
1324
- "--------------------------------------------------\n",
1325
- "prompt: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n",
1326
- "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
1327
- "\n",
1328
- "Chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
1329
- "English:<|im_end|>\n",
1330
- "<|im_start|>assistant\n",
1331
- "\n"
1332
- ]
1333
- }
1334
- ],
1335
- "source": [
1336
- "print_row_details(eval_dataset_v2.to_pandas(), range(len(eval_dataset_v2)))"
1337
- ]
1338
- },
1339
- {
1340
- "cell_type": "code",
1341
- "execution_count": 27,
1342
- "metadata": {},
1343
- "outputs": [
1344
- {
1345
- "data": {
1346
- "text/plain": [
1347
- "{'meteor': 0.21319948962320656,\n",
1348
- " 'bleu_scores': {'bleu': 0.10039676162391267,\n",
1349
- " 'precisions': [0.32075471698113206,\n",
1350
- " 0.11538461538461539,\n",
1351
- " 0.06862745098039216,\n",
1352
- " 0.04],\n",
1353
- " 'brevity_penalty': 1.0,\n",
1354
- " 'length_ratio': 1.0495049504950495,\n",
1355
- " 'translation_length': 106,\n",
1356
- " 'reference_length': 101},\n",
1357
- " 'rouge_scores': {'rouge1': 0.27369956246961596,\n",
1358
- " 'rouge2': 0.07563025210084033,\n",
1359
- " 'rougeL': 0.20450494247285692,\n",
1360
- " 'rougeLsum': 0.20450494247285692},\n",
1361
- " 'accuracy': 0.0}"
1362
- ]
1363
- },
1364
- "execution_count": 27,
1365
- "metadata": {},
1366
- "output_type": "execute_result"
1367
- }
1368
- ],
1369
- "source": [
1370
- "calc_metrics(eval_dataset_v2[\"english\"], predictions_v2)"
1371
- ]
1372
- }
1373
- ],
1374
- "metadata": {
1375
- "accelerator": "GPU",
1376
- "application/vnd.databricks.v1+notebook": {
1377
- "dashboards": [],
1378
- "environmentMetadata": null,
1379
- "language": "python",
1380
- "notebookMetadata": {
1381
- "mostRecentlyExecutedCommandWithImplicitDF": {
1382
- "commandId": -1,
1383
- "dataframes": [
1384
- "_sqldf"
1385
- ]
1386
- },
1387
- "pythonIndentUnit": 4
1388
- },
1389
- "notebookName": "10_eval-lf-medium-py3.11",
1390
- "widgets": {}
1391
- },
1392
- "colab": {
1393
- "gpuType": "L4",
1394
- "provenance": []
1395
- },
1396
- "kernelspec": {
1397
- "display_name": "Python 3",
1398
- "name": "python3"
1399
- },
1400
- "language_info": {
1401
- "codemirror_mode": {
1402
- "name": "ipython",
1403
- "version": 3
1404
- },
1405
- "file_extension": ".py",
1406
- "mimetype": "text/x-python",
1407
- "name": "python",
1408
- "nbconvert_exporter": "python",
1409
- "pygments_lexer": "ipython3",
1410
- "version": "3.11.9"
1411
- }
1412
- },
1413
- "nbformat": 4,
1414
- "nbformat_minor": 0
1415
- }
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fc857b7328476599cad79661f3dc177be0f090cf8ae0163534a130c84588e2b5
3
+ size 60083
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
notebooks/01c_Few-shot_Prompting_OpenAI.ipynb CHANGED
@@ -1,868 +1,3 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": 1,
6
- "metadata": {
7
- "executionInfo": {
8
- "elapsed": 476,
9
- "status": "ok",
10
- "timestamp": 1720679526275,
11
- "user": {
12
- "displayName": "HUANG DONGHAO _",
13
- "userId": "00977795705617022768"
14
- },
15
- "user_tz": -480
16
- },
17
- "id": "uWKRSV6eZsCn"
18
- },
19
- "outputs": [],
20
- "source": [
21
- "%load_ext autoreload\n",
22
- "%autoreload 2"
23
- ]
24
- },
25
- {
26
- "cell_type": "code",
27
- "execution_count": 2,
28
- "metadata": {
29
- "application/vnd.databricks.v1+cell": {
30
- "cellMetadata": {
31
- "byteLimit": 2048000,
32
- "rowLimit": 10000
33
- },
34
- "inputWidgets": {},
35
- "nuid": "6d394937-6c99-4a7c-9d32-7600a280032f",
36
- "showTitle": false,
37
- "title": ""
38
- },
39
- "colab": {
40
- "base_uri": "https://localhost:8080/"
41
- },
42
- "executionInfo": {
43
- "elapsed": 5,
44
- "status": "ok",
45
- "timestamp": 1720679529345,
46
- "user": {
47
- "displayName": "HUANG DONGHAO _",
48
- "userId": "00977795705617022768"
49
- },
50
- "user_tz": -480
51
- },
52
- "id": "G5pNu3zgZBrL",
53
- "outputId": "160a554f-fb08-4aa0-bc00-0422fb7c1fac"
54
- },
55
- "outputs": [
56
- {
57
- "name": "stdout",
58
- "output_type": "stream",
59
- "text": [
60
- "workding dir: d:\\code\\projects\\rapget-translation\n"
61
- ]
62
- }
63
- ],
64
- "source": [
65
- "import os\n",
66
- "import sys\n",
67
- "from pathlib import Path\n",
68
- "\n",
69
- "# check if workding_dir is in local variables\n",
70
- "if \"workding_dir\" not in locals():\n",
71
- " workding_dir = str(Path.cwd().parent)\n",
72
- "\n",
73
- "os.chdir(workding_dir)\n",
74
- "sys.path.append(workding_dir)\n",
75
- "print(\"workding dir:\", workding_dir)"
76
- ]
77
- },
78
- {
79
- "cell_type": "code",
80
- "execution_count": 3,
81
- "metadata": {
82
- "application/vnd.databricks.v1+cell": {
83
- "cellMetadata": {
84
- "byteLimit": 2048000,
85
- "rowLimit": 10000
86
- },
87
- "inputWidgets": {},
88
- "nuid": "9f67ec60-2f24-411c-84eb-0dd664b44775",
89
- "showTitle": false,
90
- "title": ""
91
- },
92
- "colab": {
93
- "base_uri": "https://localhost:8080/"
94
- },
95
- "executionInfo": {
96
- "elapsed": 3,
97
- "status": "ok",
98
- "timestamp": 1720679529345,
99
- "user": {
100
- "displayName": "HUANG DONGHAO _",
101
- "userId": "00977795705617022768"
102
- },
103
- "user_tz": -480
104
- },
105
- "id": "hPCC-6m7ZBrM",
106
- "outputId": "c7aa2c96-5e99-440a-c148-201d79465ff9"
107
- },
108
- "outputs": [
109
- {
110
- "name": "stdout",
111
- "output_type": "stream",
112
- "text": [
113
- "loading env vars from: d:\\code\\projects\\rapget-translation\\.env\n"
114
- ]
115
- },
116
- {
117
- "data": {
118
- "text/plain": [
119
- "True"
120
- ]
121
- },
122
- "execution_count": 3,
123
- "metadata": {},
124
- "output_type": "execute_result"
125
- }
126
- ],
127
- "source": [
128
- "from dotenv import find_dotenv, load_dotenv\n",
129
- "\n",
130
- "found_dotenv = find_dotenv(\".env\")\n",
131
- "\n",
132
- "if len(found_dotenv) == 0:\n",
133
- " found_dotenv = find_dotenv(\".env.example\")\n",
134
- "print(f\"loading env vars from: {found_dotenv}\")\n",
135
- "load_dotenv(found_dotenv, override=True)"
136
- ]
137
- },
138
- {
139
- "cell_type": "code",
140
- "execution_count": 4,
141
- "metadata": {
142
- "application/vnd.databricks.v1+cell": {
143
- "cellMetadata": {
144
- "byteLimit": 2048000,
145
- "rowLimit": 10000
146
- },
147
- "inputWidgets": {},
148
- "nuid": "f1597656-8042-4878-9d3b-9ebfb8dd86dc",
149
- "showTitle": false,
150
- "title": ""
151
- },
152
- "colab": {
153
- "base_uri": "https://localhost:8080/"
154
- },
155
- "executionInfo": {
156
- "elapsed": 3,
157
- "status": "ok",
158
- "timestamp": 1720679529345,
159
- "user": {
160
- "displayName": "HUANG DONGHAO _",
161
- "userId": "00977795705617022768"
162
- },
163
- "user_tz": -480
164
- },
165
- "id": "1M3IraVtZBrM",
166
- "outputId": "29ab35f6-2970-4ade-d85d-3174acf8cda0"
167
- },
168
- "outputs": [
169
- {
170
- "name": "stdout",
171
- "output_type": "stream",
172
- "text": [
173
- "01-ai/Yi-1.5-9B-Chat None True datasets/mac/mac.tsv results/mac-results_few_shots_4bit.csv False 300\n"
174
- ]
175
- }
176
- ],
177
- "source": [
178
- "import os\n",
179
- "\n",
180
- "model_name = os.getenv(\"MODEL_NAME\")\n",
181
- "adapter_name_or_path = os.getenv(\"ADAPTER_NAME_OR_PATH\")\n",
182
- "load_in_4bit = os.getenv(\"LOAD_IN_4BIT\") == \"true\"\n",
183
- "data_path = os.getenv(\"DATA_PATH\")\n",
184
- "results_path = os.getenv(\"RESULTS_PATH\")\n",
185
- "use_english_datasets = os.getenv(\"USE_ENGLISH_DATASETS\") == \"true\"\n",
186
- "max_new_tokens = int(os.getenv(\"MAX_NEW_TOKENS\", 2048))\n",
187
- "\n",
188
- "print(\n",
189
- " model_name,\n",
190
- " adapter_name_or_path,\n",
191
- " load_in_4bit,\n",
192
- " data_path,\n",
193
- " results_path,\n",
194
- " use_english_datasets,\n",
195
- " max_new_tokens,\n",
196
- ")"
197
- ]
198
- },
199
- {
200
- "cell_type": "code",
201
- "execution_count": 5,
202
- "metadata": {
203
- "application/vnd.databricks.v1+cell": {
204
- "cellMetadata": {
205
- "byteLimit": 2048000,
206
- "rowLimit": 10000
207
- },
208
- "inputWidgets": {},
209
- "nuid": "b2a43943-9324-4839-9a47-cfa72de2244b",
210
- "showTitle": false,
211
- "title": ""
212
- },
213
- "colab": {
214
- "base_uri": "https://localhost:8080/"
215
- },
216
- "executionInfo": {
217
- "elapsed": 564,
218
- "status": "ok",
219
- "timestamp": 1720679529907,
220
- "user": {
221
- "displayName": "HUANG DONGHAO _",
222
- "userId": "00977795705617022768"
223
- },
224
- "user_tz": -480
225
- },
226
- "id": "UgMvt6dIZBrM",
227
- "outputId": "ce37581c-fd26-46c2-ad87-d933d99f68f7"
228
- },
229
- "outputs": [
230
- {
231
- "name": "stdout",
232
- "output_type": "stream",
233
- "text": [
234
- "Python 3.11.9\n",
235
- "Name: torch\n",
236
- "Version: 2.4.0+cu124\n",
237
- "Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration\n",
238
- "Home-page: https://pytorch.org/\n",
239
- "Author: PyTorch Team\n",
240
- "Author-email: packages@pytorch.org\n",
241
- "License: BSD-3\n",
242
- "Location: C:\\Users\\dongh\\.conda\\envs\\rapget\\Lib\\site-packages\n",
243
- "Requires: filelock, fsspec, jinja2, networkx, sympy, typing-extensions\n",
244
- "Required-by: accelerate, bitsandbytes, peft, torchaudio, torchvision\n",
245
- "---\n",
246
- "Name: transformers\n",
247
- "Version: 4.43.3\n",
248
- "Summary: State-of-the-art Machine Learning for JAX, PyTorch and TensorFlow\n",
249
- "Home-page: https://github.com/huggingface/transformers\n",
250
- "Author: The Hugging Face team (past and future) with the help of all our contributors (https://github.com/huggingface/transformers/graphs/contributors)\n",
251
- "Author-email: transformers@huggingface.co\n",
252
- "License: Apache 2.0 License\n",
253
- "Location: C:\\Users\\dongh\\.conda\\envs\\rapget\\Lib\\site-packages\n",
254
- "Requires: filelock, huggingface-hub, numpy, packaging, pyyaml, regex, requests, safetensors, tokenizers, tqdm\n",
255
- "Required-by: peft\n",
256
- "CPU times: total: 0 ns\n",
257
- "Wall time: 8.35 s\n"
258
- ]
259
- }
260
- ],
261
- "source": [
262
- "%%time\n",
263
- "os.environ[\"TOKENIZERS_PARALLELISM\"] = \"true\"\n",
264
- "\n",
265
- "!python --version\n",
266
- "!pip show torch transformers"
267
- ]
268
- },
269
- {
270
- "cell_type": "code",
271
- "execution_count": 6,
272
- "metadata": {
273
- "colab": {
274
- "base_uri": "https://localhost:8080/"
275
- },
276
- "executionInfo": {
277
- "elapsed": 1685,
278
- "status": "ok",
279
- "timestamp": 1720679531591,
280
- "user": {
281
- "displayName": "HUANG DONGHAO _",
282
- "userId": "00977795705617022768"
283
- },
284
- "user_tz": -480
285
- },
286
- "id": "ZuS_FsLyZBrN",
287
- "outputId": "2cba0105-c505-4395-afbd-2f2fee6581d0"
288
- },
289
- "outputs": [
290
- {
291
- "name": "stderr",
292
- "output_type": "stream",
293
- "text": [
294
- "c:\\Users\\dongh\\.conda\\envs\\rapget\\Lib\\site-packages\\threadpoolctl.py:1214: RuntimeWarning: \n",
295
- "Found Intel OpenMP ('libiomp') and LLVM OpenMP ('libomp') loaded at\n",
296
- "the same time. Both libraries are known to be incompatible and this\n",
297
- "can cause random crashes or deadlocks on Linux when loaded in the\n",
298
- "same Python program.\n",
299
- "Using threadpoolctl may cause crashes or deadlocks. For more\n",
300
- "information and possible workarounds, please see\n",
301
- " https://github.com/joblib/threadpoolctl/blob/master/multiple_openmp.md\n",
302
- "\n",
303
- " warnings.warn(msg, RuntimeWarning)\n",
304
- "[nltk_data] Downloading package wordnet to\n",
305
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
306
- "[nltk_data] Package wordnet is already up-to-date!\n",
307
- "[nltk_data] Downloading package punkt to\n",
308
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
309
- "[nltk_data] Package punkt is already up-to-date!\n",
310
- "[nltk_data] Downloading package omw-1.4 to\n",
311
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
312
- "[nltk_data] Package omw-1.4 is already up-to-date!\n"
313
- ]
314
- },
315
- {
316
- "name": "stdout",
317
- "output_type": "stream",
318
- "text": [
319
- "loading: d:\\code\\projects\\rapget-translation\\eval_modules\\calc_repetitions.py\n",
320
- "loading d:\\code\\projects\\rapget-translation\\llm_toolkit\\translation_utils.py\n"
321
- ]
322
- },
323
- {
324
- "name": "stderr",
325
- "output_type": "stream",
326
- "text": [
327
- "[nltk_data] Downloading package wordnet to\n",
328
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
329
- "[nltk_data] Package wordnet is already up-to-date!\n",
330
- "[nltk_data] Downloading package punkt to\n",
331
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
332
- "[nltk_data] Package punkt is already up-to-date!\n",
333
- "[nltk_data] Downloading package omw-1.4 to\n",
334
- "[nltk_data] C:\\Users\\dongh\\AppData\\Roaming\\nltk_data...\n",
335
- "[nltk_data] Package omw-1.4 is already up-to-date!\n"
336
- ]
337
- },
338
- {
339
- "name": "stdout",
340
- "output_type": "stream",
341
- "text": [
342
- "CUDA is available, we have found 1 GPU(s)\n",
343
- "NVIDIA GeForce RTX 4080 Laptop GPU\n",
344
- "CUDA version: 12.4\n"
345
- ]
346
- }
347
- ],
348
- "source": [
349
- "from llm_toolkit.llm_utils import *\n",
350
- "from llm_toolkit.translation_utils import *\n",
351
- "\n",
352
- "device = check_gpu()"
353
- ]
354
- },
355
- {
356
- "cell_type": "code",
357
- "execution_count": 7,
358
- "metadata": {},
359
- "outputs": [
360
- {
361
- "name": "stdout",
362
- "output_type": "stream",
363
- "text": [
364
- "loading train/test data files\n",
365
- "DatasetDict({\n",
366
- " train: Dataset({\n",
367
- " features: ['chinese', 'english'],\n",
368
- " num_rows: 4528\n",
369
- " })\n",
370
- " test: Dataset({\n",
371
- " features: ['chinese', 'english'],\n",
372
- " num_rows: 1133\n",
373
- " })\n",
374
- "})\n"
375
- ]
376
- }
377
- ],
378
- "source": [
379
- "datasets = load_translation_dataset(data_path)"
380
- ]
381
- },
382
- {
383
- "cell_type": "code",
384
- "execution_count": 8,
385
- "metadata": {},
386
- "outputs": [],
387
- "source": [
388
- "os.getenv(\"OPENAI_MODEL\")\n",
389
- "base_url = os.getenv(\"OPENAI_BASE_URL\") or None"
390
- ]
391
- },
392
- {
393
- "cell_type": "code",
394
- "execution_count": 9,
395
- "metadata": {},
396
- "outputs": [
397
- {
398
- "name": "stdout",
399
- "output_type": "stream",
400
- "text": [
401
- "--------------------------------------------------\n",
402
- "chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n",
403
- "--------------------------------------------------\n",
404
- "english: When Grannie Liu heard Xi-feng talk about 'difficulties' she concluded that there was no hope. Her delight and the way in which her face lit up with pleasure when she heard that she was, after all, to be given twenty taels of silver can be imagined. 'We knew you had your troubles,' she said, 'but as the saying goes, 'A starved camel is bigger than a fat horse.'\n",
405
- "--------------------------------------------------\n",
406
- "chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n",
407
- "--------------------------------------------------\n",
408
- "english: After a while, she no longer struggled and said, You bastard! What are you going to do with me?\n"
409
- ]
410
- }
411
- ],
412
- "source": [
413
- "eval_dataset = datasets[\"test\"].select([260, 908])\n",
414
- "print_row_details(eval_dataset.to_pandas(), range(len(eval_dataset)))"
415
- ]
416
- },
417
- {
418
- "cell_type": "code",
419
- "execution_count": 10,
420
- "metadata": {},
421
- "outputs": [
422
- {
423
- "name": "stdout",
424
- "output_type": "stream",
425
- "text": [
426
- "You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\n",
427
- "\n",
428
- "Example Translations:\n",
429
- "Chinese: 全仗着狐仙搭救。\n",
430
- "English: Because I was protected by a fox fairy.\n",
431
- "Chinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\n",
432
- "English: He was the director, the cousin later told them. He had studied abroad and was also a screenwriter; in fact he had written and directed the scene they had earlier seen being filmed.\n",
433
- "Chinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\n",
434
- "English: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\n",
435
- "Chinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\n",
436
- "English: The three old Red Guards stood in front of Ye in a row—just like they had stood against Ye Zhetai—trying to recapture their long-forgotten dignity. But the demonic spiritual energy that had once propelled them was gone.\n",
437
- "Chinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\n",
438
- "English: Mr. Cheng accepted their toast with equanimity and a 'thank you.' Then, turning to Wang Qiyao, he asked if she had anything to say.\n",
439
- "\n",
440
- "Chinese: {input}\n",
441
- "English:\n"
442
- ]
443
- }
444
- ],
445
- "source": [
446
- "translation_prompt = get_few_shot_prompt(datasets[\"train\"], num_shots=5)\n",
447
- "print(translation_prompt)"
448
- ]
449
- },
450
- {
451
- "cell_type": "code",
452
- "execution_count": 11,
453
- "metadata": {},
454
- "outputs": [
455
- {
456
- "name": "stdout",
457
- "output_type": "stream",
458
- "text": [
459
- "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[chain:RunnableSequence] Entering Chain run with input:\n",
460
- "\u001b[0m{\n",
461
- " \"input\": \"那刘姥姥先听见告艰苦,只当是没想���了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\"\n",
462
- "}\n",
463
- "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[chain:RunnableSequence > prompt:ChatPromptTemplate] Entering Prompt run with input:\n",
464
- "\u001b[0m{\n",
465
- " \"input\": \"那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\"\n",
466
- "}\n",
467
- "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[chain:RunnableSequence > prompt:ChatPromptTemplate] [1ms] Exiting Prompt run with output:\n",
468
- "\u001b[0m[outputs]\n",
469
- "\u001b[32;1m\u001b[1;3m[llm/start]\u001b[0m \u001b[1m[chain:RunnableSequence > llm:ChatOpenAI] Entering LLM run with input:\n",
470
- "\u001b[0m{\n",
471
- " \"prompts\": [\n",
472
- " \"System: You are a helpful assistant that translates Chinese to English.\\nHuman: You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\\n\\nExample Translations:\\nChinese: 全仗着狐仙搭救。\\nEnglish: Because I was protected by a fox fairy.\\nChinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\\nEnglish: He was the director, the cousin later told them. He had studied abroad and was also a screenwriter; in fact he had written and directed the scene they had earlier seen being filmed.\\nChinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\\nEnglish: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\\nChinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\\nEnglish: The three old Red Guards stood in front of Ye in a row—just like they had stood against Ye Zhetai—trying to recapture their long-forgotten dignity. But the demonic spiritual energy that had once propelled them was gone.\\nChinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\\nEnglish: Mr. Cheng accepted their toast with equanimity and a 'thank you.' Then, turning to Wang Qiyao, he asked if she had anything to say.\\n\\nChinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\\nEnglish:\"\n",
473
- " ]\n",
474
- "}\n",
475
- "\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[chain:RunnableSequence > llm:ChatOpenAI] [1.45s] Exiting LLM run with output:\n",
476
- "\u001b[0m{\n",
477
- " \"generations\": [\n",
478
- " [\n",
479
- " {\n",
480
- " \"text\": \"That Liu Laolao first heard about the hardships and thought it was hopeless, then heard about the twenty taels of silver and smiled with joy, saying, \\\"We also know about difficulties, but as the saying goes: 'A dead camel is still bigger than a horse.'\\\"\",\n",
481
- " \"generation_info\": {\n",
482
- " \"finish_reason\": \"stop\",\n",
483
- " \"logprobs\": null\n",
484
- " },\n",
485
- " \"type\": \"ChatGeneration\",\n",
486
- " \"message\": {\n",
487
- " \"lc\": 1,\n",
488
- " \"type\": \"constructor\",\n",
489
- " \"id\": [\n",
490
- " \"langchain\",\n",
491
- " \"schema\",\n",
492
- " \"messages\",\n",
493
- " \"AIMessage\"\n",
494
- " ],\n",
495
- " \"kwargs\": {\n",
496
- " \"content\": \"That Liu Laolao first heard about the hardships and thought it was hopeless, then heard about the twenty taels of silver and smiled with joy, saying, \\\"We also know about difficulties, but as the saying goes: 'A dead camel is still bigger than a horse.'\\\"\",\n",
497
- " \"response_metadata\": {\n",
498
- " \"token_usage\": {\n",
499
- " \"completion_tokens\": 56,\n",
500
- " \"prompt_tokens\": 484,\n",
501
- " \"total_tokens\": 540\n",
502
- " },\n",
503
- " \"model_name\": \"gpt-4o-mini-2024-07-18\",\n",
504
- " \"system_fingerprint\": \"fp_0f03d4f0ee\",\n",
505
- " \"finish_reason\": \"stop\",\n",
506
- " \"logprobs\": null\n",
507
- " },\n",
508
- " \"type\": \"ai\",\n",
509
- " \"id\": \"run-1c7d8c24-e2d6-4ba3-b87a-16101fb1ce80-0\",\n",
510
- " \"usage_metadata\": {\n",
511
- " \"input_tokens\": 484,\n",
512
- " \"output_tokens\": 56,\n",
513
- " \"total_tokens\": 540\n",
514
- " },\n",
515
- " \"tool_calls\": [],\n",
516
- " \"invalid_tool_calls\": []\n",
517
- " }\n",
518
- " }\n",
519
- " }\n",
520
- " ]\n",
521
- " ],\n",
522
- " \"llm_output\": {\n",
523
- " \"token_usage\": {\n",
524
- " \"completion_tokens\": 56,\n",
525
- " \"prompt_tokens\": 484,\n",
526
- " \"total_tokens\": 540\n",
527
- " },\n",
528
- " \"model_name\": \"gpt-4o-mini-2024-07-18\",\n",
529
- " \"system_fingerprint\": \"fp_0f03d4f0ee\"\n",
530
- " },\n",
531
- " \"run\": null\n",
532
- "}\n",
533
- "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[chain:RunnableSequence] [1.46s] Exiting Chain run with output:\n",
534
- "\u001b[0m[outputs]\n"
535
- ]
536
- },
537
- {
538
- "data": {
539
- "text/plain": [
540
- "'That Liu Laolao first heard about the hardships and thought it was hopeless, then heard about the twenty taels of silver and smiled with joy, saying, \"We also know about difficulties, but as the saying goes: \\'A dead camel is still bigger than a horse.\\'\"'"
541
- ]
542
- },
543
- "execution_count": 11,
544
- "metadata": {},
545
- "output_type": "execute_result"
546
- }
547
- ],
548
- "source": [
549
- "from langchain_core.globals import set_debug\n",
550
- "\n",
551
- "set_debug(True)\n",
552
- "\n",
553
- "translate_via_openai(\n",
554
- " eval_dataset[\"chinese\"][0], translation_prompt, max_tokens=max_new_tokens\n",
555
- ")"
556
- ]
557
- },
558
- {
559
- "cell_type": "code",
560
- "execution_count": 12,
561
- "metadata": {},
562
- "outputs": [],
563
- "source": [
564
- "datasets[\"test\"] = eval_dataset"
565
- ]
566
- },
567
- {
568
- "cell_type": "code",
569
- "execution_count": 13,
570
- "metadata": {},
571
- "outputs": [
572
- {
573
- "name": "stderr",
574
- "output_type": "stream",
575
- "text": [
576
- " 0%| | 0/2 [00:00<?, ?it/s]"
577
- ]
578
- },
579
- {
580
- "name": "stdout",
581
- "output_type": "stream",
582
- "text": [
583
- "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[chain:RunnableSequence] Entering Chain run with input:\n",
584
- "\u001b[0m{\n",
585
- " \"input\": \"那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\"\n",
586
- "}\n",
587
- "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[chain:RunnableSequence > prompt:ChatPromptTemplate] Entering Prompt run with input:\n",
588
- "\u001b[0m{\n",
589
- " \"input\": \"那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\"\n",
590
- "}\n",
591
- "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[chain:RunnableSequence > prompt:ChatPromptTemplate] [1ms] Exiting Prompt run with output:\n",
592
- "\u001b[0m[outputs]\n",
593
- "\u001b[32;1m\u001b[1;3m[llm/start]\u001b[0m \u001b[1m[chain:RunnableSequence > llm:ChatOpenAI] Entering LLM run with input:\n",
594
- "\u001b[0m{\n",
595
- " \"prompts\": [\n",
596
- " \"System: You are a helpful assistant that translates Chinese to English.\\nHuman: You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\\n\\nExample Translations:\\nChinese: 全仗着狐仙搭救。\\nEnglish: Because I was protected by a fox fairy.\\nChinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\\nEnglish: He was the director, the cousin later told them. He had studied abroad and was also a screenwriter; in fact he had written and directed the scene they had earlier seen being filmed.\\nChinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\\nEnglish: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\\nChinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\\nEnglish: The three old Red Guards stood in front of Ye in a row—just like they had stood against Ye Zhetai—trying to recapture their long-forgotten dignity. But the demonic spiritual energy that had once propelled them was gone.\\nChinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\\nEnglish: Mr. Cheng accepted their toast with equanimity and a 'thank you.' Then, turning to Wang Qiyao, he asked if she had anything to say.\\n\\nChinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难���,但只俗语说的:‘瘦死的骆驼比马还大’呢。\\nEnglish:\"\n",
597
- " ]\n",
598
- "}\n"
599
- ]
600
- },
601
- {
602
- "name": "stderr",
603
- "output_type": "stream",
604
- "text": [
605
- " 50%|█████ | 1/2 [00:02<00:02, 2.31s/it]"
606
- ]
607
- },
608
- {
609
- "name": "stdout",
610
- "output_type": "stream",
611
- "text": [
612
- "\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[chain:RunnableSequence > llm:ChatOpenAI] [1.27s] Exiting LLM run with output:\n",
613
- "\u001b[0m{\n",
614
- " \"generations\": [\n",
615
- " [\n",
616
- " {\n",
617
- " \"text\": \"That Liu Laolao first heard about the hardships and thought it was hopeless, then heard about the twenty taels of silver and smiled with joy, saying, \\\"We also know it's difficult, but as the saying goes: 'A dead camel is still bigger than a horse.'\\\"\",\n",
618
- " \"generation_info\": {\n",
619
- " \"finish_reason\": \"stop\",\n",
620
- " \"logprobs\": null\n",
621
- " },\n",
622
- " \"type\": \"ChatGeneration\",\n",
623
- " \"message\": {\n",
624
- " \"lc\": 1,\n",
625
- " \"type\": \"constructor\",\n",
626
- " \"id\": [\n",
627
- " \"langchain\",\n",
628
- " \"schema\",\n",
629
- " \"messages\",\n",
630
- " \"AIMessage\"\n",
631
- " ],\n",
632
- " \"kwargs\": {\n",
633
- " \"content\": \"That Liu Laolao first heard about the hardships and thought it was hopeless, then heard about the twenty taels of silver and smiled with joy, saying, \\\"We also know it's difficult, but as the saying goes: 'A dead camel is still bigger than a horse.'\\\"\",\n",
634
- " \"response_metadata\": {\n",
635
- " \"token_usage\": {\n",
636
- " \"completion_tokens\": 56,\n",
637
- " \"prompt_tokens\": 484,\n",
638
- " \"total_tokens\": 540\n",
639
- " },\n",
640
- " \"model_name\": \"gpt-4o-mini-2024-07-18\",\n",
641
- " \"system_fingerprint\": \"fp_9b0abffe81\",\n",
642
- " \"finish_reason\": \"stop\",\n",
643
- " \"logprobs\": null\n",
644
- " },\n",
645
- " \"type\": \"ai\",\n",
646
- " \"id\": \"run-68581936-c5f8-4d63-a40a-9ae04e88d234-0\",\n",
647
- " \"usage_metadata\": {\n",
648
- " \"input_tokens\": 484,\n",
649
- " \"output_tokens\": 56,\n",
650
- " \"total_tokens\": 540\n",
651
- " },\n",
652
- " \"tool_calls\": [],\n",
653
- " \"invalid_tool_calls\": []\n",
654
- " }\n",
655
- " }\n",
656
- " }\n",
657
- " ]\n",
658
- " ],\n",
659
- " \"llm_output\": {\n",
660
- " \"token_usage\": {\n",
661
- " \"completion_tokens\": 56,\n",
662
- " \"prompt_tokens\": 484,\n",
663
- " \"total_tokens\": 540\n",
664
- " },\n",
665
- " \"model_name\": \"gpt-4o-mini-2024-07-18\",\n",
666
- " \"system_fingerprint\": \"fp_9b0abffe81\"\n",
667
- " },\n",
668
- " \"run\": null\n",
669
- "}\n",
670
- "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[chain:RunnableSequence] [1.28s] Exiting Chain run with output:\n",
671
- "\u001b[0m[outputs]\n",
672
- "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[chain:RunnableSequence] Entering Chain run with input:\n",
673
- "\u001b[0m{\n",
674
- " \"input\": \"后来她不挣扎了,对我说,混蛋,你要把我怎么办。\"\n",
675
- "}\n",
676
- "\u001b[32;1m\u001b[1;3m[chain/start]\u001b[0m \u001b[1m[chain:RunnableSequence > prompt:ChatPromptTemplate] Entering Prompt run with input:\n",
677
- "\u001b[0m{\n",
678
- " \"input\": \"后来她不挣扎了,对我说,混蛋,你要把我怎么办。\"\n",
679
- "}\n",
680
- "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[chain:RunnableSequence > prompt:ChatPromptTemplate] [1ms] Exiting Prompt run with output:\n",
681
- "\u001b[0m[outputs]\n",
682
- "\u001b[32;1m\u001b[1;3m[llm/start]\u001b[0m \u001b[1m[chain:RunnableSequence > llm:ChatOpenAI] Entering LLM run with input:\n",
683
- "\u001b[0m{\n",
684
- " \"prompts\": [\n",
685
- " \"System: You are a helpful assistant that translates Chinese to English.\\nHuman: You will be given a Chinese sentence to translate. If it is an incomplete sentence, or if you are unsure about the meaning, simply copy the input text as your output. Do not output any additional sentence such as explanation or reasoning.\\n\\nExample Translations:\\nChinese: 全仗着狐仙搭救。\\nEnglish: Because I was protected by a fox fairy.\\nChinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\\nEnglish: He was the director, the cousin later told them. He had studied abroad and was also a screenwriter; in fact he had written and directed the scene they had earlier seen being filmed.\\nChinese: 这凤���忽然想起一件事来,便向窗外叫:“蓉儿回来!”\\nEnglish: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\\nChinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\\nEnglish: The three old Red Guards stood in front of Ye in a row—just like they had stood against Ye Zhetai—trying to recapture their long-forgotten dignity. But the demonic spiritual energy that had once propelled them was gone.\\nChinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\\nEnglish: Mr. Cheng accepted their toast with equanimity and a 'thank you.' Then, turning to Wang Qiyao, he asked if she had anything to say.\\n\\nChinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\\nEnglish:\"\n",
686
- " ]\n",
687
- "}\n"
688
- ]
689
- },
690
- {
691
- "name": "stderr",
692
- "output_type": "stream",
693
- "text": [
694
- "100%|██████████| 2/2 [00:04<00:00, 2.12s/it]"
695
- ]
696
- },
697
- {
698
- "name": "stdout",
699
- "output_type": "stream",
700
- "text": [
701
- "\u001b[36;1m\u001b[1;3m[llm/end]\u001b[0m \u001b[1m[chain:RunnableSequence > llm:ChatOpenAI] [908ms] Exiting LLM run with output:\n",
702
- "\u001b[0m{\n",
703
- " \"generations\": [\n",
704
- " [\n",
705
- " {\n",
706
- " \"text\": \"Later, she stopped struggling and said to me, \\\"Bastard, what are you going to do with me?\\\"\",\n",
707
- " \"generation_info\": {\n",
708
- " \"finish_reason\": \"stop\",\n",
709
- " \"logprobs\": null\n",
710
- " },\n",
711
- " \"type\": \"ChatGeneration\",\n",
712
- " \"message\": {\n",
713
- " \"lc\": 1,\n",
714
- " \"type\": \"constructor\",\n",
715
- " \"id\": [\n",
716
- " \"langchain\",\n",
717
- " \"schema\",\n",
718
- " \"messages\",\n",
719
- " \"AIMessage\"\n",
720
- " ],\n",
721
- " \"kwargs\": {\n",
722
- " \"content\": \"Later, she stopped struggling and said to me, \\\"Bastard, what are you going to do with me?\\\"\",\n",
723
- " \"response_metadata\": {\n",
724
- " \"token_usage\": {\n",
725
- " \"completion_tokens\": 24,\n",
726
- " \"prompt_tokens\": 433,\n",
727
- " \"total_tokens\": 457\n",
728
- " },\n",
729
- " \"model_name\": \"gpt-4o-mini-2024-07-18\",\n",
730
- " \"system_fingerprint\": \"fp_611b667b19\",\n",
731
- " \"finish_reason\": \"stop\",\n",
732
- " \"logprobs\": null\n",
733
- " },\n",
734
- " \"type\": \"ai\",\n",
735
- " \"id\": \"run-e4bb10fb-f7c4-4440-82ba-c13a1a82bc00-0\",\n",
736
- " \"usage_metadata\": {\n",
737
- " \"input_tokens\": 433,\n",
738
- " \"output_tokens\": 24,\n",
739
- " \"total_tokens\": 457\n",
740
- " },\n",
741
- " \"tool_calls\": [],\n",
742
- " \"invalid_tool_calls\": []\n",
743
- " }\n",
744
- " }\n",
745
- " }\n",
746
- " ]\n",
747
- " ],\n",
748
- " \"llm_output\": {\n",
749
- " \"token_usage\": {\n",
750
- " \"completion_tokens\": 24,\n",
751
- " \"prompt_tokens\": 433,\n",
752
- " \"total_tokens\": 457\n",
753
- " },\n",
754
- " \"model_name\": \"gpt-4o-mini-2024-07-18\",\n",
755
- " \"system_fingerprint\": \"fp_611b667b19\"\n",
756
- " },\n",
757
- " \"run\": null\n",
758
- "}\n",
759
- "\u001b[36;1m\u001b[1;3m[chain/end]\u001b[0m \u001b[1m[chain:RunnableSequence] [918ms] Exiting Chain run with output:\n",
760
- "\u001b[0m[outputs]\n"
761
- ]
762
- },
763
- {
764
- "name": "stderr",
765
- "output_type": "stream",
766
- "text": [
767
- "\n"
768
- ]
769
- }
770
- ],
771
- "source": [
772
- "predictions = eval_openai(5, datasets)"
773
- ]
774
- },
775
- {
776
- "cell_type": "code",
777
- "execution_count": 14,
778
- "metadata": {},
779
- "outputs": [
780
- {
781
- "name": "stdout",
782
- "output_type": "stream",
783
- "text": [
784
- "['That Liu Laolao first heard about the hardships and thought it was hopeless, then heard about the twenty taels of silver and smiled with joy, saying, \"We also know it\\'s difficult, but as the saying goes: \\'A dead camel is still bigger than a horse.\\'\"', 'Later, she stopped struggling and said to me, \"Bastard, what are you going to do with me?\"']\n"
785
- ]
786
- }
787
- ],
788
- "source": [
789
- "print(predictions)"
790
- ]
791
- },
792
- {
793
- "cell_type": "code",
794
- "execution_count": 15,
795
- "metadata": {},
796
- "outputs": [
797
- {
798
- "data": {
799
- "text/plain": [
800
- "{'meteor': 0.5376810911615811,\n",
801
- " 'bleu_scores': {'bleu': 0.16133991724232039,\n",
802
- " 'precisions': [0.5454545454545454,\n",
803
- " 0.26666666666666666,\n",
804
- " 0.1643835616438356,\n",
805
- " 0.09859154929577464],\n",
806
- " 'brevity_penalty': 0.7322097138745853,\n",
807
- " 'length_ratio': 0.7623762376237624,\n",
808
- " 'translation_length': 77,\n",
809
- " 'reference_length': 101},\n",
810
- " 'rouge_scores': {'rouge1': 0.5594202898550725,\n",
811
- " 'rouge2': 0.362051015096304,\n",
812
- " 'rougeL': 0.5246376811594203,\n",
813
- " 'rougeLsum': 0.5246376811594203},\n",
814
- " 'accuracy': 0.0}"
815
- ]
816
- },
817
- "execution_count": 15,
818
- "metadata": {},
819
- "output_type": "execute_result"
820
- }
821
- ],
822
- "source": [
823
- "calc_metrics(eval_dataset[\"english\"], predictions)"
824
- ]
825
- }
826
- ],
827
- "metadata": {
828
- "accelerator": "GPU",
829
- "application/vnd.databricks.v1+notebook": {
830
- "dashboards": [],
831
- "environmentMetadata": null,
832
- "language": "python",
833
- "notebookMetadata": {
834
- "mostRecentlyExecutedCommandWithImplicitDF": {
835
- "commandId": -1,
836
- "dataframes": [
837
- "_sqldf"
838
- ]
839
- },
840
- "pythonIndentUnit": 4
841
- },
842
- "notebookName": "10_eval-lf-medium-py3.11",
843
- "widgets": {}
844
- },
845
- "colab": {
846
- "gpuType": "L4",
847
- "provenance": []
848
- },
849
- "kernelspec": {
850
- "display_name": "Python 3",
851
- "name": "python3"
852
- },
853
- "language_info": {
854
- "codemirror_mode": {
855
- "name": "ipython",
856
- "version": 3
857
- },
858
- "file_extension": ".py",
859
- "mimetype": "text/x-python",
860
- "name": "python",
861
- "nbconvert_exporter": "python",
862
- "pygments_lexer": "ipython3",
863
- "version": "3.11.9"
864
- }
865
- },
866
- "nbformat": 4,
867
- "nbformat_minor": 0
868
- }
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0628ae63c02a037f9c2e121f9a40903b82935ba1d669bf9e4e43129a1ae0663c
3
+ size 36586
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
notebooks/02_Fine_Tune_OpenAI.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
notebooks/02a_Fine_Tune_GPT-4o.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
notebooks/03a_RAPGeT_v2_Data Analysis_Chat_Template.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
notebooks/03b_RAPGeT_v2_Data Analysis_Generic_Prompt.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
requirements.txt CHANGED
@@ -10,7 +10,11 @@ scikit-learn==1.5.0
10
  jupyter
11
  ipywidgets
12
  packaging
13
- langchain_openai==0.1.13
 
 
 
 
14
  wandb==0.17.6
15
  transformers==4.45.1
16
  bitsandbytes #==0.43.3
@@ -20,3 +24,4 @@ accelerate==0.32.0
20
  peft==0.11.1
21
  sacrebleu==2.4.2
22
  unbabel-comet==2.2.2
 
 
10
  jupyter
11
  ipywidgets
12
  packaging
13
+ langchain-core==0.3.10
14
+ langchain_openai==0.2.2
15
+ langchain==0.3.3
16
+ langchain-community==0.3.2
17
+ openai==1.51.2
18
  wandb==0.17.6
19
  transformers==4.45.1
20
  bitsandbytes #==0.43.3
 
24
  peft==0.11.1
25
  sacrebleu==2.4.2
26
  unbabel-comet==2.2.2
27
+ gradio==5.0.2
results/mac-results_rpp_with_mnt_2048_generic_prompt_metrics.csv CHANGED
@@ -16,7 +16,8 @@ shenzhi-wang/Llama3.1-70B-Chinese-Chat,1.02,0.743018615750854,0.4514907128972251
16
  shenzhi-wang/Llama3.1-70B-Chinese-Chat,1.04,0.7432195577780335,0.4517500968367987,10.080425294411064,0.1008042529441106,0.4200973007348334,0.01059135039717564,35.19770520741395,35.18358340688438,0.8244802169835412,0.6235766669370041,1.0,6
17
  shenzhi-wang/Llama3.1-70B-Chinese-Chat,1.06,0.7430821573139815,0.4484154407825542,10.37470506193322,0.1037470506193321,0.4160289393328045,1.8005295675198587,26.880847308031775,28.656663724624888,0.8478345432646117,0.6381932626507077,1.0,3
18
  shenzhi-wang/Llama3.1-70B-Chinese-Chat,1.08,0.7435937259684909,0.4407733547418294,10.930453247368872,0.1093045324736887,0.4113063412348818,0.09267431597528684,12.007943512797882,12.072374227714034,0.9329421050825354,0.6953650250037441,1.0,3
19
- shenzhi-wang/Llama3.1-70B-Chinese-Chat,1.10,0.7427059700687901,0.4358940590119784,11.381344076286156,0.1138134407628615,0.4062980635945339,0.0176522506619594,11.914386584289497,11.905560458958517,0.9312420672746087,0.6933551155892559,1.0,3
 
20
  shenzhi-wang/Mistral-7B-v0.3-Chinese-Chat,1.00,0.7222260562908512,0.4039898602650971,13.461179673541356,0.1346117967354136,0.3819960428004565,0.05736981465136805,5.87378640776699,5.9179170344218885,0.9486112388485238,0.6860492554476049,1.0,1
21
  shenzhi-wang/Mistral-7B-v0.3-Chinese-Chat,1.02,0.723643534970515,0.4051102919608809,13.18537912294539,0.1318537912294539,0.3824621732976229,0.06266548984995587,5.840247131509267,5.8914386584289495,0.9486127363429205,0.6873967610154514,1.0,1
22
  shenzhi-wang/Mistral-7B-v0.3-Chinese-Chat,1.04,0.7238812581796301,0.4039456988919502,13.314773371306682,0.1331477337130668,0.3813737464821349,0.05736981465136805,5.845542806707855,5.889673433362754,0.948840810819099,0.6877794238881113,1.0,1
 
16
  shenzhi-wang/Llama3.1-70B-Chinese-Chat,1.04,0.7432195577780335,0.4517500968367987,10.080425294411064,0.1008042529441106,0.4200973007348334,0.01059135039717564,35.19770520741395,35.18358340688438,0.8244802169835412,0.6235766669370041,1.0,6
17
  shenzhi-wang/Llama3.1-70B-Chinese-Chat,1.06,0.7430821573139815,0.4484154407825542,10.37470506193322,0.1037470506193321,0.4160289393328045,1.8005295675198587,26.880847308031775,28.656663724624888,0.8478345432646117,0.6381932626507077,1.0,3
18
  shenzhi-wang/Llama3.1-70B-Chinese-Chat,1.08,0.7435937259684909,0.4407733547418294,10.930453247368872,0.1093045324736887,0.4113063412348818,0.09267431597528684,12.007943512797882,12.072374227714034,0.9329421050825354,0.6953650250037441,1.0,3
19
+ shenzhi-wang/Llama3.1-70B-Chinese-Chat,1.10,0.7427059700687901,0.4358940590119784,11.381344076286156,0.1138134407628615,0.4062980635945339,0.03971756398940865,0.6681376875551632,0.6822594880847308,0.9961814337654126,0.739875306107768,1.0,1
20
+ shenzhi-wang/Llama3.1-8B-Chinese-Chat,1.00,0.38886049199135875,0.20558757581682777,0.24345871819597525,0.0024345871819597513,0.18445521880258564,638.2797881729921,3889.9232127096207,4528.131509267431,0.07898833236661085,0.15481161323631304,0.9240953221535746,570
21
  shenzhi-wang/Mistral-7B-v0.3-Chinese-Chat,1.00,0.7222260562908512,0.4039898602650971,13.461179673541356,0.1346117967354136,0.3819960428004565,0.05736981465136805,5.87378640776699,5.9179170344218885,0.9486112388485238,0.6860492554476049,1.0,1
22
  shenzhi-wang/Mistral-7B-v0.3-Chinese-Chat,1.02,0.723643534970515,0.4051102919608809,13.18537912294539,0.1318537912294539,0.3824621732976229,0.06266548984995587,5.840247131509267,5.8914386584289495,0.9486127363429205,0.6873967610154514,1.0,1
23
  shenzhi-wang/Mistral-7B-v0.3-Chinese-Chat,1.04,0.7238812581796301,0.4039456988919502,13.314773371306682,0.1331477337130668,0.3813737464821349,0.05736981465136805,5.845542806707855,5.889673433362754,0.948840810819099,0.6877794238881113,1.0,1