Skip to content

Commit

Permalink
Update ChatGPT_sentiment_analysis_benchmark.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceYanghy committed Jun 19, 2023
1 parent c4052f6 commit 7e1857f
Showing 1 changed file with 56 additions and 59 deletions.
115 changes: 56 additions & 59 deletions fingpt/FinGPT_sentiment/ChatGPT_sentiment_analysis_benchmark.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"cell_type": "code",
"execution_count": 4,
"id": "96ef6b6c",
"id": "86ae272f",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -22,7 +22,7 @@
{
"cell_type": "code",
"execution_count": 5,
"id": "e81b2a70",
"id": "8281b17a",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -33,7 +33,7 @@
{
"cell_type": "code",
"execution_count": 6,
"id": "4764933a",
"id": "3e478369",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -46,7 +46,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "4f9ecff3",
"id": "ffd69e17",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -56,16 +56,16 @@
},
{
"cell_type": "code",
"execution_count": 9,
"id": "cb09e057",
"execution_count": 16,
"id": "a93ff689",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 8,
"id": "180b467c",
"id": "b7ff4913",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -86,7 +86,7 @@
{
"cell_type": "code",
"execution_count": 10,
"id": "4a7d40e3",
"id": "610a566b",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -104,46 +104,16 @@
},
{
"cell_type": "code",
"execution_count": 11,
"id": "788fedd7",
"execution_count": 21,
"id": "935c18b1",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Downloading builder script: 100%|██████████| 6.04k/6.04k [00:00<00:00, 1.81MB/s]\n",
"Downloading metadata: 100%|████████████████| 13.7k/13.7k [00:00<00:00, 3.22MB/s]\n",
"Downloading readme: 100%|██████████████████| 8.86k/8.86k [00:00<00:00, 2.13MB/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading and preparing dataset financial_phrasebank/sentences_50agree to /Users/bruce/.cache/huggingface/datasets/financial_phrasebank/sentences_50agree/1.0.0/550bde12e6c30e2674da973a55f57edde5181d53f5a5a34c1531c53f93b7e141...\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Downloading data: 100%|██████████████████████| 682k/682k [00:00<00:00, 1.08MB/s]\n",
" \r"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Dataset financial_phrasebank downloaded and prepared to /Users/bruce/.cache/huggingface/datasets/financial_phrasebank/sentences_50agree/1.0.0/550bde12e6c30e2674da973a55f57edde5181d53f5a5a34c1531c53f93b7e141. Subsequent calls will reuse this data.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|████████████████████████████████████████████| 1/1 [00:00<00:00, 251.85it/s]"
"Found cached dataset financial_phrasebank (/Users/bruce/.cache/huggingface/datasets/financial_phrasebank/sentences_50agree/1.0.0/550bde12e6c30e2674da973a55f57edde5181d53f5a5a34c1531c53f93b7e141)\n",
"100%|████████████████████████████████████████████| 1/1 [00:00<00:00, 236.91it/s]"
]
},
{
Expand All @@ -162,13 +132,13 @@
}
],
"source": [
"senteces, labels = get_dataset()"
"sentences, labels = get_dataset()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "0318dd00",
"execution_count": 22,
"id": "a7b5395d",
"metadata": {},
"outputs": [
{
Expand All @@ -177,19 +147,19 @@
"4846"
]
},
"execution_count": 12,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(senteces)"
"len(sentences)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "51aef211",
"execution_count": 23,
"id": "7c31bc33",
"metadata": {},
"outputs": [
{
Expand All @@ -198,7 +168,7 @@
"'Human: Determine the sentiment of the financial news as negative, neutral or positive: According to Gran , the company has no plans to move all production to Russia , although that is where the company is growing . Assistant: '"
]
},
"execution_count": 14,
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -209,8 +179,8 @@
},
{
"cell_type": "code",
"execution_count": 15,
"id": "8439bfcd",
"execution_count": 24,
"id": "ff23f775",
"metadata": {},
"outputs": [
{
Expand All @@ -219,7 +189,7 @@
"1"
]
},
"execution_count": 15,
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -231,8 +201,8 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "56eb9ac4",
"execution_count": 25,
"id": "9ee1cdb5",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -241,13 +211,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "d741dfdb",
"execution_count": 26,
"id": "6879093a",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"3it [00:07, 2.38s/it]\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[26], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mtime\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m prompt, label \u001b[38;5;129;01min\u001b[39;00m tqdm(\u001b[38;5;28mzip\u001b[39m(sentences[\u001b[38;5;241m0\u001b[39m:\u001b[38;5;241m10\u001b[39m],labels)):\n\u001b[0;32m----> 3\u001b[0m \u001b[43mtime\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msleep\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 4\u001b[0m response\u001b[38;5;241m=\u001b[39mchat_with_gpt(prompt)\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnegative\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m response:\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"source": [
"import time\n",
"for prompt, label in tdqm(zip(sentences[0:10],labels)):\n",
"for prompt, label in tqdm(zip(sentences[0:10],labels)):\n",
" time.sleep(1)\n",
" response=chat_with_gpt(prompt)\n",
" \n",
Expand All @@ -260,6 +249,14 @@
" else:\n",
" preds.append(1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7ebef148",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit 7e1857f

Please sign in to comment.