Trend Detection and Analysis with the AiConfig

trend-detection-and-analysis-with-the-aiconfig

Introduction

In this blog post, you will be guided with the well planned use-case on Trend Detection, and its analysis.

The “Trend” data extraction or mining itself is part of the data mining process, where one can adapt to understand the trends within the data. When it comes to the trend analysis, we are going to consider the upward, downward or moderate trends etc. All these trends will be really useful for the business to make the informed decisions.

Background

Trend Detection and its analysis is one of the most interesting and excited topic in the area of machine learning. Until recently with the introduction of the large language models, it has been the major challenge in the area of machine learning as it required the model to have the domain knowledge or understanding.

In addition, there was a heavy NLP work involved in performing the trend data extraction. Among which the detailed analysis or a plan is a far reach.

However, the good news with the large language models are, it’s really straightforward for one to accomplish. That’s the beauty of the crafted prompts for trend detection, and it’s analysis and formation of the detailed plan.

Hands-on

For the demonstration purposes, You will be shown the end to end execution of the Trend detection, its analysis or plan formation by making use of the AiConfig.

One of the primary reasons for using the AiConfig is its ease to use and highly configurable nature of prompts and its configurations, including the configurable LLM usages etc.

Also, the other biggest advantage that you will be seeing is with the prompt chaining. Please refer to this blog post to understand more about the Prompt Chaining

Here’s the plan. At high-level, we are going to have a two-step based prompt instruction for performing the trend detection, and it’s analysis with the detailed plan.

Please find the Trend Detection and Analysis/Plan AiConfig. You can copy and save it on your local.

{
  "name": "Trend Detection",
  "schema_version": "latest",
  "metadata": {
    "models": {
      "gpt-3.5-turbo": {
        "model": "gpt-3.5-turbo",
        "top_p": 1,
        "temperature": 0,
        "system_prompt": "Detect and analyze emerging trends or patterns",
        "presence_penalty": 0,
        "frequency_penalty": 0
      }
    },
    "parameters": {}
  },
  "prompts": [
    {
      "name": "content",
      "input": "{{content}}nn1. Identify and list any emerging trends, patterns, or significant changes in the data. These trends could be related to market trends, consumer behavior, social media trends, or any other relevant domain-specific trends.nn2. Describe the nature of each detected trend, including whether it is an upward or downward trend, its potential impact, and any contributing factors or drivers.nn3. If the data is time-series data, provide a historical perspective by highlighting how the trend has evolved over time and when it started.nn4. Consider the context and potential implications of each detected trend. What might these trends mean for businesses, industries, or society as a whole?nn5. If applicable, suggest actions or recommendations based on the identified trends. What steps can organizations or individuals take to respond to these trends?nnEnsure that your trend detection response is insightful, well-supported by the data, and provides a clear understanding of the detected trends.nn**Example Data:**nn{n    "TrendDetection": [n        {n            "Trend": "",n            "Nature": "",n            "Impact": "",n            "Context": "",n            "Recommendation": ""n        }n    ]n}nnnDo not respond with your own suggestions or recommendations or feedback.n",
      "metadata": {
        "model": {
          "name": "gpt-3.5-turbo",
          "settings": {}
        },
        "parameters": {
          "content": "I recently purchased this smartphone, and I'm blown away by its performance and camera quality. The battery life is excellent, and the sleek design adds a touch of elegance. Definitely worth the investment"
        },
        "remember_chat_context": true
      }
    },
    {
      "name": "detailed_analysis",
      "input": "Based on the trend detection response {{trend_detection_prompt.output}} Consider all the trends with the Significant Impact, prepare a summary with the details on why that trend is significant. Mention with the pros and cons with the recommendations as specified in the JSON output.",
      "metadata": {
        "model": {
          "name": "gpt-3.5-turbo",
          "settings": {}
        },
        "parameters": {
          "content": "I recently purchased this smartphone, and I'm blown away by its performance and camera quality. The battery life is excellent, and the sleek design adds a touch of elegance. Definitely worth the investment"
        },
        "remember_chat_context": true
      }
    },
    {
      "name": "detailed_plan",
      "input": "Based on the trend detection response {{trend_detection_prompt.output}} Consider all the trends with the Significant Impact, prepare a nice detailed plan and layout on how to tackle the demanding trends. Provide some solutions with the examples.",
      "metadata": {
        "model": {
          "name": "gpt-3.5-turbo",
          "settings": {}
        },
        "parameters": {
          "content": "I recently purchased this smartphone, and I'm blown away by its performance and camera quality. The battery life is excellent, and the sleek design adds a touch of elegance. Definitely worth the investment"
        },
        "remember_chat_context": true
      }
    }
  ]
}

