Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
suyashi29
GitHub Repository: suyashi29/python-su
Path: blob/master/Generative NLP Models using Python/Introduction to Generative AI & NLP.ipynb
3074 views
Kernel: Python 3 (ipykernel)

Introduction to Generative AI & NLP

Summary

Generative AI refers to artificial intelligence systems capable of generating text, images, code, audio, or other content using machine learning models. It leverages deep learning, particularly transformer architectures, to produce outputs that mimic human-like understanding and creativity.

Natural Language Processing (NLP) is a subfield of AI focused on enabling machines to understand, interpret, and generate human language. Generative AI models in NLP can perform a wide range of language tasks such as translation, summarization, Q&A, and content creation.


Applications of Generative AI in NLP

  • Text Generation: Writing blogs, poems, or essays (e.g., ChatGPT, Jasper)

  • Summarization: Condensing long documents into concise summaries

  • Translation: Real-time language translation (e.g., Google Translate)

  • Chatbots & Virtual Assistants: Intelligent human-like conversations

  • Code Generation: Generating functional code from natural language prompts

  • Sentiment Analysis: Detecting tone/mood in customer feedback

  • Named Entity Recognition (NER): Extracting key entities from text

  • Question Answering: Automatically answering questions from a text corpus

  • GPT-2 / GPT-3 / GPT-4 (OpenAI)

  • BERT / RoBERTa (Google / Facebook)

  • T5 / BART (Text-to-Text Transformers)

  • LLaMA (Meta AI)

  • BLOOM (BigScience)

Key Concepts

  • Tokenization: Splitting text into words/subwords

  • Embedding: Converting text into numerical vectors

  • Transformer: Neural architecture for handling sequential data

  • Attention Mechanism: Weighing the importance of different words

  • Fine-tuning: Customizing pretrained models for specific tasks

pip install pydantic==1.10.13 anyio==3.7.1
Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.
Note: you may need to restart the kernel to use updated packages.
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. gradio 5.29.1 requires pydantic<2.12,>=2.0, but you have pydantic 1.10.13 which is incompatible.
Collecting pydantic==1.10.13 Obtaining dependency information for pydantic==1.10.13 from https://files.pythonhosted.org/packages/9c/2b/20029a5c58943c0dd19bbf1fda77e820101b63a26237b060217821a3daa3/pydantic-1.10.13-cp311-cp311-win_amd64.whl.metadata Downloading pydantic-1.10.13-cp311-cp311-win_amd64.whl.metadata (150 kB) ---------------------------------------- 0.0/150.9 kB ? eta -:--:-- -------------------------------------- 150.9/150.9 kB 4.5 MB/s eta 0:00:00 Collecting anyio==3.7.1 Obtaining dependency information for anyio==3.7.1 from https://files.pythonhosted.org/packages/19/24/44299477fe7dcc9cb58d0a57d5a7588d6af2ff403fdd2d47a246c91a3246/anyio-3.7.1-py3-none-any.whl.metadata Downloading anyio-3.7.1-py3-none-any.whl.metadata (4.7 kB) Requirement already satisfied: typing-extensions>=4.2.0 in c:\users\suyashi144893\appdata\local\anaconda3\lib\site-packages (from pydantic==1.10.13) (4.12.2) Requirement already satisfied: idna>=2.8 in c:\users\suyashi144893\appdata\local\anaconda3\lib\site-packages (from anyio==3.7.1) (3.4) Requirement already satisfied: sniffio>=1.1 in c:\users\suyashi144893\appdata\local\anaconda3\lib\site-packages (from anyio==3.7.1) (1.2.0) Downloading pydantic-1.10.13-cp311-cp311-win_amd64.whl (2.1 MB) ---------------------------------------- 0.0/2.1 MB ? eta -:--:-- ----- ---------------------------------- 0.3/2.1 MB 8.9 MB/s eta 0:00:01 ------- -------------------------------- 0.4/2.1 MB 6.3 MB/s eta 0:00:01 ------------- -------------------------- 0.7/2.1 MB 5.5 MB/s eta 0:00:01 -------------------- ------------------- 1.1/2.1 MB 6.1 MB/s eta 0:00:01 ------------------------- -------------- 1.4/2.1 MB 6.1 MB/s eta 0:00:01 ----------------------------------- ---- 1.8/2.1 MB 6.9 MB/s eta 0:00:01 ---------------------------------------- 2.1/2.1 MB 6.7 MB/s eta 0:00:00 Downloading anyio-3.7.1-py3-none-any.whl (80 kB) ---------------------------------------- 0.0/80.9 kB ? eta -:--:-- ---------------------------------------- 80.9/80.9 kB 4.4 MB/s eta 0:00:00 Installing collected packages: pydantic, anyio Attempting uninstall: pydantic Found existing installation: pydantic 2.11.4 Uninstalling pydantic-2.11.4: Successfully uninstalled pydantic-2.11.4 Attempting uninstall: anyio Found existing installation: anyio 4.9.0 Uninstalling anyio-4.9.0: Successfully uninstalled anyio-4.9.0 Successfully installed anyio-3.7.1 pydantic-1.10.13
!pip install gradio transformers --quiet import gradio as gr from transformers import pipeline # Load the text generation pipeline generator = pipeline("text-generation", model="gpt2") # Define the Gradio interface def generate_text(prompt): result = generator(prompt, max_length=50, num_return_sequences=1) return result[0]['generated_text'] gr.Interface(fn=generate_text, inputs="text", outputs="text", title="Generative AI Text Generator").launch()
C:\Users\Suyashi144893\AppData\Local\anaconda3\Lib\site-packages\transformers\utils\generic.py:260: FutureWarning: `torch.utils._pytree._register_pytree_node` is deprecated. Please use `torch.utils._pytree.register_pytree_node` instead. torch.utils._pytree._register_pytree_node( C:\Users\Suyashi144893\AppData\Local\anaconda3\Lib\site-packages\huggingface_hub\file_download.py:943: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`. warnings.warn(
* Running on local URL: http://127.0.0.1:7860 * To create a public link, set `share=True` in `launch()`.