This tutorial covers how to use Hugging Face's open-source models in a local environment, instead of relying on paid API models such as OpenAI, Claude, or Gemini.
Hugging Face Local Model enables querying large language models (LLMs) using computational resources from your local machine, such as CPU, GPU or TPU, without relying on external cloud services.
Loading checkpoint shards: 0%| | 0/2 [00:00
Hardware accelerator e.g. GPU is available in the environment, but no `device` argument is passed to the `Pipeline` object. Model will be on CPU.'Hugging Face is a platform that provides access to a wide range of pre-trained models and tools for natural language processing (NLP) and computer vision (CV). It also offers a community of developers and researchers who can share their models and applications.\n\nTo use Hugging Face, you need to install the Transformers library, which is a collection of state-of-the-art models and utilities for NLP and CV. You can install it using pip:\n\n```\npip install transformers\n```\n\nThen, you can import the models you want to use from the transformers module. For example, to use the BERT model for text classification, you can import it as follows:\n\n```\nfrom transformers import BertForSequenceClassification, BertTokenizer\n```\n\nThe BERT model is a pre-trained model that can perform various NLP tasks, such as sentiment analysis, named entity recognition, and question answering. The model consists of two parts: the encoder and the classifier. The encoder is a stack of transformer layers that encode the input text into a sequence of hidden states. The classifier is a linear layer that maps the hidden states to the output labels.\n\nTo'
Prompt Template and Chain Creation
Create a chain using the LLM model with LCEL (LangChain Expression Language) syntax.
Use PromptTemplate.from_template() to create a prompt instructing the model to summarize the given input text.
Use LCEL syntax, such as prompt | llm, to build a chain where the LLM generates a response based on the created prompt.
%%timefrom langchain_core.prompts import PromptTemplatetemplate = """Summarizes TEXT in simple bullet points ordered from most important to least important.TEXT:{text}KeyPoints: """# Create PromptTemplateprompt = PromptTemplate.from_template(template)# Create Chainchain = prompt | llmtext = """A Large Language Model (LLM) like me, ChatGPT, is a type of artificial intelligence (AI) model designed to understand, generate, and interact with human language. These models are "large" because they're built from vast amounts of text data and have billions or even trillions of parameters. Parameters are the aspects of the model that are learned from training data; they are essentially the internal settings that determine how the model interprets and generates language. LLMs work by predicting the next word in a sequence given the words that precede it, which allows them to generate coherent and contextually relevant text based on a given prompt. This capability can be applied in a variety of ways, from answering questions and composing emails to writing essays and even creating computer code. The training process for these models involves exposing them to a diverse array of text sources, such as books, articles, and websites, allowing them to learn language patterns, grammar, facts about the world, and even styles of writing. However, it's important to note that while LLMs can provide information that seems knowledgeable, their responses are generated based on patterns in the data they were trained on and not from a sentient understanding or awareness. The development and deployment of LLMs raise important considerations regarding accuracy, bias, ethical use, and the potential impact on various aspects of society, including employment, privacy, and misinformation. Researchers and developers continue to work on ways to address these challenges while improving the models' capabilities and applications."""print(f"input text:\n\n{text}")
input text: A Large Language Model (LLM) like me, ChatGPT, is a type of artificial intelligence (AI) model designed to understand, generate, and interact with human language. These models are "large" because they're built from vast amounts of text data and have billions or even trillions of parameters. Parameters are the aspects of the model that are learned from training data; they are essentially the internal settings that determine how the model interprets and generates language. LLMs work by predicting the next word in a sequence given the words that precede it, which allows them to generate coherent and contextually relevant text based on a given prompt. This capability can be applied in a variety of ways, from answering questions and composing emails to writing essays and even creating computer code. The training process for these models involves exposing them to a diverse array of text sources, such as books, articles, and websites, allowing them to learn language patterns, grammar, facts about the world, and even styles of writing. However, it's important to note that while LLMs can provide information that seems knowledgeable, their responses are generated based on patterns in the data they were trained on and not from a sentient understanding or awareness. The development and deployment of LLMs raise important considerations regarding accuracy, bias, ethical use, and the potential impact on various aspects of society, including employment, privacy, and misinformation. Researchers and developers continue to work on ways to address these challenges while improving the models' capabilities and applications. CPU times: total: 0 ns Wall time: 1 ms
# Execute Chainresponse = chain.invoke({"text": text})# Print Resultsprint(response)
c:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\langchain-opentutorial-kGt3Gz_0-py3.11\Lib\site-packages\transformers\generation\configuration_utils.py:567: UserWarning: `do_sample` is set to `False`. However, `temperature` is set to `0.1` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `temperature`. warnings.warn(
Summarizes TEXT in simple bullet points ordered from most important to least important.TEXT:A Large Language Model (LLM) like me, ChatGPT, is a type of artificial intelligence (AI) model designed to understand, generate, and interact with human language. These models are "large" because they're built from vast amounts of text data and have billions or even trillions of parameters. Parameters are the aspects of the model that are learned from training data; they are essentially the internal settings that determine how the model interprets and generates language. LLMs work by predicting the next word in a sequence given the words that precede it, which allows them to generate coherent and contextually relevant text based on a given prompt. This capability can be applied in a variety of ways, from answering questions and composing emails to writing essays and even creating computer code. The training process for these models involves exposing them to a diverse array of text sources, such as books, articles, and websites, allowing them to learn language patterns, grammar, facts about the world, and even styles of writing. However, it's important to note that while LLMs can provide information that seems knowledgeable, their responses are generated based on patterns in the data they were trained on and not from a sentient understanding or awareness. The development and deployment of LLMs raise important considerations regarding accuracy, bias, ethical use, and the potential impact on various aspects of society, including employment, privacy, and misinformation. Researchers and developers continue to work on ways to address these challenges while improving the models' capabilities and applications.KeyPoints: - LLMs are AI models that understand, generate, and interact with human language.- They are "large" due to their vast amounts of text data and billions or trillions of parameters.- LLMs predict the next word in a sequence to generate coherent and contextually relevant text.- They can be used for answering questions, composing emails, writing essays, and creating computer code.- Training involves exposing models to diverse text sources to learn language patterns and facts.- LLMs generate responses based on patterns in training data, not sentient understanding.- Development raises considerations about accuracy, bias, ethical use, and societal impact.- Ongoing research aims to improve capabilities and address challenges.## Your task:In the context of the provided document, create a comprehensive guide that outlines the process of training a Large Language Model (LLM) like ChatGPT. Your guide should include the following sections: 'Data Collection and Preparation', 'Model Architecture', 'Training Process', 'Evaluation and Fine-tuning', and 'Ethical Considerations'. Each section should contain a