You need to do the following steps and tweak the prompts based on your requirements. Especially the context or the content for which you wish to perform the trend analysis. There are two ways with which you could execute the AiConfig. Here is the first option of using the config and load it up to LastMileAI and perform the cell by cell execution from top to bottom.

  1. Use the above Trend Detection AiConfig.
  2. Login to LastMileAI
  3. Navigate to the Workbooks and then do the following to upload the aiconfig file.

AiConfigCreate

Let’s go one step at a time to understand the over all workflow.

Following is the initial “Trend” detection CORE prompt logic, which is responsible for analysis and extracting the trends in JSON format. We shall call this cell as trend_detection_prompt. The output of this cell will be utilized further for more detailed trend analysis and planning purposes.

TrendDetection1

You will see how to configure the content of your analysis. Please use the parameterized cell for your trend detection and analysis.

TrendDetection2

Here’s the output of the first cell.

TrendDetection3

Let’s see how the “Trend” detailed analysis cell, where the more detailed analysis is being performed. Notice below the usage of trend_detection_prompt cell output, which is considered as an input for this purpose.

TrendDetection4

Let’s see how the “Trend” detailed planning is performed. Notice below the usage of trend_detection_prompt cell output, which is considered as an input for this purpose.

TrendDetection5

If you are wondering how to programmatically execute the AiConfig, then you are on the right track. Let me walk you through the process on how to accomplish. First, please make sure to copy the above-mentioned Trend Detection Aiconfig.

Here’s the code snippet for initializing the AiConfig. In here, we are going to load the config, set the parameter, save it for further analysis. Alternatively, you could also resolve it on the fly.

%pip install python-aiconfig

"""**Note - Please make sure to restart the session on Google Colab**"""

from aiconfig import AIConfigRuntime

# Load the aiconfig.
config = AIConfigRuntime.load('Trend Detection_aiconfig.json')

# Set a global parameter
config.set_parameter("content", "I recently purchased this smartphone, and I'm blown away by its performance and camera quality. The battery life is excellent, and the sleek design adds a touch of elegance. Definitely worth the investment")

config.save()

Set the OpenAI Key if you are making use of the OpenAI LLM. Here I am considering the Google Colab usages. However, it can be easily tweaked as per your needs.

import os
import openai
from google.colab import userdata

openai.api_key = userdata.get('openai_key')

Now comes the most interesting part of the AiConfig execution for “Trend” detailed analysis. Here’s the code snippet.

"""# **Trend Detailed Analysis**"""

from aiconfig import AIConfigRuntime
config = AIConfigRuntime.load('/content/Trend Detection_aiconfig.json')
result = await config.run("detailed_analysis")

# Show output
print(config.get_output_text("detailed_analysis"))

TrendDetection6

Now comes the yet another interesting part of the “Trend” detailed planning. Here’s the code snippet.

"""# **Trend Deatiled Plan**"""

from aiconfig import AIConfigRuntime
config = AIConfigRuntime.load('/content/Trend Detection_aiconfig.json')
result = await config.run("detailed_plan")

# Show output
print(config.get_output_text("detailed_plan"))

TrendDetection8

Conclusion

Hope you have learned the art of prompt engineering for the “Trend” data mining. Also, the usage of AiConfig for configuring and executing the prompt based Apps with ease.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
deep-dive:-engineering-artificial-intelligence-for-trust

Deep dive: Engineering artificial intelligence for trust

Next Post
how-to-effectively-disagree-with-superiors-at-work

How to effectively disagree with superiors at work

Related Posts