Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 11

LLM for Trend Ranking and Hype Filtering

Recommended resources

Hello! Welcome to the next lesson in our journey to build an automated content creation system.

In the last lesson, we built the quantitative engine of our trend detector. By analyzing topic frequency and velocity, your script can now flag topics that are gaining momentum. However, it operates on numbers alone. It can tell us that a topic is spiking, but not why or if it's even relevant to our goals.

Today, we will address this by adding a crucial layer of qualitative analysis. Our learning outcome is to use an LLM to rank trends by relevance and filter out short-lived hype. We'll transform the LLM from a generator into a judge, creating a sophisticated filter that ensures our system focuses only on meaningful, substantive trends in the programming world. This step is what elevates our pipeline from a simple data aggregator to an intelligent content strategist.

From Signal to Substance: The Need for an LLM Judge

A spike in discussion could be about a groundbreaking new database technology, or it could be about a humorous programming meme that's going viral. Both are "trending," but only one is suitable for the kind of thought-leadership content you aim to create. We need a way to distinguish between them.

Manually reviewing each trend is not scalable and defeats the purpose of our automation goal. This is where we can leverage an LLM's ability to understand context and nuance.

To understand the core principles of using an LLM for evaluation, let's watch a segment from IBM Technology.

LLM as a Judge: Scaling AI Evaluation Strategies

This video, 'LLM as a Judge: Scaling AI Evaluation Strategies', provides an excellent overview of the techniques we'll be using.

Please watch from the beginning until 2:30. Focus on these two key concepts: The Problem: The introduction (0:00 - 0:38) sets up why manual labeling is inefficient and how an 'LLM as a judge' can help. Evaluation Strategies: The video then explains two methods: Direct Assessment (using a rubric) and Pairwise Comparison. For our task, we will be using Direct Assessment, so pay close attention to that part.

As the video explains, Direct Assessment is our method of choice. We will design a rubric and ask the LLM to score each potential trend against it.


Designing Our Evaluation Rubric

A good judge needs clear laws. A good LLM judge needs a clear rubric. Our rubric must capture two critical dimensions: relevance and substance.

1. Relevance

This is straightforward. We need to check if a trend is aligned with our target domain.

  • Question: Is this topic directly related to software engineering, programming, data engineering, or AI development?
  • Scale: We can use a simple numerical scale, like 1 (not relevant) to 5 (highly relevant).

2. Substance (Filtering Hype)

This is more nuanced. How do we programmatically separate a durable technological shift from fleeting hype? We can use the well-known Gartner Hype Cycle as a mental model for our LLM.

Gartner Hype Cycle for Generative AI, 2024
Gartner's Hype Cycle provides a framework for understanding the maturity of new technologies. We want our LLM to identify trends that are either at the 'Innovation Trigger' or on the 'Slope of Enlightenment', while being cautious of those at the 'Peak of Inflated Expectations'.

Our substance criteria will be a composite of:

  • Maturity/Hype: Where would this topic fall on the Hype Cycle?
  • Impact: Does this represent a new tool, technique, or paradigm with the potential to change how developers work?
  • Source Quality: Are the articles discussing this topic from research papers (like ArXiv), reputable engineering blogs, and official documentation, or primarily from social media and forums?

By combining these criteria into a structured prompt, we can ask the LLM to provide a nuanced score instead of a simple yes/no.

Prompting Strategies for Relevance Generation with LLMs
As this image illustrates, moving from a binary 'Yes/No' to a 'Rating scale' allows for a much more granular and useful evaluation. We will design our prompt to output a structured JSON object with scores for each criterion.

A Real-World Analogy: Filtering at Indeed

The task of filtering "good" items from a large pool of candidates is a common challenge in industry. The approach we're taking is similar to how major tech companies refine their recommendation systems.

Recsys Keynote: Improving Recommendation Systems & Search in the Age of LLMs - Eugene Yan, Amazon

In this keynote from AI Engineer, Eugene Yan of Amazon discusses how Indeed tackled a similar problem: filtering out bad job recommendations. This provides a fantastic industrial-strength example of our goal.

