Cohere V3 For Multilingual Qa
Should I Stay at This Hotel?
Notebook by Bilge Yucel
Multilingual Generative QA Using Cohere and Haystack
In this notebook, we'll delve into the details of multilingual retrieval and multilingual generation, and demonstrate how to build a Retrieval Augmented Generation (RAG) pipeline to generate answers from multilingual hotel reviews using Cohere models and Haystack. 🏡
Haystack Useful Sources
For Haystack 1.x version, check out Article: Multilingual Generative Question Answering with Haystack and Cohere
Installation
Let's start by installing Haystack's Cohere integration:
Storing Multilingual Embeddings
To create a question answering system for hotel reviews, the first thing we need is a document store. We’ll use an InMemoryDocumentStore to save the hotel reviews along with their embeddings.
Getting Cohere API Key
After signing up, you can get a Cohere API key for free to start using Cohere models.
Enter Cohere API key:··········
Creating an Indexing Pipeline
Let's create an indexing pipeline to write the hotel reviews from different languages to our document store. For this, we'll split the long reviews with DocumentSplitter and create multilingual embeddings for each document using embed-multilingual-v3.0 model with CohereDocumentEmbedder.
Calculating embeddings: 100%|██████████| 1/1 [00:00<00:00, 3.29it/s]
{'embedder': {'meta': {'api_version': {'version': '1'},
, 'billed_units': {'input_tokens': 1137}}},
, 'writer': {'documents_written': 16}} Building a RAG Pipeline
Now that we have multilingual embeddings indexed in our document store, we'll create a pipeline where users interact the most: Retrieval-Augmented Generation (RAG) Pipeline.
A RAG pipeline consists of two parts: document retrieval and answer generation.
Multilingual Document Retrieval
In the document retrieval step of a RAG pipeline, CohereTextEmbedder creates an embedding for the query in the multilingual vector space and InMemoryEmbeddingRetriever retrieves the most similar top_k documents to the query from the document store. In our case, the retrieved documents will be hotel reviews.
Multilingual Answer Generation
In the generation step of the RAG pipeline, we'll use command model of Cohere with CohereGenerator to generate an answer based on the retrieved documents.
Let’s create a prompt template to use for hotel reviews. In this template, we’ll have two prompt variables: {{documents}} and {{question}}. These variables will later be filled with the user question and the retrieved hotel reviews outputted from the retriever.
Asking a Question
Learn if this hotel is a suitable place this stay with your questions!
The general consensus from the reviews is that this accommodation is very loud and not ideal for sleeping. The first review warns of loud club music which vibrates the beds, while the second review describes loud nightlife noise and loud cleaning practices in the early morning. Based on this evidence, it is fair to conclude that this accommodation is too noisy for guests to get adequate rest.
Other questions you can try 👇
Some of the main issues with this accommodation include loud vibrations and poor sound insulation, likely due to the proximity of clubs in the same building. Also, the WiFi did not work and the equipment in the apartment, including the shower head and bed, was broken and aged. Finally, the staff who checked them in offered no guidance or support and charged additionally for any needed amenities.
The reviews highlight the following positive aspects of the accommodation: - Great location - Good breakfast - Friendly staff and taxi driver (Ricardo) - Gentleness and care of the staff, with a kind message each morning to ensure all was well. It seems like the guests greatly appreciated the staff and service of the accommodation, and recommend it, wishing to return again in the future.
The reviews for this hotel are mixed. Some guests had an enjoyable experience at this hotel, highlighting the convenient location, breakfast, and friendly staff. However, it's important to note that there are also more critical reviews that point out some lacking amenities and an unclean atmosphere. If you are looking for a hotel with a more consistent reputation, it might be worth considering other options in the area. Ultimately, it is up to you to decide whether this hotel's potential strengths match your preferences and whether the reported issues are deal-breakers for your stay.
Based on the reviews provided, the wifi is functional but may not work sometimes. There also seems to be an issue with the television set and the cleanliness of the room.
Yes, the apartment is located above multiple bars. However the noise levels at night are mentioned as "ferment(ing) très tard", so you will want to consider ahead of time whether this might be an issue for you.