<|im_end|>We are asked: \"what was the percentage increase in the employee contribution from 2002 to 2003?\" Let's check the provided context carefully. The context is a snippet from a financial statement notes. It says: \"retirement plan 2014the company has a 401 (k) plan covering substantially all employees who meet certain age and employment requirements . under the plan , the company matching contribution for periods prior to june 30, 2004 was 35% (35%) up to a maximum 5% (5%) of a participant's contributions. effective july 1, 2004, the plan was amended to increase the company match to 50% (50%) up to a maximum 6% (6%) of a participant's contributions. the company contributed approximately $533,000, $825,000 and $979,000 to the plan for the years ended December 31, 2004, 2003 and 2002, respectively.\"\n",
"\n",
"We must compute: \"what was the percentage increase in the employee contribution from 2002 to 2003?\" Wait, caution: The question says: \"what was the percentage increase in the employee contribution from 2002 to 2003?\" However, careful reading: \"the company contributed approximately $533,000, $825,000 and $979,000 to the plan for the years ended December 31, 2004, 2003, and 2002, respectively.\" The question: \"percentage increase in the employee contribution\" But these numbers are the company's contributions to the plan? Wait, not exactly, they are the company's contributions to the 401(k) plan. However, the question says \"employee contribution.\" But the text says \"the company contributed\" amounts. Actually, check: The text says \"the company contributed approximately $533,000, $825,000 and $979,000 to the plan for the years ended December 31, 2004, 2003, and 2002, respectively.\" That indicates the amounts that the company contributed. But the question says \"employee contribution.\" Possibly a misprint? Wait, maybe \"employee contribution\" means the employees' contributions? But no, the amounts are clearly stated as \"company contributed\" amounts.\n",
"\n",
"Let's re-read the retirement plan note carefully:\n",
"\n",
"\"retirement plan 2014the company has a 401 (k) plan covering substantially all employees who meet certain age and employment requirements . under the plan , the company matching contribution for periods prior to june 30, 2004 was 35% (35%) up to a maximum 5% (5%) of a participant's contributions. effective july 1, 2004, the plan was amended to increase the company match to 50% (50%) up to a maximum 6% (6%) of a participant's contributions. the company contributed approximately $533,000, $825,000 and $979,000 to the plan for the years ended December 31, 2004, 2003 and 2002, respectively.\"\n",
"\n",
"So the amounts are \"company contributions\" to the plan. But then the question asks: \"what was the percentage increase in the employee contribution from 2002 to 2003?\" Possibly the percentages refer to the company match percentages? Possibly the question means \"what was the percentage increase in the company match percentage from 2002 to 2003?\" But wait, the text: \"the company matching contribution for periods prior to june 30, 2004 was 35% up to a maximum 5% of a participant's contributions. effective july 1, 2004, the plan was amended to increase the company match to 50% up to a maximum 6% of a participant's contributions.\" But then the question: \"what was the percentage increase in the employee contribution from 2002 to 2003\" I see: The given numbers: For 2002: $979,000, for 2003: $825,000, for 2004: $533,000. The question asks: \"employee contribution\" but those amounts are company contributions. Possibly there is a misinterpretation: Actually the question may be asking: \"what was the percentage increase in the employee contribution\" but the text says \"the company contributed approximately $533,000, $825,000 and $979,000 to the plan for the years ended December 31, 2004, 2003 and 2002, respectively.\" So which one is the employee's contribution? Alternatively, the note says \"employee\" may refer to the company's matching contribution? Actually, re-read: \"under the plan, the company matching contribution for periods prior to june 30, 2004 was 35% (35%) up to a maximum 5% (5%) of a participant's contributions.\" That is the company match. Then: \"effective july 1, 2004, the plan was amended to increase the company match to 50% (50%) up to a maximum 6% (6%) of a participant's contributions.\" So these are percentages of the employee's contributions. But then later the note says \"the company contributed approximately $533,000, $825,000 and $979,000 to the plan for the years ended December 31, 2004, 2003 and 2002, respectively.\" So maybe the question \"what was the percentage increase in the employee contribution\" actually might refer to the company's matching contribution as a percentage of the employee contributions, i.e. from 5% to 6%? But then the question \"from 2002 to 2003\" doesn't match because the plan change effective date is july 1, 2004, and that's not relevant to the\n"
]
}
],
"source": [
"question = dataset[20]['Open-ended Verifiable Question']\n",
"inputs = tokenizer(\n",
" [inference_prompt_style.format(question, \"\") + tokenizer.eos_token],\n",
" return_tensors=\"pt\"\n",
").to(\"cuda\")\n",
"\n",
"outputs = model.generate(\n",
" input_ids=inputs.input_ids,\n",
" attention_mask=inputs.attention_mask,\n",
" max_new_tokens=1200,\n",
" eos_token_id=tokenizer.eos_token_id,\n",
" use_cache=True,\n",
")\n",
"response = tokenizer.batch_decode(outputs)\n",
"print(response[0].split(\"<|im_start|>assistant<|im_sep|>\")[1])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setting up the model"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"from peft import LoraConfig, get_peft_model\n",
"\n",
"# LoRA config\n",
"peft_config = LoraConfig(\n",
" lora_alpha=16, # Scaling factor for LoRA\n",
" lora_dropout=0.05, # Add slight dropout for regularization\n",
" r=64, # Rank of the LoRA update matrices\n",
" bias=\"none\", # No bias reparameterization\n",
" task_type=\"CAUSAL_LM\", # Task type: Causal Language Modeling\n",
" target_modules=[\n",
" \"q_proj\",\n",
" \"k_proj\",\n",
" \"v_proj\",\n",
" \"o_proj\",\n",
" \"gate_proj\",\n",
" \"up_proj\",\n",
" \"down_proj\",\n",
" ], # Target modules for LoRA\n",
")\n",
"\n",
"model = get_peft_model(model, peft_config)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "50fed52d9fce44e5a7f7586b13700d83",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Converting train dataset to ChatML: 0%| | 0/1000 [00:00, ? examples/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bbe465aef9164fda938c16123563e185",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Adding EOS to train dataset: 0%| | 0/1000 [00:00, ? examples/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a302c537fdab496aad69b7f42915cacc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Tokenizing train dataset: 0%| | 0/1000 [00:00, ? examples/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3735f907a3a84669b38856d8e8e62a71",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Truncating train dataset: 0%| | 0/1000 [00:00, ? examples/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"No label_names provided for model class `PeftModelForCausalLM`. Since `PeftModel` hides base models input arguments, if label_names is not given, label_names can't be set automatically within `Trainer`. Note that empty label_names list will be used instead.\n"
]
}
],
"source": [
"from trl import SFTTrainer\n",
"from transformers import TrainingArguments\n",
"\n",
"\n",
"# Training Arguments\n",
"training_arguments = TrainingArguments(\n",
" output_dir=\"output\",\n",
" per_device_train_batch_size=1,\n",
" per_device_eval_batch_size=1,\n",
" gradient_accumulation_steps=2,\n",
" optim=\"paged_adamw_32bit\",\n",
" num_train_epochs=1,\n",
" logging_steps=0.2,\n",
" warmup_steps=10,\n",
" logging_strategy=\"steps\",\n",
" learning_rate=2e-4,\n",
" fp16=False,\n",
" bf16=False,\n",
" group_by_length=True,\n",
" report_to=\"none\"\n",
")\n",
"\n",
"# Initialize the Trainer\n",
"trainer = SFTTrainer(\n",
" model=model,\n",
" args=training_arguments,\n",
" train_dataset=dataset,\n",
" peft_config=peft_config,\n",
" data_collator=data_collator,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Model Training"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" \n",
"
\n",
" [500/500 07:20, Epoch 1/1]\n",
"
\n",
" \n",
" \n",
" \n",
" Step | \n",
" Training Loss | \n",
"
\n",
" \n",
" \n",
" \n",
" 100 | \n",
" 1.452900 | \n",
"
\n",
" \n",
" 200 | \n",
" 1.366900 | \n",
"
\n",
" \n",
" 300 | \n",
" 1.285200 | \n",
"
\n",
" \n",
" 400 | \n",
" 1.324600 | \n",
"
\n",
" \n",
" 500 | \n",
" 1.345900 | \n",
"
\n",
" \n",
"
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"TrainOutput(global_step=500, training_loss=1.3550911560058594, metrics={'train_runtime': 442.2688, 'train_samples_per_second': 2.261, 'train_steps_per_second': 1.131, 'total_flos': 8.592683944836096e+16, 'train_loss': 1.3550911560058594})"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import gc, torch\n",
"gc.collect()\n",
"torch.cuda.empty_cache()\n",
"model.config.use_cache = False\n",
"trainer.train()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Model inference after fine-tuning"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<|im_end|>First, I need to figure out what the employee contributions were for the years 2002 and 2003. Okay, looking at the numbers, I see that the company contributed $979,000 in 2002 and $825,000 in 2003. So, those are my two key figures. \n",
"\n",
"Next, I'll calculate the change in the contribution amount. To find this, I subtract the 2003 contribution from the 2002 contribution. Let me do that: $979,000 minus $825,000 equals $154,000. So, there's a decrease of $154,000 from 2002 to 2003.\n",
"\n",
"Now, I need to understand what this decrease means in terms of percentage. Percentage change is usually calculated by taking the change, dividing it by the original number, and then multiplying by 100. So, I'll take that $154,000 change and divide it by the 2002 amount, $979,000. \n",
"\n",
"Let me do that math: $154,000 divided by $979,000... Hmm, this gives me a value of approximately 0.1573. \n",
"\n",
"Finally, I multiply that by 100 to convert it to a percentage. That gives me about 15.73%. \n",
"\n",
"Oh, wait, let me make sure everything makes sense. I calculated the change in contributions correctly by subtracting the 2003 amount from the 2002 amount. Then I used the original amount from 2002 as the base for the percentage calculation. \n",
"\n",
"Yes, that all seems right. So, the employee contribution decreased by approximately 15.73% from 2002 to 2003.The percentage decrease in the employee contribution from 2002 to 2003 was approximately 15.73%.<|im_end|>\n"
]
}
],
"source": [
"question = dataset[20]['Open-ended Verifiable Question']\n",
"inputs = tokenizer(\n",
" [inference_prompt_style.format(question, \"\") + tokenizer.eos_token],\n",
" return_tensors=\"pt\"\n",
").to(\"cuda\")\n",
"\n",
"outputs = model.generate(\n",
" input_ids=inputs.input_ids,\n",
" attention_mask=inputs.attention_mask,\n",
" max_new_tokens=1200,\n",
" eos_token_id=tokenizer.eos_token_id,\n",
" use_cache=True,\n",
")\n",
"response = tokenizer.batch_decode(outputs)\n",
"print(response[0].split(\"<|im_start|>assistant<|im_sep|>\")[1])"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<|im_end|>Okay, let's figure out how much of the long-term debt should be considered current liabilities. So, the total long-term debt at the end of 2011 was $1859 million. Now, I remember that there's some information about the timing of cash payments related to this debt. In particular, there's a chunk of $29 million that is due in 2012. Hmm, that's the part that's likely to become a current liability. \n",
"\n",
"Let’s check the table again to make sure. It says total long-term debt is $1859 million, and the breakdown of estimated cash payments includes $29 million for 2012. Yep, that seems to align. So, this $29 million should be classified as a current liability because it's due within the next year. \n",
"\n",
"But wait, let me double-check. The table is pretty straightforward: long-term debt is $1859 million and the breakdown clearly shows $29 million due in 2012. So, that $29 million is the part that should be on the current liabilities section of the balance sheet. \n",
"\n",
"Alright, so I'm confident that the portion of the long-term debt that's included in current liabilities as of December 31, 2011, is $29 million. That's it!The portion of the long-term debt included in the current liabilities on the balance sheet as of December 31, 2011, is $29 million. This $29 million represents the amount of debt due within the next year, making it a current liability.<|im_end|>\n"
]
}
],
"source": [
"question = dataset[200]['Open-ended Verifiable Question']\n",
"inputs = tokenizer(\n",
" [inference_prompt_style.format(question, \"\") + tokenizer.eos_token],\n",
" return_tensors=\"pt\"\n",
").to(\"cuda\")\n",
"\n",
"outputs = model.generate(\n",
" input_ids=inputs.input_ids,\n",
" attention_mask=inputs.attention_mask,\n",
" max_new_tokens=1200,\n",
" eos_token_id=tokenizer.eos_token_id,\n",
" use_cache=True,\n",
")\n",
"response = tokenizer.batch_decode(outputs)\n",
"print(response[0].split(\"<|im_start|>assistant<|im_sep|>\")[1])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Saving the model"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "353b85ce8ef84ff1980867ff5547abc0",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Uploading...: 0%| | 0.00/341M [00:00, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"No files have been modified since last commit. Skipping to prevent empty commit.\n"
]
},
{
"data": {
"text/plain": [
"CommitInfo(commit_url='https://huggingface.co/kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT/commit/a18b837a05dc0a83729c7f0bab1a8e39a91b7774', commit_message='Upload tokenizer', commit_description='', oid='a18b837a05dc0a83729c7f0bab1a8e39a91b7774', pr_url=None, repo_url=RepoUrl('https://huggingface.co/kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT', endpoint='https://huggingface.co', repo_type='model', repo_id='kingabzpro/Phi-4-Reasoning-Plus-FinQA-COT'), pr_revision=None, pr_num=None)"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"new_model_name = \"Phi-4-Reasoning-Plus-FinQA-COT\"\n",
"model.push_to_hub(new_model_name)\n",
"tokenizer.push_to_hub(new_model_name)"
]
}
],
"metadata": {
"kaggle": {
"accelerator": "nvidiaTeslaT4",
"dataSources": [
{
"modelId": 322000,
"modelInstanceId": 301517,
"sourceId": 363139,
"sourceType": "modelInstanceVersion"
}
],
"dockerImageVersionId": 31011,
"isGpuEnabled": true,
"isInternetEnabled": true,
"language": "python",
"sourceType": "notebook"
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"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.11"
}
},
"nbformat": 4,
"nbformat_minor": 4
}