{"cells":[{"cell_type":"code","execution_count":1,"metadata":{"executionInfo":{"elapsed":476,"status":"ok","timestamp":1720679526275,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"},"user_tz":-480},"id":"uWKRSV6eZsCn"},"outputs":[],"source":["%load_ext autoreload\n","%autoreload 2"]},{"cell_type":"code","execution_count":2,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{"byteLimit":2048000,"rowLimit":10000},"inputWidgets":{},"nuid":"6d394937-6c99-4a7c-9d32-7600a280032f","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":5,"status":"ok","timestamp":1720679529345,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"},"user_tz":-480},"id":"G5pNu3zgZBrL","outputId":"160a554f-fb08-4aa0-bc00-0422fb7c1fac"},"outputs":[{"name":"stdout","output_type":"stream","text":["workding dir: /Users/inflaton/code/engd/papers/rapget-translation\n"]}],"source":["import os\n","import sys\n","from pathlib import Path\n","\n","# check if workding_dir is in local variables\n","if \"workding_dir\" not in locals():\n"," workding_dir = str(Path.cwd().parent)\n","\n","os.chdir(workding_dir)\n","sys.path.append(workding_dir)\n","print(\"workding dir:\", workding_dir)"]},{"cell_type":"code","execution_count":3,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{"byteLimit":2048000,"rowLimit":10000},"inputWidgets":{},"nuid":"9f67ec60-2f24-411c-84eb-0dd664b44775","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":3,"status":"ok","timestamp":1720679529345,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"},"user_tz":-480},"id":"hPCC-6m7ZBrM","outputId":"c7aa2c96-5e99-440a-c148-201d79465ff9"},"outputs":[{"name":"stdout","output_type":"stream","text":["loading env vars from: /Users/inflaton/code/engd/papers/rapget-translation/.env\n"]},{"data":{"text/plain":["True"]},"execution_count":3,"metadata":{},"output_type":"execute_result"}],"source":["from dotenv import find_dotenv, load_dotenv\n","\n","found_dotenv = find_dotenv(\".env\")\n","\n","if len(found_dotenv) == 0:\n"," found_dotenv = find_dotenv(\".env.example\")\n","print(f\"loading env vars from: {found_dotenv}\")\n","load_dotenv(found_dotenv, override=True)"]},{"cell_type":"code","execution_count":4,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{"byteLimit":2048000,"rowLimit":10000},"inputWidgets":{},"nuid":"f1597656-8042-4878-9d3b-9ebfb8dd86dc","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":3,"status":"ok","timestamp":1720679529345,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"},"user_tz":-480},"id":"1M3IraVtZBrM","outputId":"29ab35f6-2970-4ade-d85d-3174acf8cda0"},"outputs":[{"name":"stdout","output_type":"stream","text":["01-ai/Yi-1.5-9B-Chat None False datasets/mac/mac.tsv results/mac-results.csv False 300\n"]}],"source":["import os\n","\n","model_name = os.getenv(\"MODEL_NAME\")\n","adapter_name_or_path = os.getenv(\"ADAPTER_NAME_OR_PATH\")\n","load_in_4bit = os.getenv(\"LOAD_IN_4BIT\") == \"true\"\n","data_path = os.getenv(\"DATA_PATH\")\n","results_path = os.getenv(\"RESULTS_PATH\")\n","use_english_datasets = os.getenv(\"USE_ENGLISH_DATASETS\") == \"true\"\n","max_new_tokens = int(os.getenv(\"MAX_NEW_TOKENS\", 2048))\n","\n","print(model_name, adapter_name_or_path, load_in_4bit, data_path, results_path, use_english_datasets, max_new_tokens)"]},{"cell_type":"code","execution_count":5,"metadata":{"application/vnd.databricks.v1+cell":{"cellMetadata":{"byteLimit":2048000,"rowLimit":10000},"inputWidgets":{},"nuid":"b2a43943-9324-4839-9a47-cfa72de2244b","showTitle":false,"title":""},"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":564,"status":"ok","timestamp":1720679529907,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"},"user_tz":-480},"id":"UgMvt6dIZBrM","outputId":"ce37581c-fd26-46c2-ad87-d933d99f68f7"},"outputs":[{"name":"stdout","output_type":"stream","text":["Python 3.11.9\n","Name: torch\n","Version: 2.4.0\n","Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration\n","Home-page: https://pytorch.org/\n","Author: PyTorch Team\n","Author-email: packages@pytorch.org\n","License: BSD-3\n","Location: /Users/inflaton/anaconda3/envs/rapget/lib/python3.11/site-packages\n","Requires: filelock, fsspec, jinja2, networkx, sympy, typing-extensions\n","Required-by: accelerate, peft, torchaudio, torchvision\n","---\n","Name: transformers\n","Version: 4.43.3\n","Summary: State-of-the-art Machine Learning for JAX, PyTorch and TensorFlow\n","Home-page: https://github.com/huggingface/transformers\n","Author: The Hugging Face team (past and future) with the help of all our contributors (https://github.com/huggingface/transformers/graphs/contributors)\n","Author-email: transformers@huggingface.co\n","License: Apache 2.0 License\n","Location: /Users/inflaton/anaconda3/envs/rapget/lib/python3.11/site-packages\n","Requires: filelock, huggingface-hub, numpy, packaging, pyyaml, regex, requests, safetensors, tokenizers, tqdm\n","Required-by: peft\n","CPU times: user 11.7 ms, sys: 10.4 ms, total: 22.1 ms\n","Wall time: 2 s\n"]}],"source":["%%time\n","os.environ[\"TOKENIZERS_PARALLELISM\"] = \"true\"\n","\n","!python --version\n","!pip show torch transformers"]},{"cell_type":"code","execution_count":6,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":1685,"status":"ok","timestamp":1720679531591,"user":{"displayName":"HUANG DONGHAO _","userId":"00977795705617022768"},"user_tz":-480},"id":"ZuS_FsLyZBrN","outputId":"2cba0105-c505-4395-afbd-2f2fee6581d0"},"outputs":[{"name":"stderr","output_type":"stream","text":["[nltk_data] Downloading package wordnet to\n","[nltk_data] /Users/inflaton/nltk_data...\n","[nltk_data] Package wordnet is already up-to-date!\n","[nltk_data] Downloading package punkt to /Users/inflaton/nltk_data...\n","[nltk_data] Package punkt is already up-to-date!\n","[nltk_data] Downloading package omw-1.4 to\n","[nltk_data] /Users/inflaton/nltk_data...\n","[nltk_data] Package omw-1.4 is already up-to-date!\n"]},{"name":"stdout","output_type":"stream","text":["loading: /Users/inflaton/code/engd/papers/rapget-translation/eval_modules/calc_repetitions.py\n","loading /Users/inflaton/code/engd/papers/rapget-translation/llm_toolkit/translation_utils.py\n"]},{"name":"stderr","output_type":"stream","text":["[nltk_data] Downloading package wordnet to\n","[nltk_data] /Users/inflaton/nltk_data...\n","[nltk_data] Package wordnet is already up-to-date!\n","[nltk_data] Downloading package punkt to /Users/inflaton/nltk_data...\n","[nltk_data] Package punkt is already up-to-date!\n","[nltk_data] Downloading package omw-1.4 to\n","[nltk_data] /Users/inflaton/nltk_data...\n","[nltk_data] Package omw-1.4 is already up-to-date!\n"]},{"name":"stdout","output_type":"stream","text":["MPS is available\n"]}],"source":["from llm_toolkit.llm_utils import *\n","from llm_toolkit.translation_utils import *\n","\n","device = check_gpu()"]},{"cell_type":"code","execution_count":7,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["loading model: 01-ai/Yi-1.5-9B-Chat with adapter: None\n"]},{"data":{"application/vnd.jupyter.widget-view+json":{"model_id":"7c89049569084209a59d0209b96315f8","version_major":2,"version_minor":0},"text/plain":["Loading checkpoint shards: 0%| | 0/4 [00:00user\n","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","\n","Example Translations:\n","Chinese: 全仗着狐仙搭救。\n","English: Because I was protected by a fox fairy.\n","Chinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\n","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","Chinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\n","English: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\n","Chinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\n","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","Chinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\n","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","\n","Chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n","English:<|im_end|>\n","<|im_start|>assistant\n","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","--------------------------------------------------\n","prompt: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n","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","\n","Example Translations:\n","Chinese: 全仗着狐仙搭救。\n","English: Because I was protected by a fox fairy.\n","Chinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\n","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","Chinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\n","English: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\n","Chinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\n","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","Chinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\n","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","\n","Chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n","English:<|im_end|>\n","<|im_start|>assistant\n","\n","--------------------------------------------------\n","chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n","--------------------------------------------------\n","english: After a while, she no longer struggled and said, You bastard! What are you going to do with me?\n","--------------------------------------------------\n","text: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n","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","\n","Example Translations:\n","Chinese: 全仗着狐仙搭救。\n","English: Because I was protected by a fox fairy.\n","Chinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\n","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","Chinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\n","English: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\n","Chinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\n","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","Chinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\n","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","\n","Chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n","English:<|im_end|>\n","<|im_start|>assistant\n","After a while, she no longer struggled and said, You bastard! What are you going to do with me?<|im_end|>\n","--------------------------------------------------\n","prompt: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n","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","\n","Example Translations:\n","Chinese: 全仗着狐仙搭救。\n","English: Because I was protected by a fox fairy.\n","Chinese: 过后,表哥告诉她俩,这人是导演,在外国留过学的,还会编剧,今天拍的这戏,就是他自编自导的。\n","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","Chinese: 这凤姐忽然想起一件事来,便向窗外叫:“蓉儿回来!”\n","English: Xi-feng suddenly seemed to remember something, and called to him through the window, 'Rong, come back!'\n","Chinese: 三个老红卫兵走到叶文洁面前,面对着她站成了一排——当年,她们也是这样面对叶哲泰的——试图再现那早已忘却的尊严,但她们当年那魔鬼般的精神力量显然已荡然无存。\n","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","Chinese: 程先生照单全收,都是一个“谢”字,然后问王琦瑶有什么话说。\n","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","\n","Chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n","English:<|im_end|>\n","<|im_start|>assistant\n","\n"]}],"source":["print_row_details(eval_dataset.to_pandas(), range(len(eval_dataset)))"]},{"cell_type":"code","execution_count":12,"metadata":{},"outputs":[{"name":"stderr","output_type":"stream","text":[" 50%|█████ | 1/2 [22:49<22:49, 1369.92s/it]"]},{"name":"stdout","output_type":"stream","text":["Batch output: ['The task is to translate a given Chinese sentence into English. If the sentence is incomplete or unclear, the assistant should simply copy the input text as the output without providing any additional explanation or reasoning.\\n\\nHere\\'s how to use the guidelines to find the answer:\\n\\n1. Read the given Chinese sentence carefully.\\n2. If the sentence is incomplete or unclear, copy the input text as the output.\\n3. If the sentence is clear, translate it into English while maintaining the original meaning.\\n4. Ensure that the translation is accurate and conveys the intended message.\\n\\nNow, let\\'s apply these guidelines to the given Chinese sentence:\\n\\nChinese: 那刘姥姥先听见告艰苦, 只当是没想头了, 又听见给他二十两银子, 喜的眉开眼笑道: “我们也知道艰难的, 但只俗语说的: ‘瘦死的骆驼比马还大’呢。\\n\\nFollowing the guidelines:\\n\\n1. Read the sentence carefully.\\n2. The sentence is clear, so we will translate it into English.\\n3. Translate the sentence: \"The first thing Dao-hsi heard was that they were in difficulties, and she thought there was no way out. Then she heard that they would give her twenty silver dollars, and she was overjoyed, smiling from ear to ear, saying, \\'We know the difficulties too, but']\n"]},{"name":"stderr","output_type":"stream","text":["100%|██████████| 2/2 [1:05:53<00:00, 1976.68s/it]\n"]}],"source":["predictions = eval_model(\n"," model, tokenizer, eval_dataset, device=device, max_new_tokens=max_new_tokens\n",")"]},{"cell_type":"code","execution_count":13,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["['The task is to translate a given Chinese sentence into English. If the sentence is incomplete or unclear, the assistant should simply copy the input text as the output without providing any additional explanation or reasoning.\\n\\nHere\\'s how to use the guidelines to find the answer:\\n\\n1. Read the given Chinese sentence carefully.\\n2. If the sentence is incomplete or unclear, copy the input text as the output.\\n3. If the sentence is clear, translate it into English while maintaining the original meaning.\\n4. Ensure that the translation is accurate and conveys the intended message.\\n\\nNow, let\\'s apply these guidelines to the given Chinese sentence:\\n\\nChinese: 那刘姥姥先听见告艰苦, 只当是没想头了, 又听见给他二十两银子, 喜的眉开眼笑道: “我们也知道艰难的, 但只俗语说的: ‘瘦死的骆驼比马还大’呢。\\n\\nFollowing the guidelines:\\n\\n1. Read the sentence carefully.\\n2. The sentence is clear, so we will translate it into English.\\n3. Translate the sentence: \"The first thing Dao-hsi heard was that they were in difficulties, and she thought there was no way out. Then she heard that they would give her twenty silver dollars, and she was overjoyed, smiling from ear to ear, saying, \\'We know the difficulties too, but', 'Later, she stopped struggling and said to me, \"Asshole, what are you going to do with me?\"']\n"]}],"source":["print(predictions)"]},{"cell_type":"code","execution_count":14,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["loading /Users/inflaton/code/engd/papers/rapget-translation/llm_toolkit/translation_utils_v1.py\n"]},{"name":"stderr","output_type":"stream","text":["[nltk_data] Downloading package wordnet to\n","[nltk_data] /Users/inflaton/nltk_data...\n","[nltk_data] Package wordnet is already up-to-date!\n","[nltk_data] Downloading package punkt to /Users/inflaton/nltk_data...\n","[nltk_data] Package punkt is already up-to-date!\n","[nltk_data] Downloading package omw-1.4 to\n","[nltk_data] /Users/inflaton/nltk_data...\n","[nltk_data] Package omw-1.4 is already up-to-date!\n"]},{"name":"stdout","output_type":"stream","text":["loading train/test data files\n","DatasetDict({\n"," train: Dataset({\n"," features: ['chinese', 'english', 'text', 'prompt'],\n"," num_rows: 4528\n"," })\n"," test: Dataset({\n"," features: ['chinese', 'english', 'text', 'prompt'],\n"," num_rows: 1133\n"," })\n","})\n"]}],"source":["from llm_toolkit.translation_utils_v1 import (\n"," load_translation_dataset as load_translation_dataset_v1,\n",")\n","\n","dataset_v1 = load_translation_dataset_v1(data_path, tokenizer=tokenizer)"]},{"cell_type":"code","execution_count":15,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["--------------------------------------------------\n","chinese: 老耿端起枪,眯缝起一只三角眼,一搂扳机响了枪,冰雹般的金麻雀劈哩啪啦往下落,铁砂子在柳枝间飞迸着,嚓嚓有声。\n","--------------------------------------------------\n","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","--------------------------------------------------\n","text: You are an expert in translating Chinese to English.<|im_start|>user\n","Please translate the following Chinese text into English and provide only the translated content, nothing else.\n","老耿端起枪,眯缝起一只三角眼,一搂扳机响了枪,冰雹般的金麻雀劈哩啪啦往下落,铁砂子在柳枝间飞迸着,嚓嚓有声。<|im_end|>\n","<|im_start|>assistant\n","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","--------------------------------------------------\n","prompt: You are an expert in translating Chinese to English.<|im_start|>user\n","Please translate the following Chinese text into English and provide only the translated content, nothing else.\n","老耿端起枪,眯缝起一只三角眼,一搂扳机响了枪,冰雹般的金麻雀劈哩啪啦往下落,铁砂子在柳枝间飞迸着,嚓嚓有声。<|im_end|>\n","<|im_start|>assistant\n","\n"]}],"source":["print_row_details(dataset_v1[\"test\"].to_pandas())"]},{"cell_type":"code","execution_count":16,"metadata":{},"outputs":[{"name":"stderr","output_type":"stream","text":[" 50%|█████ | 1/2 [31:44<31:44, 1904.57s/it]"]},{"name":"stdout","output_type":"stream","text":["Batch output: [\"First, I'll identify the key phrases and words in the Chinese text:\\n\\n1. 那刘姥姥 (that Diao Huawang)\\n2. 先听见告艰苦 (first heard of the hardship)\\n3. 只当是没想头了 (thought it was hopeless)\\n4. 又听见给他二十两银子 (also heard that he received 20 silver yuan)\\n5. 喜的眉开眼笑 (very happy, smiling broadly)\\n6. 我们也知道艰难的 (we also know the hardship)\\n7. 但只俗语说的 (but as the saying goes)\\n8. 瘦死的骆驼比马还大 (a camel that has lost weight is still larger than a horse)\\n\\nNow, I'll translate these key phrases and words into English:\\n\\n1. That Diao Huawang\\n2. First heard of the hardship\\n3. Thought it was hopeless\\n4. Also heard that he received 20 silver yuan\\n5. Was very happy, smiling broadly\\n6. We also know the hardship\\n7. But as the saying goes\\n8. A camel that has lost weight is still larger than a horse\\n\\nFinally, I'll construct the English sentence using these translated phrases:\\n\\nThat Diao Huawang first heard of the hardship, thinking it was hopeless, and then heard that he received\"]\n"]},{"name":"stderr","output_type":"stream","text":["100%|██████████| 2/2 [1:12:03<00:00, 2161.88s/it]\n"]},{"data":{"text/plain":["[\"First, I'll identify the key phrases and words in the Chinese text:\\n\\n1. 那刘姥姥 (that Diao Huawang)\\n2. 先听见告艰苦 (first heard of the hardship)\\n3. 只当是没想头了 (thought it was hopeless)\\n4. 又听见给他二十两银子 (also heard that he received 20 silver yuan)\\n5. 喜的眉开眼笑 (very happy, smiling broadly)\\n6. 我们也知道艰难的 (we also know the hardship)\\n7. 但只俗语说的 (but as the saying goes)\\n8. 瘦死的骆驼比马还大 (a camel that has lost weight is still larger than a horse)\\n\\nNow, I'll translate these key phrases and words into English:\\n\\n1. That Diao Huawang\\n2. First heard of the hardship\\n3. Thought it was hopeless\\n4. Also heard that he received 20 silver yuan\\n5. Was very happy, smiling broadly\\n6. We also know the hardship\\n7. But as the saying goes\\n8. A camel that has lost weight is still larger than a horse\\n\\nFinally, I'll construct the English sentence using these translated phrases:\\n\\nThat Diao Huawang first heard of the hardship, thinking it was hopeless, and then heard that he received\",\n"," 'Later, she stopped struggling and said to me, \"Son of a bitch, what are you going to do with me?\"']"]},"execution_count":16,"metadata":{},"output_type":"execute_result"}],"source":["eval_dataset_v1 = dataset_v1[\"test\"].select([260, 908])\n","predictions_v1 = eval_model(\n"," model, tokenizer, eval_dataset_v1, device=device, max_new_tokens=max_new_tokens\n",")\n","predictions_v1"]},{"cell_type":"code","execution_count":25,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["[\"First, I'll identify the key phrases and words in the Chinese text:\\n\\n1. 那刘姥姥 (that Diao Huawang)\\n2. 先听见告艰苦 (first heard of the hardship)\\n3. 只当是没想头了 (thought it was hopeless)\\n4. 又听见给他二十两银子 (also heard that he received 20 silver yuan)\\n5. 喜的眉开眼笑 (very happy, smiling broadly)\\n6. 我们也知道艰难的 (we also know the hardship)\\n7. 但只俗语说的 (but as the saying goes)\\n8. 瘦死的骆驼比马还大 (a camel that has lost weight is still larger than a horse)\\n\\nNow, I'll translate these key phrases and words into English:\\n\\n1. That Diao Huawang\\n2. First heard of the hardship\\n3. Thought it was hopeless\\n4. Also heard that he received 20 silver yuan\\n5. Was very happy, smiling broadly\\n6. We also know the hardship\\n7. But as the saying goes\\n8. A camel that has lost weight is still larger than a horse\\n\\nFinally, I'll construct the English sentence using these translated phrases:\\n\\nThat Diao Huawang first heard of the hardship, thinking it was hopeless, and then heard that he received\", 'Later, she stopped struggling and said to me, \"Son of a bitch, what are you going to do with me?\"']\n"]}],"source":["print(predictions_v1)"]},{"cell_type":"code","execution_count":23,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["--------------------------------------------------\n","chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n","--------------------------------------------------\n","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","--------------------------------------------------\n","text: You are an expert in translating Chinese to English.<|im_start|>user\n","Please translate the following Chinese text into English and provide only the translated content, nothing else.\n","那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。<|im_end|>\n","<|im_start|>assistant\n","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","--------------------------------------------------\n","prompt: You are an expert in translating Chinese to English.<|im_start|>user\n","Please translate the following Chinese text into English and provide only the translated content, nothing else.\n","那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。<|im_end|>\n","<|im_start|>assistant\n","\n","--------------------------------------------------\n","chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n","--------------------------------------------------\n","english: After a while, she no longer struggled and said, You bastard! What are you going to do with me?\n","--------------------------------------------------\n","text: You are an expert in translating Chinese to English.<|im_start|>user\n","Please translate the following Chinese text into English and provide only the translated content, nothing else.\n","后来她不挣扎了,对我说,混蛋,你要把我怎么办。<|im_end|>\n","<|im_start|>assistant\n","After a while, she no longer struggled and said, You bastard! What are you going to do with me?<|im_end|>\n","--------------------------------------------------\n","prompt: You are an expert in translating Chinese to English.<|im_start|>user\n","Please translate the following Chinese text into English and provide only the translated content, nothing else.\n","后来她不挣扎了,对我说,混蛋,你要把我怎么办。<|im_end|>\n","<|im_start|>assistant\n","\n"]}],"source":["print_row_details(eval_dataset_v1.to_pandas(), range(len(eval_dataset_v1)))"]},{"cell_type":"code","execution_count":17,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["loading train/test data files\n"]},{"data":{"application/vnd.jupyter.widget-view+json":{"model_id":"1ab2b86ace5f4210bb27b51fb5d66c7a","version_major":2,"version_minor":0},"text/plain":["Map: 0%| | 0/4528 [00:00user\n","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","\n","Chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n","English:<|im_end|>\n","<|im_start|>assistant\n","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","--------------------------------------------------\n","prompt: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n","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","\n","Chinese: 那刘姥姥先听见告艰苦,只当是没想头了, 又听见给他二十两银子,喜的眉开眼笑道:“我们也知道艰难的,但只俗语说的:‘瘦死的骆驼比马还大’呢。\n","English:<|im_end|>\n","<|im_start|>assistant\n","\n","--------------------------------------------------\n","chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n","--------------------------------------------------\n","english: After a while, she no longer struggled and said, You bastard! What are you going to do with me?\n","--------------------------------------------------\n","text: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n","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","\n","Chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n","English:<|im_end|>\n","<|im_start|>assistant\n","After a while, she no longer struggled and said, You bastard! What are you going to do with me?<|im_end|>\n","--------------------------------------------------\n","prompt: You are a helpful assistant that translates Chinese to English.<|im_start|>user\n","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","\n","Chinese: 后来她不挣扎了,对我说,混蛋,你要把我怎么办。\n","English:<|im_end|>\n","<|im_start|>assistant\n","\n"]}],"source":["print_row_details(eval_dataset_v2.to_pandas(), range(len(eval_dataset_v2)))"]}],"metadata":{"accelerator":"GPU","application/vnd.databricks.v1+notebook":{"dashboards":[],"environmentMetadata":null,"language":"python","notebookMetadata":{"mostRecentlyExecutedCommandWithImplicitDF":{"commandId":-1,"dataframes":["_sqldf"]},"pythonIndentUnit":4},"notebookName":"10_eval-lf-medium-py3.11","widgets":{}},"colab":{"gpuType":"L4","provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.9"}},"nbformat":4,"nbformat_minor":0}