What is the best way to Embedding our text for a "multi level Question"

Hi all,
It’s been a while since I have experiment with GPT-3 prompt text completion, especially for Question Answering. Text-davinci it’s actually good to have a kind of sort of “memory” by putting a past conversation or summary, so the prompt will still generate in the same context of what the conversation is currently ongoing. Something like this: (Q for User question, A for Bot Answer)

Q: Do you know about London?
A: Yes, I do. London is the capital of England and the United Kingdom. It is a major global city with a diverse population and culture. It is a popular tourist destination and home to some of the world’s most iconic landmarks such as Buckingham Palace, the Tower of London, and the London Eye.
Q: what’s the iconic place in there
A: The most iconic place in London is probably Buckingham Palace, the official residence of the British Royal Family. Other popular landmarks include the Tower of London, Big Ben, and the London Eye.
Q: how much cost of living
A: The cost of living in London varies depending on the area, but on average it is one of the most expensive cities in the world. According to Numbeo, the average cost of living for a single person in London is $2,590 per month.

But I have a kind of problem while implementing this into Embedding, since you know Embedding will search the most similar text/document and it looks like if there are 2 or more texts related to the same topic such as “iconic place” or “cost of living” in the example of above conversations, there will be chance thus other text will have a higher similarity rather than the text talking about London. What is the best format for Embedding, either when we are transforming our text corpus into text embedding or when we are going to query our question to search similar texts through Embedding?

I’m so glad if there’s any experience you guys would like to share while you guys have been doing with Embedding Model.

Thank you

Note: the conversation above is merely a dummy example, in order to make it simple to convey what I want to elaborate.

Great question. The solution is simple, scope outside of your semantic search and utilize a method to keep context.

If someone asks about London, and then starts asking questions that are contextually attached to the original question, you should be prepending that to all your queries.

You could accomplish this with token classification. In your example, it would be paramount to identify the city and include that as context until the user/agent changes the topic to another city.

You can also accomplish this with a secondary database. If the user/agent mentions London you can focus your database only inside of London - ignoring everything else, until something else is mentioned.


thank you for the replies @RonaldGRuckus, oh wow I have been thinking like your suggestions actually. Something like extracting or summarizing a key point on User’s first question, since people tend to put some rich information mostly on their first question. Then if the conversation is still happening, I append the last 2 or 4 user queries too, or until they moved or jump into a new topic. I don’t know if this will works well or not, but let’s give it a try.

Really appreciate your replies anyways!

Is there a tutorial or a quick start sample app available somewhere? I’m in need of trying this as well for the embeddings approach to build a Q/A system that maintains the context on follow up questions.

I think you should try to extract Named entity from the user prompt instead of classification.

If you haven’t already check out langchain and llamaindex Memory — 🦜🔗 LangChain 0.0.95

oh wow interesting, thank you for the sharing

for the moment, I’m still using this kind of format but it’s somehow has a decent result.

for example: If there are 4 conversations happening, I will append the latest 4 question from the user including the current question. and I set the limit up to 4 questions too, so the last one will be replace if there’s any newer questions. So the query will look like this:

BEFORE: previous_3rd_q
BEFORE: previous_2th_q
BEFORE: previous_1st_q
NOW: current_q

Correct me if I’m wrong, but does NER is part of token classification?

As per my knowledge NER is sub part of Token classification!

1 Like