In the realm of natural language processing (NLP) technology, we encounter different models serving distinct purposes. There are both free and paid models available. In the paid section, the OpenAI Library provides a range of models, all of which are grounded in the transformer architecture. Over time, numerous models have been developed based on the transformer, an advanced architecture that has been meticulously trained on extensive datasets to comprehend and generate human-like text. BLOOM, a cutting-edge model built on this transformer architecture, demonstrates exceptional proficiency in tasks such as token classification and question-answering. I created a Q&A model using Gemini Pro and Langchain, underscoring its versatility for developers, researchers, and businesses seeking to leverage the capabilities of state-of-the-art NLP.
BLOOM offers a free model that stands out for its enhanced power and accuracy, owing to its training on large datasets. This makes it an ideal choice for applications like conversational chatbots, where grasping the subtleties of language is paramount. BLOOM not only showcases the latest AI advancements but also empowers users to construct intelligent, context-aware applications that elevate user interactions and redefine the landscape of conversational AI.
This article was published as a part of the Data Science Blogathon.
BLOOM is a Large Language Model (LLM), and a remarkable aspect of its development is the involvement of 1000 researchers spanning over 70 countries, with 250+ institutions participating. This collaborative effort, unprecedented in the field of generative AI, focuses on creating a freely accessible LLM. Unlike other LLMs, the researchers aim to make the model freely available for use by small companies and academic students. Trained on the Jean Zay supercomputer in Paris, BLOOM boasts 176 billion parameters and the ability to generate text in 46 natural languages and 13 programming languages. This release represents a significant stride in making advanced language models accessible to a broader audience, encouraging collaboration, and providing researchers with the opportunity to explore the inner workings of the model.
BLOOM, a large language model (LLM), is based on the Transformer architecture. In the context of the Transformer, this architecture elevates generative AI, or NLP, to the next level. This architecture follows the decoder-only concept. Unlike the old encoder-decoder architecture, the Transformer employs only the decoder on both sides. ‘Decoder-only’ implies a focus on predicting the next token in a sequence, akin to models like GPT. The model has been trained with over 100 billion parameters, establishing it as a state-of-the-art language model (LLM).
Feature | BLOOM | Other LLMs |
---|---|---|
Multilingual Capability | 46 natural languages, 13 programming languages | Varies, some focus on specific languages |
Collaborative Development | Involves 1000+ researchers from 70+ countries | Developed by individual companies or labs |
Transparency and Accessibility | Released with a focus on transparency and accessibility | Varies, some may have restrictions on usage |
Training Details | Trained with 176 billion parameters | Varies in parameter size, training duration |
Model Architecture | Causal decoder-only architecture | Varies (encoder-only, decoder-only, etc.) |
Free Access and Responsible AI | Released with a Responsible AI License, fostering collaboration | Licensing models and usage restrictions may differ(OpenAI) |
conda create -p ./venv python=3.8 -y
Virtual Environment Activation: Activate the virtual environment:
conda activate ./env
## Creating requirements.txt
touch requirements.txt
## inside the requirements.text file
""""
streamlit
notebook
transformers
"""
## Install the packages
pip install -r requirements.txt
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
## Importing the libraries
from transformers import AutoTokenizer, AutoModelForCausalLM
# Replace with the desired BLOOM model
model_name = "bigscience/bloom-560m"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
def initialize_model(model_name):
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
return tokenizer, model
def generate_response(model, tokenizer, user_input, max_length=50):
input_ids = tokenizer.encode(user_input, return_tensors="pt")
output = model.generate(input_ids, max_length=max_length, num_beams=5, no_repeat_ngram_size=2)
response = tokenizer.decode(output[0], skip_special_tokens=True)
return response
def chatbot_interaction(model, tokenizer):
print("Chatbot: Hello! I'm a BLOOM-based chatbot. Type 'exit' to end the conversation.")
while True:
user_input = input("You: ")
if user_input.lower() == 'exit':
print("Chatbot: Goodbye!")
break
response = generate_response(model, tokenizer, user_input)
print("Chatbot:", response)
chatbot_interaction(model, tokenizer)
In the output, check the upper red box. In this box, we want to write our query for interacting with the chatbot. The bottom red box shows that the chatbot model has been successfully initialized.
In the red box, the output is printed. We can also print the complete output according to the token creation. For the above, we can mention (max_length=50).
To create a simple Streamlit application for your BLOOM-based chatbot, follow these steps:
touch main.py
# main.py
import streamlit as st
from transformers import AutoTokenizer, AutoModelForCausalLM
# Function to initialize BLOOM model
def initialize_model(model_name):
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
return tokenizer, model
# Function to generate response
def generate_response(model, tokenizer, user_input, max_length=50):
input_ids = tokenizer.encode(user_input, return_tensors="pt")
output = model.generate(input_ids, max_length=max_length, num_beams=5, no_repeat_ngram_size=2)
response = tokenizer.decode(output[0], skip_special_tokens=True)
return response
def main():
st.title("BLOOM Chatbot")
# Choose BLOOM model
model_name = st.selectbox("Select BLOOM Model", ["bigscience/bloom-560m", "other/bloom-model"])
tokenizer, model = initialize_model(model_name)
st.sidebar.markdown("## Conversation")
# Interactive chat
user_input = st.text_input("You:")
if user_input:
response = generate_response(model, tokenizer, user_input)
st.text_area("Chatbot:", value=response, height=100)
if __name__ == "__main__":
main()
streamlit run streamlit_chatbot.py
Here, we observe the UI of our application. We inquire about machine learning, and the model predicts the correct answer. Note that the output is approximately 50 words, and you can adjust it based on your requirements.
Note: Follow on GitHub for the complete code.
BLOOM represents a groundbreaking contribution to generative AI and natural language processing, boasting an impressive 176 billion parameters. This extensive parameter count underscores the model’s ability to process and generate vast amounts of data. Another notable aspect is BLOOM’s provision as a free and open-source model, emphasizing accessibility and collaboration within the AI community.
As a large language model (LLM), BLOOM excels in text-to-text generation, taking on tasks such as causal language modeling, text classification, token classification, and question answering. Our practical section delves into hands-on experiences, guiding users through the process of building with BLOOM, including parameter adjustments like stop word criteria.
A. BLOOM is a 176-billion-parameter language model trained on 46 natural languages and 13 programming languages.
A. BLOOM is transparent and accessible, aiming to democratize access to advanced language models.
A. BLOOM is versatile, and used for text-to-text generation, text classification, token classification, and question-answering.
A. Developed collaboratively by 1000+ researchers from 70+ countries, trained on Jean Zay supercomputer in Paris.
A. Yes, BLOOM is open-source, allowing researchers and developers to download, run, and study it.
The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.