Watch the section covering the Indeed case study (6:14 - 10:34). Notice the parallel: they used LLMs to filter out 'bad' recommendations to improve user trust and engagement. We are using an LLM to filter out 'bad' (irrelevant, hype-y) trends to improve our content quality.

The key takeaway from Indeed's story is that quality trumps quantity. By intelligently filtering out the noise, they improved their core metrics. Similarly, by filtering out irrelevant trends, we will increase the quality and relevance of our final content, making our system far more effective.


Activity: Implementing the Trend Ranker in TypeScript

Now, let's put this into practice. We'll write a TypeScript function that takes the raw data for a trending topic (i.e., the content of the articles within that cluster) and uses an LLM to score it based on our rubric.

This implementation will draw heavily from the patterns in the Firecrawl blog post you have access to, which uses TypeScript, Together AI, and Zod for structured output.

Building a Trend Detection System with AI in TypeScript

Before we code, let's review the relevant sections of the Firecrawl article 'Building a Trend Detection System with AI in TypeScript'. It provides a perfect template for what we're about to build.

Please focus on these two parts of the article: 'Synthesizing scraped contents into a summary': This section shows how to initialize an LLM client, define a Zod schema for the expected JSON output, and structure a prompt to enforce that output format. This is the exact pattern we will follow. 'Next Steps -> Enhanced Analysis': This small point reinforces that customizing AI prompts for different types of analysis is a key part of extending the system—which is exactly what we are doing now.

Implementation Plan:

  1. Input: The function will receive the combined text content of all articles belonging to a single trending topic identified in the previous lesson.
  2. Schema Definition (Zod): We'll define a Zod schema that describes our desired JSON output. This ensures the LLM's response is type-safe and predictable.
  3. Prompt Engineering: We will craft a detailed system prompt that instructs the LLM to act as an expert tech analyst. The prompt will include our full evaluation rubric.
  4. LLM Call: We will send the topic content and the prompt to an LLM.
  5. Output: The function will return the structured JSON object containing the scores and a justification.

Here is a TypeScript code skeleton for a rankTrend.ts service. You can integrate this into the TypeScript project you set up in Module 1.

import { z } from 'zod';
import zodToJsonSchema from 'zod-to-json-schema';
import OpenAI from 'openai';

// 1. Define the schema for the LLM's structured output using Zod
const TrendAnalysisSchema = z.object({
  relevanceScore: z.number().min(1).max(5).describe("Score from 1-5 on relevance to software/data engineering & AI."),
  substanceScore: z.number().min(1).max(5).describe("Score from 1-5 on the topic's substance and long-term potential."),
  hypeCycleStage: z.enum([
    "Innovation Trigger",
    "Peak of Inflated Expectations",
    "Trough of Disillusionment",
    "Slope of Enlightenment",
    "Plateau of Productivity"
  ]).describe("Estimated position on the Gartner Hype Cycle."),
  justification: z.string().describe("A brief explanation for the scores, highlighting key signals."),
  isWorthPursuing: z.boolean().describe("A final boolean verdict on whether this trend is worth creating content about.")
});

// Type alias for our analysis result
type TrendAnalysis = z.infer<typeof TrendAnalysisSchema>;

// Initialize your LLM client (e.g., OpenAI)
const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

