> ## Documentation Index
> Fetch the complete documentation index at: https://pearsdb.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Nlp extended examples

<Tip>
  Actualmente, el motor de NLP de MindsDB está impulsado por [Hugging Face](https://huggingface.co/) y [OpenAI](https://openai.com/). Pero planeamos expandirnos a otras opciones de NLP en el futuro, ¡así que estén atentos!
</Tip>

<Tip>
  El motor de Hugging Face de MindsDB es extensible. Estamos trabajando activamente en agregar más tareas y modelos.
  Si tienes una tarea o modelo específico en mente, háganoslo saber en la [Comunidad de MindsDB](https://community.mindsdb.com/).
</Tip>

## Ejemplos de Hugging Face

Aquí están las tareas soportadas por MindsDB y Hugging Face:

* Clasificación de Texto
* Clasificación Zero-Shot
* Traducción
* Resumen

Veamos los ejemplos.

### Clasificación de Texto

<AccordionGroup>
  <Accordion title="Spam">
    Vamos a crear un modelo.

    ```sql theme={null}
    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'];
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_spam;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    SELECT *
    FROM mindsdb.hf_spam
    WHERE text = 'I like you. I love you.';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +----+--------------------------------------------------------+-----------------------+
    |PRED|PRED_explain                                            |text                   |
    +----+--------------------------------------------------------+-----------------------+
    |spam|{"ham":0.00020051795581821352,"spam":0.9997995495796204}|I like you. I love you.|
    +----+--------------------------------------------------------+-----------------------+
    ```
  </Accordion>

  <Accordion title="Sentimiento">
    Vamos a crear un modelo.

    ```sql theme={null}
    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'];
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_sentiment;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    SELECT *
    FROM mindsdb.hf_sentiment
    WHERE text = 'I like you. I love you.';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +----+--------------------------------------------------------------------------------+-----------------------+
    |PRED|PRED_explain                                                                    |text                   |
    +----+--------------------------------------------------------------------------------+-----------------------+
    |pos |{"neg":0.003046575468033552,"neu":0.021965451538562775,"pos":0.9749879240989685}|I like you. I love you.|
    +----+--------------------------------------------------------------------------------+-----------------------+
    ```
  </Accordion>

  <Accordion title="Sentimiento (Finanzas)">
    Vamos a crear un modelo.

    ```sql theme={null}
    CREATE MODEL mindsdb.hf_sentiment_finance
    PREDICT PRED
    USING
    engine = 'huggingface',
    task = 'text-classification',
    model_name = 'ProsusAI/finbert',
    input_column = 'text';
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_sentiment_finance;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    SELECT *
    FROM mindsdb.hf_sentiment_finance
    WHERE text = 'Stocks rallied and the British pound gained.';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +--------+-------------------------------------------------------------------------------------------+--------------------------------------------+
    |PRED    |PRED_explain                                                                               |text                                        |
    +--------+-------------------------------------------------------------------------------------------+--------------------------------------------+
    |positive|{"negative":0.0344734713435173,"neutral":0.06716493517160416,"positive":0.8983616232872009}|Stocks rallied and the British pound gained.|
    +--------+-------------------------------------------------------------------------------------------+--------------------------------------------+
    ```
  </Accordion>

  <Accordion title="Emociones (6)">
    Vamos a crear un modelo.

    ```sql theme={null}
    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';
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_emotions_6;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    SELECT *
    FROM mindsdb.hf_emotions_6
    WHERE text = 'Oh Happy Day';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+
    |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|
    +----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+
    ```
  </Accordion>

  <Accordion title="Toxicidad">
    Vamos a crear un modelo.

    ```sql theme={null}
    CREATE MODEL mindsdb.hf_toxicity
    PREDICT PRED
    USING
    engine = 'huggingface',
    task = 'text-classification',
    model_name = 'SkolkovoInstitute/roberta_toxicity_classifier',
    input_column = 'text';
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_toxicity;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    SELECT *
    FROM mindsdb.hf_toxicity
    WHERE text = 'I like you. I love you.';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +-------+-------------------------------------------------------------+-----------------------+
    |PRED   |PRED_explain                                                 |text                   |
    +-------+-------------------------------------------------------------+-----------------------+
    |neutral|{"neutral":0.9999547004699707,"toxic":0.00004535282641882077}|I like you. I love you.|
    +-------+-------------------------------------------------------------+-----------------------+
    ```
  </Accordion>

  <Accordion title="ESG (6)">
    Vamos a crear un modelo.

    ```sql theme={null}
    CREATE MODEL mindsdb.hf_esg_6
    PREDICT PRED
    USING
    engine = 'huggingface',
    task = 'text-classification',
    model_name = 'yiyanghkust/finbert-esg',
    input_column = 'text';
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_esg_6;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    SELECT * FROM  mindsdb.hf_esg_6
    WHERE text = 'Rhonda has been volunteering for several years for a variety of charitable community programs.';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +------+---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------+
    |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.|
    +------+---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------+
    ```
  </Accordion>

  <Accordion title="ESG (26)">
    Vamos a crear un modelo.

    ```sql theme={null}
    CREATE MODEL mindsdb.hf_esg_26
    PREDICT PRED
    USING
    engine = 'huggingface',
    task = 'text-classification',
    model_name = 'yiyanghkust/finbert-esg',
    input_column = 'text';
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_esg_26;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    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.';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +------+-----------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |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.|
    +------+-----------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    ```
  </Accordion>

  <Accordion title="Discurso de Odio">
    Vamos a crear un modelo.

    ```sql theme={null}
    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';
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_hate;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    SELECT *
    FROM mindsdb.hf_hate
    WHERE text = 'I like you. I love you.';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +------+-----------------------------------------------------------------------------------------------+-----------------------+
    |PRED  |PRED_explain                                                                                   |text                   |
    +------+-----------------------------------------------------------------------------------------------+-----------------------+
    |normal|{"hate speech":0.03551718592643738,"normal":0.7747423648834229,"offensive":0.18974047899246216}|I like you. I love you.|
    +------+-----------------------------------------------------------------------------------------------+-----------------------+
    ```
  </Accordion>

  <Accordion title="Señales de Compra de Criptomonedas">
    Vamos a crear un modelo.

    ```sql theme={null}
    CREATE MODEL mindsdb.hf_crypto
    PREDICT PRED
    USING
    engine = 'huggingface',
    task = 'text-classification',
    model_name = 'ElKulako/cryptobert',
    input_column = 'text';
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_crypto;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    SELECT *
    FROM mindsdb.hf_crypto
    WHERE text = 'BTC is killing it right now';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +-------+------------------------------------------------------------------------------------------+---------------------------+
    |PRED   |PRED_explain                                                                              |text                       |
    +-------+------------------------------------------------------------------------------------------+---------------------------+
    |Bullish|{"Bearish":0.0002816587220877409,"Bullish":0.559426486492157,"Neutral":0.4402918517589569}|BTC is killing it right now|
    +-------+------------------------------------------------------------------------------------------+---------------------------+
    ```
  </Accordion>

  <Accordion title="Partido Político de EE.UU.">
    Vamos a crear un modelo.

    ```sql theme={null}
    CREATE MODEL mindsdb.hf_us_party
    PREDICT PRED
    USING
    engine = 'huggingface',
    task = 'text-classification',
    model_name = 'm-newhauser/distilbert-political-tweets',
    input_column = 'text';
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_us_party;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    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.';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +--------+-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |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.|
    +--------+-------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    ```
  </Accordion>

  <Accordion title="Detección de Preguntas">
    Vamos a crear un modelo.

    ```sql theme={null}
    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'];
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_question;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    SELECT *
    FROM mindsdb.hf_question
    WHERE text = 'Where can I buy electronics in London';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +-----+--------------------------------------------------------------+-------------------------------------+
    |PRED |PRED_explain                                                  |text                                 |
    +-----+--------------------------------------------------------------+-------------------------------------+
    |query|{"query":0.9997773766517639,"question":0.00022261829872149974}|Where can I buy electronics in London|
    +-----+--------------------------------------------------------------+-------------------------------------+
    ```
  </Accordion>

  <Accordion title="Industria">
    Vamos a crear un modelo.

    ```sql theme={null}
    CREATE MODEL mindsdb.hf_industry
    PREDICT PRED
    USING
    engine = 'huggingface',
    task = 'text-classification',
    model_name = 'sampathkethineedi/industry-classification',
    input_column = 'text';
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_industry;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    SELECT *
    FROM mindsdb.hf_industry
    WHERE text = 'Low latency is one of our best cloud features';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
    |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|
    +----------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
    ```
  </Accordion>
</AccordionGroup>

### Clasificación Zero-Shot

<AccordionGroup>
  <Accordion title="Bart">
    Vamos a crear un modelo.

    ```sql theme={null}
    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'];
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_zs_bart;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    SELECT *
    FROM mindsdb.hf_zs_bart
    WHERE text = 'Paper Plane Design Framed Wall Hanging Motivational Office Decor Art Prints';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +---------+------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
    |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|
    +---------+------------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
    ```
  </Accordion>
</AccordionGroup>

### Traducción

<AccordionGroup>
  <Accordion title="Inglés a Francés (T5)">
    Vamos a crear un modelo.

    ```sql theme={null}
    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';
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_t5_en_fr;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    SELECT *
    FROM mindsdb.hf_t5_en_fr
    WHERE text = 'The monkey is on the branch';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +---------------------------+---------------------------+
    |PRED                       |text                       |
    +---------------------------+---------------------------+
    |Le singe est sur la branche|The monkey is on the branch|
    +---------------------------+---------------------------+
    ```
  </Accordion>
</AccordionGroup>

### Resumen

<AccordionGroup>
  <Accordion title="Bart">
    Vamos a crear un modelo.

    ```sql theme={null}
    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;
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_bart_sum_20;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    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.';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |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.|
    +-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    ```
  </Accordion>

  <Accordion title="Google Pegasus">
    Vamos a crear un modelo.

    ```sql theme={null}
    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;
    ```

    Y comprobemos su estado.

    ```sql theme={null}
    DESCRIBE hf_peg_sum_20;
    ```

    Una vez que el estado es `complete`, podemos consultar para obtener predicciones.

    ```sql theme={null}
    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.';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |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.|
    +------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    ```
  </Accordion>
</AccordionGroup>

## Ejemplos de OpenAI

Aquí están las tareas soportadas por MindsDB y OpenAI:

* Responder Preguntas sin Contexto
* Responder Preguntas con Contexto
* Completar Prompt

<Note>
  Sigue [esta instrucción](/integrations/ai-engines/openai#setup) para configurar la integración de OpenAI en MindsDB.
</Note>

Veamos los ejemplos.

### Responder Preguntas sin Contexto

<AccordionGroup>
  <Accordion title="Responder Preguntas sin Contexto">
    Vamos a crear un modelo.

    ```sql theme={null}
    CREATE MODEL project_a.openai_test_a
    PREDICT answer
    USING
        engine = 'openai',
        question_column = 'question';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    Query successfully completed
    ```

    Ahora podemos consultar para obtener respuestas.

    ```sql theme={null}
    SELECT question, answer
    FROM project_a.openai_test_a
    WHERE question = 'Where is Stockholm located?';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +---------------------------+-------------------------------+
    |question                   |answer                         |
    +---------------------------+-------------------------------+
    |Where is Stockholm located?|Stockholm is located in Sweden.|
    +---------------------------+-------------------------------+
    ```
  </Accordion>
</AccordionGroup>

### Responder Preguntas con Contexto

<AccordionGroup>
  <Accordion title="Responder Preguntas con Contexto">
    Vamos a crear un modelo.

    ```sql theme={null}
    CREATE MODEL project_a.openai_test_b
    PREDICT answer
    USING
        engine = 'openai',
        question_column = 'question',
        context_column = 'context';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    Query successfully completed
    ```

    Ahora podemos consultar para obtener respuestas.

    ```sql theme={null}
    SELECT context, question, answer
    FROM project_a.openai_test_b
    WHERE context = 'Answer with a joke'
    AND question = 'How to cook soup?';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +-------------------+------------------+---------------------------------------------------------+
    |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!|
    +-------------------+------------------+---------------------------------------------------------+
    ```
  </Accordion>
</AccordionGroup>

### Completar Prompt

<AccordionGroup>
  <Accordion title="Completar Prompt con Parámetros Proporcionados en el Momento de la Creación">
    Vamos a crear un modelo.

    ```sql theme={null}
    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;
    ```

    Veamos un ejemplo que utiliza parámetros proporcionados en el momento de la creación del modelo.

    ```sql theme={null}
    SELECT context, question, answer
    FROM project_a.openai_test_c
    WHERE context = 'Answer accurately'
    AND question = 'How many planets exist in the solar system?';
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +-------------------+-------------------------------------------+----------------------------------------------+
    |context            |question                                   |answer                                        |
    +-------------------+-------------------------------------------+----------------------------------------------+
    |Answer accurately  |How many planets exist in the solar system?| There are eight planets in the solar system. |
    +-------------------+-------------------------------------------+----------------------------------------------+
    ```
  </Accordion>

  <Accordion title="Completar Prompt con Parámetros Proporcionados en el Momento de la Predicción">
    Vamos a crear un modelo.

    ```sql theme={null}
    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;
    ```

    Veamos un ejemplo que anula los parámetros en el momento de la predicción.

    ```sql theme={null}
    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;
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |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.|
    +----------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    ```
  </Accordion>

  <Accordion title="Clasificación de Sentimiento">
    Vamos a crear un modelo.

    ```sql theme={null}
    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';
    ```

    Ahora podemos consultar para obtener predicciones.

    ```sql theme={null}
    SELECT output.sentiment, input.review
    FROM example_db.demo_data.amazon_reviews AS input
    JOIN mindsdb.sentiment_classifier AS output
    LIMIT 3;
    ```

    Al ejecutar, obtenemos:

    ```sql theme={null}
    +----------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | 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.                                                                                                                                                                                                                           |
    +----------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    ```
  </Accordion>
</AccordionGroup>

## ¿Qué sigue?

¡Diviértete mientras lo pruebas tú mismo!

* Marca como favorito el [repositorio de MindsDB en GitHub](https://github.com/mindsdb/mindsdb).
* Regístrese para obtener una [cuenta gratuita de MindsDB](https://cloud.mindsdb.com/register/nlp).
* Interactúe con la comunidad de MindsDB en

  [Slack](https://mindsdb.com/joincommunity) o

  [GitHub](https://github.com/mindsdb/mindsdb/discussions) para hacer preguntas y
  compartir sus ideas y pensamientos.

Si este tutorial fue útil, por favor denos una estrella en GitHub

[aquí](https://github.com/mindsdb/mindsdb).
