UCONN

UCONN
UCONN

Prompt Engineering Exercises

Prompt Engineering Exercises

Summarizing a document - One valuable use of AI would be to summarize

a long report or document so that you can get a high level understanding of

the content without having to read through the entire document.

Let's take the latest Nvidia earnings release.

I can instruct Gemini to summarize the text from a specific link.


First, I’ll ask Gemini to find the the link I need


need link for the latest earnings release from Nvidia



Then I will get Gemini to summarize the link



SUMMARIZE THE TEXT FROM THIS LINK -

https://nvidianews.nvidia.com/news/nvidia-announces-financial-results-for-fourth-quarter-and-fiscal-2026


NVIDIA reported record-breaking financial results for the fourth quarter and

full fiscal year 2026, driven by the "exponential" growth of agentic AI

and accelerated computing.

Financial Highlights

  • Q4 Revenue: Record $68.1 billion, up 73% year-over-year and 20%

  • from the previous quarter.

  • Full-Year Revenue: Record $215.9 billion, a 65% increase from fiscal 2025.

  • Earnings per Share (EPS): * GAAP: $1.76 (up 98% YoY).

    • Non-GAAP: $1.62 (up 82% YoY).

  • Gross Margin: Remained strong at 75.0% (GAAP) for the quarter.

  • Shareholder Returns: NVIDIA returned $41.1 billion to shareholders

  • in fiscal 2026 through share repurchases and dividends.

Segment Performance

  • Data Center: The primary growth engine, reaching a record $62.3 billion

  • in Q4 revenue (up 75% YoY). This was driven by the shift to

  • AI infrastructure and the ramp-up of the Blackwell platform.

  • Gaming: Q4 revenue was $3.7 billion (up 47% YoY), supported by

  • strong Blackwell demand, though down 13% sequentially due to

  • post-holiday inventory normalization.

  • Professional Visualization: Revenue rose to $1.3 billion

  • (up 159% YoY).

  • Automotive and Robotics: Achieved record full-year revenue of

  • $2.3 billion (up 39% YoY).

Future Outlook & Strategic Moves

  • Q1 FY2027 Guidance: NVIDIA expects revenue of $78.0 billion (± 2%).

  • New Platforms: CEO Jensen Huang highlighted the arrival of the

  • Rubin platform (the successor to Blackwell), which aims to reduce AI

  • inference costs by up to 10x.

  • Partnerships: The company announced major collaborations with

  • Meta (deploying millions of GPUs), AWS, Microsoft Azure, and

  • Anthropic.

  • Policy Change: Starting in Q1 FY2027, NVIDIA will include stock-based

  • compensation in its non-GAAP financial measures.

CEO Quote: Jensen Huang stated, "The agentic AI inflection point has arrived...

Our customers are racing to invest in AI compute —

the factories powering the AI industrial revolution."


Earnings call 


Next I want to get the sentiment from the earnings call related to the press release.


Python Code


First I ask gemini to find the latest earnings transcript I want to analyze

link for the latest nvidia conference call from motley fool


Note: I need to use motley fool because they do not block API access


As a Google cloud developer I use AI to help speed up the process or debug

issues in code. I can use AI to either generate new code or change existing

code based upon parameters that I provide. Staying with the same Example, 

ask the model to provide document and paragraph level sentiment for

an earnings  call.


I set the persona 

python developer

Task 

build a program using google cloud nlp libraries to extract the document

and paragraph level sentiment scores

Input  https://www.fool.com/earnings/call-transcripts/2026/02/25/nvidia-nvda-q4-2026-earnings-call-transcript

Format 

the output should be in JSON format

Constrait

limit paragraph scores to first 10 paragraphs


As a python developer build a program using google cloud nlp libraries to

extract the document and paragraph level sentiment scores with of the

following article link -

https://www.fool.com/earnings/call-transcripts/2026/02/25/nvidia-nvda-q4-2026-earnings-call-transcript/

- the output should be in JSON format

- limit paragraph scores to first 10 paragraphs



Google will provide the code and a proper way to implement it on the cloud.


Results:


To fulfill your request, I have developed a Python solution that utilizes the

Google Cloud Natural Language API to perform sentiment analysis

on the document and the first 10 paragraphs of the Nvidia Q4 2026

earnings call transcript.


john_iacovacci1@cloudshell:~ (cloud-project-examples)$ mkdir prompt-eng

john_iacovacci1@cloudshell:~ (cloud-project-examples)$ cd prompt-eng/


john_iacovacci1@cloudshell:~/prompt-eng (cloud-project-examples)$

gcloud services enable language.googleapis.com


Note: Use your JSON key not mine


john_iacovacci1@cloudshell:~/prompt-eng (cloud-project-examples)$

export GOOGLE_APPLICATION_CREDENTIALS="/home/john_iacovacci1/cloud-project-examples-316c375c6892.json"


john_iacovacci1@cloudshell:~/prompt-eng (cloud-project-examples)$

pip install google-cloud-language beautifulsoup4 requests


