Find answers from the community

Updated 4 months ago

Hi there! Is it possible to use

At a glance

The community member is interested in building a chatbot similar to the Rasa framework, but using ChatGPT instead of natural language understanding (NLU). They want to know if it's possible to use LlamaIndex for intent classification and entity retrieval. The comments suggest that an LLM can be used to predict a structured object for intent classification, providing an example using OpenAI's LLM. The community members also discuss using structured_predict for entity recognition, with suggestions to check out the span-marker package and Gliner for zero-shot token classification.

Hi there! Is it possible to use llamaindex for intent classification/entity retrieval? I want to build chatbot similar to rasa framework but using chatgpt instead of nlu. I mean I want to describe stories with intents/actions. I would be grateful for any examples/thoughts. can you help please πŸ™‚
L
r
6 comments
Pretty tricky! You can use an LLM to maybe predict a structured object

Plain Text
from pydantic.v1 import BaseModel, Field
from typing import Literal

IntentTypes = Literal["BOOKING", "QUIT", "ANGRY", ...]

class Intent(BaseModel):
  """The intent behind a piece of text."""
  intent: IntentTypes = Field(description="The type of intent that best represents a piece of text. Make sure to only use a valid intent type: ['BOOKING', 'QUIT', 'ANGRY', ...]"
  explanation: str = Field(description="An explanation for your choice of intent.")


from llama_index.core.prompts import PromptTemplate
from llama_index.llms.openai import OpenAI
llm = OpenAI()

prompt = PromptTemplate("Here is some context, give me an intent: {context}")

intent = llm.structured_predict(Intent, prompt, context="...")

print(intent)
I'd probably wrap that predict call in a try/except though πŸ˜…
Cool! Thanks )
What about entity recognition, use structured_predict as well?
Pretty much. That is, if you want to use an LLM for this.

I know there are some good NER models out there (check out the span-marker package for example)

I've also heard good things about Gliner for zero-shot token classification as well
Add a reply
Sign up and join the conversation on Discord