{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "authorship_tag": "ABX9TyNs+mL3FuFwJixqlz34eHXX", "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "" ] }, { "cell_type": "code", "source": [ "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns" ], "metadata": { "id": "-I0iwu0lGx37" }, "execution_count": 23, "outputs": [] }, { "cell_type": "markdown", "source": [ "# transformer" ], "metadata": { "id": "tYWE2ItALNIr" } }, { "cell_type": "code", "source": [ "from transformers import pipeline\n", "\n", "def sentiment_analysis1(text):\n", " # Load the sentiment analysis pipeline with the BERT model\n", " classifier = pipeline(\"sentiment-analysis\", model=\"nlptown/bert-base-multilingual-uncased-sentiment\")\n", "\n", " # Perform sentiment analysis\n", " result = classifier(text)\n", " return result\n", "\n", "# Example usage:\n", "financial_news = \"The stock market experienced a significant downturn today amid concerns over inflation.\"\n", "result = sentiment_analysis1(financial_news)\n", "print(\"Sentiment Analysis Result:\", result)\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "JNfVZxzuGx-y", "outputId": "f73c6293-4a01-4abb-bcb4-8c370eaf40aa" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Sentiment Analysis Result: [{'label': '2 stars', 'score': 0.47418859601020813}]\n" ] } ] }, { "cell_type": "markdown", "source": [ "Label Interpretation: The label '2 stars' suggests that the sentiment expressed in the text you analyzed is generally negative. In sentiment rating systems where labels are presented as stars (often ranging from 1 star to 5 stars), a rating of 2 stars typically denotes dissatisfaction or a negative view. It implies that the text likely contains criticisms or less favorable opinions.\n", "\n", "Score Interpretation: The confidence score of approximately 0.474 (or 47.4%) associated with this label indicates a moderate level of confidence in the assessment. This isn't a very high confidence level, which might suggest that the sentiment expressed in the text was not overwhelmingly clear or that the text contained mixed sentiments, making it harder for the model to assign a more definitive sentiment rating with higher confidence.\n", "\n", "Considerations:" ], "metadata": { "id": "fzvz6mGYQC8G" } }, { "cell_type": "code", "source": [ "data = {\n", " 'headline': [\n", " \"Apple's revenue exceeds expectations with a strong quarterly report\",\n", " \"Major banks face scrutiny as financial regulations tighten\",\n", " \"Tesla's new factory investment raises concerns over debt levels\"\n", " ]\n", "}\n", "\n", "df = pd.DataFrame(data)\n", "df" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 143 }, "id": "7d30p39CGyBq", "outputId": "20668295-f231-4bc7-fb81-3bcb4947bef1" }, "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " headline\n", "0 Apple's revenue exceeds expectations with a st...\n", "1 Major banks face scrutiny as financial regulat...\n", "2 Tesla's new factory investment raises concerns..." ], "text/html": [ "\n", "
\n", " | headline | \n", "
---|---|
0 | \n", "Apple's revenue exceeds expectations with a st... | \n", "
1 | \n", "Major banks face scrutiny as financial regulat... | \n", "
2 | \n", "Tesla's new factory investment raises concerns... | \n", "