Overview
- Introduction
- Setup & Install
- Quickstart
Concepts
- AI Tables
- Data Sources
- Automation
Use Cases
- Overview
- Fine-Tuning
- Chatbots with Agents
- Chatbots with Jobs
- Alert Systems
- Content Generation
- Semantic Search
- Recommenders
- Question Answering
- Sentiment Analysis
- Text Summarization
- Forecasting
- Classification
- Regression
- Natural Language Processing
NLP Example Library
Currently, MindsDB’s NLP engine is powered by Hugging Face and OpenAI. But we plan to expand to other NLP options in the future, so stay tuned!
The MindsDB’s Hugging Face engine is extensible. We are actively working on adding more tasks and models. If you have a specific task or model in mind, please let us know in the MindsDB Community.
Hugging Face Examples
Here are the tasks supported by MindsDB and Hugging Face:
- Text Classification
- Zero-Shot Classification
- Translation
- Summarization
Let’s go through the examples.
Text Classification
Let’s create a model.
CREATE MODEL mindsdb.hf_spam
PREDICT PRED
USING
engine = 'huggingface',
task = 'text-classification',
model_name = 'mariagrandury/roberta-base-finetuned-sms-spam-detection',
input_column = 'text',
labels = ['spam', 'ham'];
And check its status.
DESCRIBE hf_spam;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_spam
WHERE text = 'I like you. I love you.';
On execution, we get:
+----+--------------------------------------------------------+-----------------------+
|PRED|PRED_explain |text |
+----+--------------------------------------------------------+-----------------------+
|spam|{"ham":0.00020051795581821352,"spam":0.9997995495796204}|I like you. I love you.|
+----+--------------------------------------------------------+-----------------------+
Let’s create a model.
CREATE MODEL mindsdb.hf_sentiment
PREDICT PRED
USING
engine = 'huggingface',
task = 'text-classification',
model_name = 'cardiffnlp/twitter-roberta-base-sentiment',
input_column = 'text',
labels = ['neg', 'neu', 'pos'];
And check its status.
DESCRIBE hf_sentiment;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_sentiment
WHERE text = 'I like you. I love you.';
On execution, we get:
+----+--------------------------------------------------------------------------------+-----------------------+
|PRED|PRED_explain |text |
+----+--------------------------------------------------------------------------------+-----------------------+
|pos |{"neg":0.003046575468033552,"neu":0.021965451538562775,"pos":0.9749879240989685}|I like you. I love you.|
+----+--------------------------------------------------------------------------------+-----------------------+
Let’s create a model.
CREATE MODEL mindsdb.hf_sentiment_finance
PREDICT PRED
USING
engine = 'huggingface',
task = 'text-classification',
model_name = 'ProsusAI/finbert',
input_column = 'text';
And check its status.
DESCRIBE hf_sentiment_finance;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_sentiment_finance
WHERE text = 'Stocks rallied and the British pound gained.';
On execution, we get:
+--------+-------------------------------------------------------------------------------------------+--------------------------------------------+
|PRED |PRED_explain |text |
+--------+-------------------------------------------------------------------------------------------+--------------------------------------------+
|positive|{"negative":0.0344734713435173,"neutral":0.06716493517160416,"positive":0.8983616232872009}|Stocks rallied and the British pound gained.|
+--------+-------------------------------------------------------------------------------------------+--------------------------------------------+
Let’s create a model.
CREATE MODEL mindsdb.hf_emotions_6
PREDICT PRED
USING
engine = 'huggingface',
task = 'text-classification',
model_name = 'j-hartmann/emotion-english-distilroberta-base',
input_column = 'text';
And check its status.
DESCRIBE hf_emotions_6;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_emotions_6
WHERE text = 'Oh Happy Day';
On execution, we get:
+----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+
|PRED|PRED_explain |text |
+----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+
|joy |{"anger":0.0028446922078728676,"disgust":0.0009613594156689942,"fear":0.0007112706662155688,"joy":0.7692911624908447,"neutral":0.037753619253635406,"sadness":0.015293814241886139,"surprise":0.17314413189888}|Oh Happy Day|
+----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+
Let’s create a model.
CREATE MODEL mindsdb.hf_toxicity
PREDICT PRED
USING
engine = 'huggingface',
task = 'text-classification',
model_name = 'SkolkovoInstitute/roberta_toxicity_classifier',
input_column = 'text';
And check its status.
DESCRIBE hf_toxicity;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_toxicity
WHERE text = 'I like you. I love you.';
On execution, we get:
+-------+-------------------------------------------------------------+-----------------------+
|PRED |PRED_explain |text |
+-------+-------------------------------------------------------------+-----------------------+
|neutral|{"neutral":0.9999547004699707,"toxic":0.00004535282641882077}|I like you. I love you.|
+-------+-------------------------------------------------------------+-----------------------+
Let’s create a model.
CREATE MODEL mindsdb.hf_esg_6
PREDICT PRED
USING
engine = 'huggingface',
task = 'text-classification',
model_name = 'yiyanghkust/finbert-esg',
input_column = 'text';
And check its status.
DESCRIBE hf_esg_6;
Once the status is complete
, we can query for predictions.
SELECT * FROM mindsdb.hf_esg_6
WHERE text = 'Rhonda has been volunteering for several years for a variety of charitable community programs.';
On execution, we get:
+------+---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------+
|PRED |PRED_explain |text |
+------+---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------+
|Social|{"Environmental":0.0034267122391611338,"Governance":0.004729956854134798,"None":0.001239194767549634,"Social":0.9906041026115417}|Rhonda has been volunteering for several years for a variety of charitable community programs.|
+------+---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------+
Let’s create a model.
CREATE MODEL mindsdb.hf_esg_26
PREDICT PRED
USING
engine = 'huggingface',
task = 'text-classification',
model_name = 'yiyanghkust/finbert-esg',
input_column = 'text';
And check its status.
DESCRIBE hf_esg_26;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_esg_26
WHERE text = 'We believe it is essential to establish validated conflict-free sources of 3TG within the Democratic Republic of the Congo (the “DRC”) and adjoining countries (together, with the DRC, the “Covered Countries”), so that these minerals can be procured in a way that contributes to economic growth and development in the region. To aid in this effort, we have established a conflict minerals policy and an internal team to implement the policy.';
On execution, we get:
+------+-----------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|PRED |PRED_explain |text |
+------+-----------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|Social|{"Environmental":0.2031959593296051,"Governance":0.08251894265413284,"None":0.050893042236566544,"Social":0.6633920073509216}|We believe it is essential to establish validated conflict-free sources of 3TG within the Democratic Republic of the Congo (the “DRC”) and adjoining countries (together, with the DRC, the “Covered Countries”), so that these minerals can be procured in a way that contributes to economic growth and development in the region. To aid in this effort, we have established a conflict minerals policy and an internal team to implement the policy.|
+------+-----------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Let’s create a model.
CREATE MODEL mindsdb.hf_hate
PREDICT PRED
USING
engine = 'huggingface',
task = 'text-classification',
model_name = 'Hate-speech-CNERG/bert-base-uncased-hatexplain',
input_column = 'text';
And check its status.
DESCRIBE hf_hate;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_hate
WHERE text = 'I like you. I love you.';
On execution, we get:
+------+-----------------------------------------------------------------------------------------------+-----------------------+
|PRED |PRED_explain |text |
+------+-----------------------------------------------------------------------------------------------+-----------------------+
|normal|{"hate speech":0.03551718592643738,"normal":0.7747423648834229,"offensive":0.18974047899246216}|I like you. I love you.|
+------+-----------------------------------------------------------------------------------------------+-----------------------+
Let’s create a model.
CREATE MODEL mindsdb.hf_crypto
PREDICT PRED
USING
engine = 'huggingface',
task = 'text-classification',
model_name = 'ElKulako/cryptobert',
input_column = 'text';
And check its status.
DESCRIBE hf_crypto;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_crypto
WHERE text = 'BTC is killing it right now';
On execution, we get:
+-------+------------------------------------------------------------------------------------------+---------------------------+
|PRED |PRED_explain |text |
+-------+------------------------------------------------------------------------------------------+---------------------------+
|Bullish|{"Bearish":0.0002816587220877409,"Bullish":0.559426486492157,"Neutral":0.4402918517589569}|BTC is killing it right now|
+-------+------------------------------------------------------------------------------------------+---------------------------+
Let’s create a model.
CREATE MODEL mindsdb.hf_us_party
PREDICT PRED
USING
engine = 'huggingface',
task = 'text-classification',
model_name = 'm-newhauser/distilbert-political-tweets',
input_column = 'text';
And check its status.
DESCRIBE hf_us_party;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_us_party
WHERE text = 'This pandemic has shown us clearly the vulgarity of our healthcare system. Highest costs in the world, yet not enough nurses or doctors. Many millions uninsured, while insurance company profits soar. The struggle continues. Healthcare is a human right. Medicare for all.';
On execution, we get:
+--------+-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|PRED |PRED_explain |text |
+--------+-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|Democrat|{"Democrat":0.9999973773956299,"Republican":0.00000261212517216336}|This pandemic has shown us clearly the vulgarity of our healthcare system. Highest costs in the world, yet not enough nurses or doctors. Many millions uninsured, while insurance company profits soar. The struggle continues. Healthcare is a human right. Medicare for all.|
+--------+-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Let’s create a model.
CREATE MODEL mindsdb.hf_question
PREDICT PRED
USING
engine = 'huggingface',
task = 'text-classification',
model_name = 'shahrukhx01/bert-mini-finetune-question-detection',
input_column = 'text',
labels = ['question', 'query'];
And check its status.
DESCRIBE hf_question;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_question
WHERE text = 'Where can I buy electronics in London';
On execution, we get:
+-----+--------------------------------------------------------------+-------------------------------------+
|PRED |PRED_explain |text |
+-----+--------------------------------------------------------------+-------------------------------------+
|query|{"query":0.9997773766517639,"question":0.00022261829872149974}|Where can I buy electronics in London|
+-----+--------------------------------------------------------------+-------------------------------------+
Let’s create a model.
CREATE MODEL mindsdb.hf_industry
PREDICT PRED
USING
engine = 'huggingface',
task = 'text-classification',
model_name = 'sampathkethineedi/industry-classification',
input_column = 'text';
And check its status.
DESCRIBE hf_industry;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_industry
WHERE text = 'Low latency is one of our best cloud features';
On execution, we get:
+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
|PRED |PRED_explain |text |
+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
|Systems Software|{"Advertising":0.000006795735771447653,"Aerospace & Defense":0.00001537964453746099,"Apparel Retail":5.350161131900677e-7,"Apparel, Accessories & Luxury Goods":0.000002604161181807285,"Application Software":0.009111878462135792,"Asset Management & Custody Banks":0.00003155150625389069,"Auto Parts & Equipment":0.000015504940165556036,"Biotechnology":6.533917940032552e-8,"Building Products":7.348538133555849e-8,"Casinos & Gaming":0.000013775999832432717,"Commodity Chemicals":0.0000010432338513055583,"Communications Equipment":0.000019887389498762786,"Construction & Engineering":0.000001826199536480999,"Construction Machinery & Heavy Trucks":0.000009827364920056425,"Consumer Finance":0.0000018292046206624946,"Data Processing & Outsourced Services":0.0000010666744856280275,"Diversified Metals & Mining":0.000006960767223063158,"Diversified Support Services":0.000016824227714096196,"Electric Utilities":0.000003896044290740974,"Electrical Components & Equipment":0.000001626394464437908,"Electronic Equipment & Instruments":0.00003863943129545078,"Environmental & Facilities Services":0.000736175337806344,"Gold":0.00002220332135038916,"Health Care Equipment":4.6927588925882446e-8,"Health Care Facilities":7.432880124724761e-7,"Health Care Services":6.929263918209472e-7,"Health Care Supplies":2.1007431882935634e-7,"Health Care Technology":0.000003907185146090342,"Homebuilding":3.903339234057057e-7,"Hotels, Resorts & Cruise Lines":6.0527639789143e-7,"Human Resource & Employment Services":5.48697983049351e-7,"IT Consulting & Other Services":0.0000723653138265945,"Industrial Machinery":7.230253231682582e-7,"Integrated Telecommunication Services":2.8266379104024963e-7,"Interactive Media & Services":0.00003454017496551387,"Internet & Direct Marketing Retail":0.000003871373337460682,"Internet Services & Infrastructure":0.0007196652004495263,"Investment Banking & Brokerage":0.0000040634336073708255,"Leisure Products":0.000002158361439796863,"Life Sciences Tools & Services":0.000002861268058040878,"Movies & Entertainment":0.000007286199888767442,"Oil & Gas Equipment & Services":0.000004376991455501411,"Oil & Gas Exploration & Production":0.000005569149834627751,"Oil & Gas Refining & Marketing":0.000012647416951949708,"Oil & Gas Storage & Transportation":0.000005852583853993565,"Packaged Foods & Meats":0.0000011130315442642313,"Personal Products":0.00000970239307207521,"Pharmaceuticals":0.0000037546726616710657,"Property & Casualty Insurance":0.000006116194072092185,"Real Estate Operating Companies":0.00001882187461887952,"Regional Banks":0.0000011669454806906288,"Research & Consulting Services":0.000024276219846797176,"Restaurants":8.598511840318679e-7,"Semiconductors":0.0000021006283077440457,"Specialty Chemicals":0.000004160017397225602,"Specialty Stores":2.644004553076229e-7,"Steel":0.0000013566890402216814,"Systems Software":0.9889177083969116,"Technology Distributors":0.00001339179198112106,"Technology Hardware, Storage & Peripherals":0.00004790363891515881,"Thrifts & Mortgage Finance":3.924862141957419e-7,"Trading Companies & Distributors":0.0000035233156268077437}|Low latency is one of our best cloud features|
+----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
Zero-Shot Classification
Let’s create a model.
CREATE MODEL mindsdb.hf_zs_bart
PREDICT PRED
USING
engine = 'huggingface',
task = 'zero-shot-classification',
model_name = 'facebook/bart-large-mnli',
input_column = 'text',
candidate_labels = ['Books', 'Household', 'Clothing & Accessories', 'Electronics'];
And check its status.
DESCRIBE hf_zs_bart;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_zs_bart
WHERE text = 'Paper Plane Design Framed Wall Hanging Motivational Office Decor Art Prints';
On execution, we get:
+---------+------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
|PRED |PRED_explain |text |
+---------+------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
|Household|{"Books":0.1876104772090912,"Clothing & Accessories":0.08688066899776459,"Electronics":0.14785148203372955,"Household":0.5776574015617371}|Paper Plane Design Framed Wall Hanging Motivational Office Decor Art Prints|
+---------+------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
Translation
Let’s create a model.
CREATE MODEL mindsdb.hf_t5_en_fr
PREDICT PRED
USING
engine = 'huggingface',
task = 'translation',
model_name = 't5-base',
input_column = 'text',
lang_input = 'en',
lang_output = 'fr';
And check its status.
DESCRIBE hf_t5_en_fr;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_t5_en_fr
WHERE text = 'The monkey is on the branch';
On execution, we get:
+---------------------------+---------------------------+
|PRED |text |
+---------------------------+---------------------------+
|Le singe est sur la branche|The monkey is on the branch|
+---------------------------+---------------------------+
Summarization
Let’s create a model.
CREATE MODEL mindsdb.hf_bart_sum_20
PREDICT PRED
USING
engine = 'huggingface',
task = 'summarization',
model_name = 'sshleifer/distilbart-cnn-12-6',
input_column = 'text',
min_output_length = 5,
max_output_length = 20;
And check its status.
DESCRIBE hf_bart_sum_20;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_bart_sum_20
WHERE text = 'The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.';
On execution, we get:
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|PRED |text |
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|The tower is 324 metres (1,063 ft) tall, about the same|The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.|
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Let’s create a model.
CREATE MODEL mindsdb.hf_peg_sum_20
PREDICT PRED
USING
engine = 'huggingface',
task = 'summarization',
model_name = 'google/pegasus-xsum',
input_column = 'text',
min_output_length = 5,
max_output_length = 20;
And check its status.
DESCRIBE hf_peg_sum_20;
Once the status is complete
, we can query for predictions.
SELECT *
FROM mindsdb.hf_peg_sum_20
WHERE text = 'The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.';
On execution, we get:
+------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|PRED |text |
+------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|The Eiffel Tower is a landmark in Paris, France.|The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.|
+------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
OpenAI Examples
Here are the tasks supported by MindsDB and OpenAI:
- Answering Questions without Context
- Answering Questions with Context
- Prompt Completion
Follow this instruction to set up the OpenAI integration in MindsDB.
Let’s go through the examples.
Answering Questions without Context
Let’s create a model.
CREATE MODEL project_a.openai_test_a
PREDICT answer
USING
engine = 'openai',
question_column = 'question';
On execution, we get:
Query successfully completed
Now we can query for answers.
SELECT question, answer
FROM project_a.openai_test_a
WHERE question = 'Where is Stockholm located?';
On execution, we get:
+---------------------------+-------------------------------+
|question |answer |
+---------------------------+-------------------------------+
|Where is Stockholm located?|Stockholm is located in Sweden.|
+---------------------------+-------------------------------+
Answering Questions with Context
Let’s create a model.
CREATE MODEL project_a.openai_test_b
PREDICT answer
USING
engine = 'openai',
question_column = 'question',
context_column = 'context';
On execution, we get:
Query successfully completed
Now we can query for answers.
SELECT context, question, answer
FROM project_a.openai_test_b
WHERE context = 'Answer with a joke'
AND question = 'How to cook soup?';
On execution, we get:
+-------------------+------------------+---------------------------------------------------------+
|context |question |answer |
+-------------------+------------------+---------------------------------------------------------+
|Answer with a joke |How to cook soup? |How do you cook soup? You put it in a pot and heat it up!|
+-------------------+------------------+---------------------------------------------------------+
Prompt Completion
Let’s create a model.
CREATE MODEL project_a.openai_test_c
PREDICT answer
USING
engine = 'openai',
prompt_template = 'Context: {{context}}. Question: {{question}}. Answer:',
max_tokens = 100,
temperature = 0.3;
Let’s look at an example that uses parameters provided at model creation time.
SELECT context, question, answer
FROM project_a.openai_test_c
WHERE context = 'Answer accurately'
AND question = 'How many planets exist in the solar system?';
On execution, we get:
+-------------------+-------------------------------------------+----------------------------------------------+
|context |question |answer |
+-------------------+-------------------------------------------+----------------------------------------------+
|Answer accurately |How many planets exist in the solar system?| There are eight planets in the solar system. |
+-------------------+-------------------------------------------+----------------------------------------------+
Let’s create a model.
CREATE MODEL project_a.openai_test_c
PREDICT answer
USING
engine = 'openai',
prompt_template = 'Context: {{context}}. Question: {{question}}. Answer:',
max_tokens = 100,
temperature = 0.3;
Let’s look at an example that overrides parameters at prediction time.
SELECT instruction, answer
FROM project_a.openai_test_c
WHERE instruction = 'Speculate extensively'
USING
prompt_template = '{{instruction}}. What does Tom Hanks like?',
max_tokens = 100,
temperature = 0.5;
On execution, we get:
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|instruction |answer |
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|Speculate extensively |Some people speculate that Tom Hanks likes to play golf, while others believe that he enjoys acting and directing. It is also speculated that he likes to spend time with his family and friends, and that he enjoys traveling.|
+----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Let’s create a model.
CREATE MODEL mindsdb.sentiment_classifier
PREDICT sentiment
USING
engine = 'openai',
prompt_template = 'predict the sentiment of the text:{{review}} exactly as either positive or negative or neutral';
Now we can query for predictions.
SELECT output.sentiment, input.review
FROM example_db.demo_data.amazon_reviews AS input
JOIN mindsdb.sentiment_classifier AS output
LIMIT 3;
On execution, we get:
+----------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| sentiment | review |
+----------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| positive | Late gift for my grandson. He is very happy with it. Easy for him (9yo ). |
| The sentiment of the text is positive. | I'm not super thrilled with the proprietary OS on this unit, but it does work okay and does what I need it to do. Appearance is very nice, price is very good and I can't complain too much - just wish it were easier (or at least more obvious) to port new apps onto it. For now, it helps me see things that are too small on my phone while I'm traveling. I'm a happy buyer.|
| positive | I purchased this Kindle Fire HD 8 was purchased for use by 5 and 8 yer old grandchildren. They basically use it to play Amazon games that you download. |
+----------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
What’s Next?
Have fun while trying it out yourself!
- Bookmark MindsDB repository on GitHub.
- Sign up for a free MindsDB account.
- Engage with the MindsDB community on Slack or GitHub to ask questions and share your ideas and thoughts.
If this tutorial was helpful, please give us a GitHub star here.