These examples demonstrate how to answer questions from the 'text_data' column of a TeradataML DataFrame. Refer to TextAnalyticsAI Example Setup for the prerequisite steps.
- If you do not specify a script in the Text Analytics function call, default scripts will be utilized. Specifically, for the "embedding" method, the default script is 'td_sample_embeddings_script.py'. For all other methods, the default script used is 'td_sample_inference_script.py'.
- You can access it in the 'example-data' directory in the installed package.
Example setup: Import the modules and create a teradataml DataFrame
from teradataml import DataFrame
from teradatagenai import TeradataAI, TextAnalyticsAI, load_data
load_data('question', 'question_data')
load_data('context', 'context_data')
data = DataFrame('question_data')
context = DataFrame('context_data')
Example: Answer questions from the 'text_data' column of a teradataml DataFrame using the 'context' DataFrame as context
Create an LLM endpoint using the environment variables.
obj_aws.ask(column="text_data", data=data,
context=context, context_column='text_data',
data_partition_column='id', context_partition_column='id',
prompt='Provide an answer to the question using data as
information relevant to the question.
\nQuestion: #QUESTION# \n Data: #DATA#',
data_position='#DATA#',
question_position='#QUESTION#')
Output:
| id | text_data | Response |
|---|---|---|
| 2 | Does it have a desert? | The provided text states: \ |
| 4 | What landmarks are UNESCO World Heritage sites in Lahore? | According to the text provided, the Lahore Fort and Badshahi Mosque are UNESCO World Heritage sites in Lahore. \n |
| 4 | What is Lahore famous for besides its landmarks? | According to the text provided, Lahore is also famous for its **vibrant food scene** and **colorful festivals**. \n |
| 4 | Which city is known as the cultural capital of Pakistan? | According to the text provided, **Lahore** is known as the cultural capital of Pakistan. \n |
| 5 | What is Peshawar known for historically? | The provided text does not contain information about what Peshawar is known for historically to confirm or refute the question. Therefore, I cannot answer your question using only the provided text. \n |
| 5 | Which city serves as the gateway to the Khyber Pass? | Based on the information provided:\n\n* **Data:** \ |
| 5 | What type of goods is Peshawar famous for? | The provided text does not explicitly state what goods Peshawar is famous for. \n\nHowever, it mentions that Peshawar is known for its:\n\n* **Ancient bazaars:** Bazaars are marketplaces where various goods are traditionally sold. This suggests Peshawar might be famous for goods typically found in bazaars.\n\nTo determine what specific goods Peshawar is famous for, we need additional information. \n |
| 3 | Give me name and value from the given data. | ## Answer:\n\nBased on the provided data:\n\n* **Musa** has the highest net worth at **$40,000**. \n \n Let's break it down:\n\n* **Sara:** $20,000 (financial holdings)\n* **Ali:** $20,000 (assets)\n* **Musa:** $40,000 (net worth, including savings and assets)\n\nNet worth represents the total value of a person's assets minus their liabilities. Since Musa has the highest net worth, it indicates he possesses the highest overall value even though the individual components of Sara's and Ali's financial situations are not fully detailed. \n |
| 2 | What is in Karachi? | The provided text already answers what is in Karachi:\n\n* **Beaches**\n* **Ports**\n* **Diverse cultural heritage** \n\nAdditionally, we know:\n\n* **It's a major economic hub** \n* **Areas with desert landscapes** \n \nTherefore, combining the question and the provided information, we know that Karachi has beaches, ports, a diverse cultural heritage, is a major economic hub and has areas with desert landscapes. \n |
| 1 | What is this city name in discussion? | The city in discussion is **Islamabad**. \n\nThe provided text states: \ |
Example: Answer questions from the 'text_data' column of a teradataml DataFrame using the 'context' DataFrame as context using Azure AI
Create an LLM endpoint using the environment variables.
obj_azure.ask(column="text_data", data=data,
context=context, context_column='text_data',
data_partition_column='id', context_partition_column='id',
prompt='Provide an answer to the question using data as
information relevant to the question.
\nQuestion: #QUESTION# \n Data: #DATA#',
data_position='#DATA#',
question_position='#QUESTION#')
Output:
| id | text_data | Response |
|---|---|---|
| 2 | What is in Karachi? | Based on the provided information, here is a summary of what is in Karachi:\n\n- Karachi is located on the southern coast of Pakistan and is a major economic hub. It is part of the Sindh province.\n\n- The city includes areas with desert landscapes.\n\n- Karachi is known for its beaches along the coast. \n\n- It has major ports due to its coastal location. \n\n- Karachi has a diverse cultural heritage as a major city in Pakistan.\n\nIn summary, Karachi contains beaches, ports, desert landscapes, and a diverse culture as a major coastal city in southern Pakistan. |
| 4 | Which city is known as the cultural capital of Pakistan? | Lahore is known as the cultural capital of Pakistan. |
| 4 | What is Lahore famous for besides its landmarks? | Based on the provided information, some things that Lahore is famous for besides its landmarks include:\n\n- Its food scene - The passage mentions Lahore has a \ |
| 4 | What landmarks are UNESCO World Heritage sites in Lahore? | Based on the provided information, the UNESCO World Heritage sites in Lahore are the Lahore Fort and Badshahi Mosque. |
| 3 | Give me name and value from the given data. | Okay, based on the data provided:\n\nMusa has a net worth of $40,000\nSara has financial holdings valued at $20,000\nAli owns assets worth $20,000 |
| 5 | What type of goods is Peshawar famous for? | Based on the data provided, Peshawar is famous for its handcrafted goods. The relevant sentence is:\n\n\ |
| 5 | Which city serves as the gateway to the Khyber Pass? | Peshawar |
| 1 | What is this city name in discussion? | Based on the data provided, the city name in discussion is Islamabad. |
| 2 | Does it have a desert? | Based on the provided information, my answer is:\n\nYes, Karachi has some desert areas. The passage states that \ |
| 6 | Why is the Great Wall of China considered a marvel? | Based on the data provided, the Great Wall of China is considered a marvel of engineering for the following reasons:\n\n- It stretches over 13,000 miles, making it one of the longest structures ever built. The sheer scale and length of the wall is an incredible engineering achievement.\n\n- It was built over 2,000 years ago without modern machinery. Much of the wall was built by hand using basic tools and equipment, which is remarkable considering its size.\n\n- It traverses challenging and diverse terrain including mountains, deserts, and grasslands. Building a wall through such environments was an engineering challenge. \n\n- Much of the wall is made from stone and bricks. Transporting the amount of material needed and precisely stacking the bricks and stones to build the wall was a major feat of engineering and construction.\n\n- It has stood the test of time and remains largely intact today despite its age. The engineering and durability of the wall allowed it to withstand the elements and avoid crumbling over centuries.\n\nIn summary, the scale, antiquity, diversity of terrain, use of materials, and enduring legacy make the Great Wall of China an unparalleled marvel of engineering and construction for its time. The wall demonstrated remarkable ingenuity in ancient Chinese engineering that impresses modern visitors. |
Example: Answer questions from the 'text_data' column of a teradataml DataFrame using the 'context' DataFrame as context using Google Gemini
Create an LLM endpoint using the environment variables.
obj_gcp.ask(column="text_data", data=data,
context=context, context_column='text_data',
data_partition_column='id', context_partition_column='id',
prompt='Provide an answer to the question using data as
information relevant to the question.
\nQuestion: #QUESTION# \n Data: #DATA#',
data_position='#DATA#',
question_position='#QUESTION#')
Output:
| id | text_data | Response |
|---|---|---|
| 5 | What type of goods is Peshawar famous for? | Based on the information provided:\n\n**Peshawar is famous for its traditional cuisine and handcrafted goods.** \n |
| 5 | Which city serves as the gateway to the Khyber Pass? | The answer is **Peshawar**. \n\nYou stated that \ |
| 6 | Why is the Great Wall of China considered a marvel? | The provided text states: **\ |
| 2 | What is in Karachi? | Please provide the data you are referring to so I can answer the question accurately. For example, the data could be:\n\n* **A list of landmarks and attractions:** This would help me confirm if Karachi has beaches, ports, etc.\n* **Economic statistics:** This would tell me about Karachi's role as a major economic hub. \n* **Geographical information:** This could include details about Sindh province and the presence of desert landscapes.\n* **Cultural data:** This might list examples of Karachi's diverse cultural heritage.\n\nOnce you provide the data, I can analyze it and answer your question about Karachi. \n |
| 4 | Which city is known as the cultural capital of Pakistan? | According to the text provided, **Lahore** is known as the cultural capital of Pakistan. \n |
| 4 | What is Lahore famous for besides its landmarks? | Based on the provided text, Lahore is famous for its:\n\n* **Vibrant food scene**\n* **Colorful festivals** \n |
| 4 | What landmarks are UNESCO World Heritage sites in Lahore? | The UNESCO World Heritage sites in Lahore are the **Lahore Fort** and the **Badshahi Mosque**. \n |
| 2 | Does it have a desert? | The provided text states: \ |
| 5 | What is Peshawar known for historically? | Based on the information provided:\n\n* **Peshawar is known historically as a gateway to the Khyber Pass.** \n\nThe text states, \ |
| 3 | Give me name and value from the given data. | ## Answer:\n\nBased on the provided data:\n\n* **Musa:** Net worth = $40,000 (includes savings and assets)\n* **Sara:** Financial holdings = $20,000 \n* **Ali:** Assets = $20,000 \n\nTherefore, we can conclude:\n\n* **Musa is the wealthiest of the three individuals.** He has a net worth of $40,000, which is double that of Sara and Ali. \n |
Create LLM endpoint using the environment variables.
obj_nim.ask(column="text_data", data=data,
context=context, context_column='text_data',
data_partition_column='id', context_partition_column='id',
prompt='Provide an answer to the question using data as
information relevant to the question.
\nQuestion: #QUESTION# \n Data: #DATA#',
data_position='#DATA#',
question_position='#QUESTION#')
Output:
| id | text_data | Response |
|---|---|---|
| 4 | Which city is known as the cultural capital of Pakistan? | The city known as the cultural capital of Pakistan is Lahore. |
| 4 | What is Lahore famous for besides its landmarks? | Lahore is famous for its vibrant food scene and colorful festivals, in addition to its historical landmarks. |
| 6 | How long is the Great Wall of China? | The Great Wall of China is approximately 13,000 miles long. |
| 6 | Why is the Great Wall of China considered a marvel? | The Great Wall of China is considered a marvel due to its immense size and impressive engineering. Spanning over 13,000 miles, it is one of the longest structures ever built. The wall's construction was a monumental feat, involving millions of laborers and thousands of years of continuous development. It was built to protect China from invasions, making it a significant historical and cultural landmark. These factors contribute to its recognition as a marvel of engineering and a major tourist attraction, attracting millions of tourists each year. |
| 5 | What type of goods is Peshawar famous for? | Peshawar is famous for its traditional cuisine and handcrafted goods. These goods include intricate carpets, woodwork, and metalwork. The city is also known for its locally produced spices, dry fruits, and traditional sweets. Additionally, Peshawar serves as a gateway to the historic Khyber Pass, a major trade route that has played a significant role in the city's history and cultural exchange. |
| 5 | Which city serves as the gateway to the Khyber Pass? | The city that serves as the gateway to the Khyber Pass is Peshawar. |
| 5 | What is Peshawar known for historically? | Peshawar is historically known for being a gateway to the Khyber Pass, a strategic trade route connecting Afghanistan and India. It has been an important city since ancient times, serving as a crossroads for various civilizations, including the Persians, Greeks, Mauryans, and Kushans. The city's rich history is reflected in its architecture, such as the Bala Hisar Fort and the Mahabodhi Temple ruins. Additionally, Peshawar is known for its traditional cuisine, handcrafted goods, and bustling bazaars. |
| 6 | What is the purpose of the Great Wall of China? | The Great Wall of China was built to protect against invasions. |
| 4 | What landmarks are UNESCO World Heritage sites in Lahore? | The data provided indicates that Lahore, being the cultural capital of Pakistan, is home to two UNESCO World Heritage sites: Lahore Fort and Badshahi Mosque. |
| 2 | Does it have a desert? | Yes, Karachi is part of the Sindh province, which includes areas with desert landscapes. However, it's important to note that Karachi itself is not entirely a desert. It's a coastal city with a diverse landscape that includes urban areas, beaches, and ports. |