Python code from gemini - sent_scores.py


========================================================

import json

from google.cloud import language_v1

import requests

from bs4 import BeautifulSoup


def analyze_sentiment(text_content):

    """Performs sentiment analysis using Google Cloud NLP."""

    client = language_v1.LanguageServiceClient()

   

    document = language_v1.Document(

        content=text_content,

        type_=language_v1.Document.Type.PLAIN_TEXT

    )

   

    # Extract Document and Sentence level sentiment

    response = client.analyze_sentiment(request={'document': document})

    return response


def get_transcript_paragraphs(url, limit=10):

    """Scrapes the transcript and extracts the first N paragraphs."""

    headers = {'User-Agent': 'Mozilla/5.0'}

    page = requests.get(url, headers=headers)

    soup = BeautifulSoup(page.content, 'html.parser')

   

    # Finding transcript text - typically within 'article-body' or specific divs

    # This selector is optimized for the Motley Fool layout

    content = soup.find('div', class_='article-body')

    paragraphs = [p.get_text().strip() for p in content.find_all('p') if p.get_text().strip()]

   

    return paragraphs[:limit]


def main():

    url = "https://www.fool.com/earnings/call-transcripts/2026/02/25/nvidia-nvda-q4-2026-earnings-call-transcript/"

   

    # 1. Extract content

    paragraphs = get_transcript_paragraphs(url, limit=10)

    full_text = "\n".join(paragraphs)

   

    # 2. Call Google Cloud NLP

    # Analyze the whole document (first 10 paragraphs combined)

    doc_response = analyze_sentiment(full_text)

   

    output = {

        "document_sentiment": {

            "score": round(doc_response.document_sentiment.score, 2),

            "magnitude": round(doc_response.document_sentiment.magnitude, 2)

        },

        "paragraph_sentiments": []

    }

   

    # 3. Analyze each paragraph individually

    for i, para in enumerate(paragraphs):

        para_response = analyze_sentiment(para)

        output["paragraph_sentiments"].append({

            "paragraph_index": i + 1,

            "text_snippet": para[:100] + "...",

            "score": round(para_response.document_sentiment.score, 2),

            "magnitude": round(para_response.document_sentiment.magnitude, 2)

        })

   

    # 4. Export to JSON

    print(json.dumps(output, indent=4))


if __name__ == "__main__":

    main()

========================================================


Results:


john_iacovacci1@cloudshell:~/prompt-eng (cloud-project-examples)$ python3 sent_scores.py

{

    "document_sentiment": {

        "score": 0.1,

        "magnitude": 13.3

    },

    "paragraph_sentiments": [

        {

            "paragraph_index": 1,

            "text_snippet": "Image source: The Motley Fool....",

            "score": 0.1,

            "magnitude": 0.1

        },

        {

            "paragraph_index": 2,

            "text_snippet": "Wednesday, Feb. 25, 2026 at 5 p.m. ET...",

            "score": 0.0,

            "magnitude": 0.0

        },

        {

            "paragraph_index": 3,

            "text_snippet": "Need a quote from a Motley Fool analyst? Email [email\u00a0protected]...",

            "score": 0.0,

            "magnitude": 0.2

        },

        {

            "paragraph_index": 4,

            "text_snippet": "The call revealed outsized growth in Data Center and Networking revenue underpinned by expanded cust...",

            "score": 0.5,

            "magnitude": 2.0

        },

        {

            "paragraph_index": 5,

            "text_snippet": "Toshiya Hari: Good afternoon, everyone, and welcome to NVIDIA Corporation's conference call for 2026...",

            "score": -0.1,

            "magnitude": 1.8

        },

        {

            "paragraph_index": 6,

            "text_snippet": "For a discussion of factors that could affect our future financial results and business, please refe...",

            "score": -0.1,

            "magnitude": 1.0

        },

        {

            "paragraph_index": 7,

            "text_snippet": "Colette Kress: Thanks, Toshiya. We delivered another outstanding quarter, with record revenue, opera...",

            "score": 0.5,

            "magnitude": 3.0

        },

        {

            "paragraph_index": 8,

            "text_snippet": "Agentic and physical AI applications built on increasingly smarter and multimodal models are beginni...",

            "score": 0.4,

            "magnitude": 0.4

        },

        {

            "paragraph_index": 9,

            "text_snippet": "On a full-year basis, Data Center generated revenue of $194,000,000,000, up 68% year over year. We h...",

            "score": 0.0,

            "magnitude": 1.8

        },

        {

            "paragraph_index": 10,

            "text_snippet": "SemiAnalysis declared NVIDIA Corporation inference king as recent results from InferenceX reinforced...",

            "score": 0.7,

            "magnitude": 2.9

        }

    ]

}

john_iacovacci1@cloudshell:~/prompt-eng (cloud-project-examples)$ 


No comments:

Post a Comment

Assignment 10 due before grading

  Pick any stock and send me the linear regression chart for that stock. https://uconnstamfordslp.blogspot.com/p/machine-learning-exercise.h...