×

Let’s explore generating topic names for news articles using a generative model, specifically, Azure OpenAI.

Topic generation is a powerful application of NLP that involves creating relevant and coherent content based on a given prompt. In the context of Azure OpenAI prompts, the ability to generate topics is demonstrated using a news headline classification example.

In this code snippet, the task is to categorize a news headline into one of the predefined categories, which are Business, Tech, Politics, Sport, and Entertainment. The news headline, provided as input, is “Trump is ready to contest in Nov 2024 elections.” The code uses the Azure OpenAI API to generate a response that predicts the most appropriate category for the given headline.

The completion engine is configured with specific parameters, such as temperature, max tokens, and penalties for frequency and presence. After generating the response, the code extracts and prints the predicted category from the output.

This example showcases how Azure OpenAI prompts can be utilized for the automatic categorization of news headlines, demonstrating the versatility and effectiveness of NLP in topic-generation tasks:
news_headline=”
Label the following news headline into 1 of the following categories: Business, Tech, Politics, Sport, Entertainment\n\n Headline 1: Trump is ready to contest in nov 2024 elections\nCategory:
“,
response = openai.Completion.create(
    engine=model_deployment_name,
    prompt= news_headline,
    temperature=0,
    max_tokens=118,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0,
    stop=None)
index_of_newline=response.choice[0].text.find(‘\n’)
print(‘category:’,response.choices[0].text[:index_of_newline])

Here’s the output:
category: Politics

Leave a Reply

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

Related Posts

Example of video data labeling using k-means clustering with a color histogram – Exploring Video Data

Let us see example code for performing k-means clustering on video data using the open source scikit-learn Python package and the Kinetics...

Read out all

Frame visualization – Exploring Video Data

We create a line plot to visualize the frame intensities over the frame indices. This helps us understand the variations in intensity...

Read out all

Appearance and shape descriptors – Exploring Video Data

Extract features based on object appearance and shape characteristics. Examples include Hu Moments, Zernike Moments, and Haralick texture features. Appearance and shape...

Read out all

Optical flow features – Exploring Video Data

We will extract features based on the optical flow between consecutive frames. Optical flow captures the movement of objects in video. Libraries...

Read out all

Extracting features from video frames – Exploring Video Data

Another useful technique for the EDA of video data is to extract features from each frame and analyze them. Features are measurements...

Read out all

Loading video data using cv2 – Exploring Video Data

Exploratory Data Analysis (EDA) is an important step in any data analysis process. It helps you understand your data, identify patterns and...

Read out all