There are four main NLP tasks currently supported by MindsDB:
Text Classification
Zero-Shot Classification
Translation
Summarization
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.
Completes the task of assigning a label to a text without training on the labels.
For example, you can use it to classify a movie review as positive or negative without training on positive or negative labels.
The Hugging Face models are used to perform these tasks.
Keep in mind that usually there is more than one model for each task,
so you can choose the one that suits you best.
We use the CREATE MODEL statement to bring the Hugging Face models to MindsDB.Generally, it looks like this:
Copy
Ask AI
CREATE MODEL project_name.predictor_name -- AI TABLE TO STORE THE MODELPREDICT target_column -- NAME OF THE COLUMN TO STORE PREDICTED VALUESUSING engine = 'huggingface', -- USING THE HUGGING FACE ENGINE task = 'task', -- TASK OF CLASSIFYING TEXT (OPTIONAL) model_name = 'model_name_from_hugging_face', -- MODEL NAME UNDER THE HUGGING FACE MODEL HUB input_column = 'input_column', -- COLUMN NAME OF THE INPUT DATA labels = ['label', 'label_1']; -- ARRAY OF LABELS
Where:
Expressions
Description
project_name
Name of the project where the model is created. By default, the mindsdb project is used.
predictor_name
Name of the model to be created.
target_column
Column to store the predicted values.
engine
Optional. You can provide an ML engine, based on which the model is created.
task
Optional. It is relative to the Hugging Face task tag.
model_name
Model name from the Hugging Face model hub.
input_column
Name of the column that has the input data, especially important for batch predictions using JOIN.
labels
Depending on the model. Usually used for Zero-Shot Classification models.
Let’s go through a Spam Classification example to understand better how to link Hugging Face models and bring them to MindsDB as AI tables.
Using Local Installation of MindsDBPlease note that if you use a local installation of MindsDB, instead of MindsDB Cloud, you should install transformers==4.21.0 to be able to use the Hugging Face models.
Copy
Ask AI
CREATE MODEL mindsdb.spam_classifierPREDICT PRED USING engine = 'huggingface', task = 'text-classification', model_name = 'mrm8488/bert-tiny-finetuned-sms-spam-detection', input_column = 'text_spammy', labels = ['ham', 'spam'];
Once the status is complete, we can query for predictions.
Copy
Ask AI
SELECT h.PRED, h.PRED_explain, t.text_spammy AS input_textFROM example_db.demo_data.hf_test AS tJOIN mindsdb.spam_classifier AS h;
On execution, we get:
Copy
Ask AI
+----+---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+|PRED|PRED_explain |input_text |+----+---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+|spam|{'spam': 0.9051626920700073, 'ham': 0.09483727067708969} |Free entry in 2 a wkly comp to win FA Cup final tkts 21st May 2005. Text FA to 87121 to receive entry question(std txt rate)T&C's apply 08452810075over18's ||ham |{'ham': 0.9380123615264893, 'spam': 0.061987683176994324}|Nah I don't think he goes to usf, he lives around here though ||spam|{'spam': 0.9064534902572632, 'ham': 0.09354648739099503} |WINNER!! As a valued network customer you have been selected to receivea £900 prize reward! To claim call 09061701461. Claim code KL341. Valid 12 hours only. |+----+---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+
For the full library of supported examples please go here.
Let’s go through a Sentiment Classification example, but this time we’ll use a Mongo database.
Using Local Installation of MindsDBPlease note that if you use a local installation of MindsDB, instead of MindsDB Cloud, you should install transformers==4.21.0 to be able to use the Hugging Face models.
We have a sample Mongo database that you can connect to your MindsDB Cloud account by running this command in Mongo Shell:
We use this sample database throughout the example.The next step is to create a connection between Mongo and MindsDB. Follow the instructions to connect MindsDB via Mongo Compass or Mongo Shell.Now, we are ready to create a Hugging Face model.
{ sentiment: 'positive', comment: 'I love pizza' }{ sentiment: 'negative', comment: 'I hate dancing' }{ sentiment: 'neutral', comment: 'Baking is not a big deal' }
For the full library of supported examples please go here.