// 2. Create the main ranking function
export async function rankTrend(topicContent: string): Promise<TrendAnalysis | null> {
  const jsonSchema = zodToJsonSchema(TrendAnalysisSchema, "TrendAnalysisSchema");

  const systemPrompt = `
    You are an expert technology analyst for a software engineering thought leader.
    Your task is to evaluate a potential content topic based on a collection of articles and headlines.
    Assess the topic based on the following rubric and provide your analysis in a structured JSON format.

    **Evaluation Rubric:**
    1.  **Relevance (1-5):** How directly is this topic related to software engineering, programming languages, system architecture, data engineering, or AI development?
        - 1: Unrelated (e.g., politics, celebrity news).
        - 3: Tangentially related (e.g., general business tech, a viral meme among developers).
        - 5: Directly relevant (e.g., a new database, a programming pattern, a major library update).

    2.  **Substance (1-5):** How substantial and durable is this topic? Is it a genuine technological shift or short-lived hype?
        - 1: Pure hype, a meme, or a minor news item.
        - 3: An interesting new tool or feature, but with uncertain long-term impact.
        - 5: A fundamental shift, a major research breakthrough, or a new paradigm with clear long-term potential.

    3.  **Hype Cycle Stage:** Based on the discussion, estimate its position on the Gartner Hype Cycle.

    4.  **Verdict:** Based on your analysis, provide a final boolean \`isWorthPursuing\`. This should generally be true if both relevance and substance scores are 3 or higher.

    Analyze the provided text and return ONLY a valid JSON object matching the specified schema.
  `;

  try {
    const response = await openai.chat.completions.create({
      model: "gpt-4-turbo", // Or another powerful model
      messages: [
        { role: "system", content: systemPrompt },
        { role: "user", content: `Here is the content for the topic to analyze:\n\n---\n\n${topicContent}` }
      ],
      response_format: { type: "json_object" },
      // The `functions` or `tools` parameter can also be used to enforce the schema,
      // but `json_object` mode with a strong prompt is often sufficient.
    });

    const content = response.choices[0].message.content;
    if (!content) {
      throw new Error("Empty response from LLM.");
    }

    // 3. Parse and validate the response against our Zod schema
    const analysis = TrendAnalysisSchema.parse(JSON.parse(content));
    console.log("Trend Analysis Complete:", analysis);
    return analysis;

  } catch (error) {
    console.error("Error during trend ranking:", error);
    return null;
  }
}

// Example usage:
// In your main script, after identifying a trending topic, you would
// aggregate its content and call this function.
/*
async function main() {
  const topicId = 5;
  const articlesForTopic5 = getArticlesByTopicId(topicId); // Your function to get data
  const combinedText = articlesForTopic5.map(a => `${a.title}\n${a.summary}`).join('\n\n');
  
  const result = await rankTrend(combinedText);

  if (result && result.isWorthPursuing) {
    console.log(`Topic ${topicId} is a high-quality trend!`);
    // Add to a list of approved trends for the next pipeline step
  } else {
    console.log(`Topic ${topicId} was filtered out.`);
  }
}
*/

This script gives you a powerful, reusable "ranking agent." You can now loop through the trending topic IDs from your previous script, pass their content to rankTrend, and build a new, filtered list of high-quality trends that are ready for content generation.


Connecting to the Broader Architecture

What we've just built is essentially a "guardrail" or a "decision node" in our larger content creation workflow. This idea of using LLMs to evaluate, grade, and route information is a cornerstone of modern agentic architectures.

The LangChain blog post on Self-Reflective RAG explores this concept in depth. While we won't implement the full frameworks now, understanding the terminology will be valuable for Module 6, where you'll assemble the entire workflow using LangGraph.

  • Corrective RAG (CRAG): This framework uses a "retrieval evaluator" to grade the quality of documents. Our rankTrend function is a "trend evaluator" that serves the same purpose.
  • Self-RAG: This framework trains an LLM to use special tokens like ISREL (Is Relevant?) to make decisions. Our rubric-based scoring is a practical way to achieve a similar outcome without special model training.

By building this ranking component, you are already implementing the core principles of self-correcting AI systems.


Conclusion

Fantastic work today. You have added a critical layer of intelligence to our system, moving it beyond simple quantitative metrics into the realm of qualitative, contextual understanding.

Key Takeaways:

  • LLMs can be used as effective "judges" to evaluate and rank information, not just generate it.
  • A Direct Assessment approach with a well-defined rubric is a powerful way to steer an LLM's evaluation.
  • Frameworks like the Gartner Hype Cycle can be integrated into prompts to help an LLM distinguish between substantive trends and fleeting hype.
  • Using Zod to define a JSON schema for the LLM's output makes the process robust, type-safe, and reliable for use in an automated pipeline.
  • This ranking step acts as a crucial filter, ensuring that only the most relevant and promising trends proceed to the content generation phase.

Preview of the next lesson:
We now have a high-quality, ranked list of trends that are relevant and substantive. The next logical step is to start crafting a narrative around them. In the next lesson, "Design prompts to synthesize multiple sources into a coherent trend narrative," we will take the articles from a top-ranked trend and use an LLM to synthesize them into a single, cohesive story—the raw material for our final thought-leadership posts.