Hayo Launches AI-Powered IoT Platform to Enhance Operations in Developing Markets

It is important to bridge technological gaps in the developing markets. New York City-based global innovator in digital solutions, Hayo, has come up with new Internet of Things (IoT) platform that is designed to support Machine-to-Machine (M2M) and consumer IoT use cases. It is learned to be offering immense potential to mobile network operators (MNOs) […]

Effective Strategies to Safeguard Yourself and Loved Ones from AI Scam Calls

This is a digital age and the rise of artificial intelligence (AI) has brought many conveniences. However, it has also invited some new threats and especially in the form of AI-powered scam calls. The scams are increasingly becoming sophisticated. It is suggested to adopt effective strategies to protect ourselves. Let us explore the evolving world […]

Why does AI hallucinate?

On April 2, the World Health Organization launched a chatbot named SARAH to raise health awareness about things like how to eat well, quit smoking, and more.

But like any other chatbot, SARAH started giving incorrect answers. Leading to a lot of internet trolls and finally, the usual disclaimer: The answers from the chatbot might not be accurate. This tendency to make things up, known as hallucination, is one of the biggest obstacles chatbots face. Why does this happen? And why can’t we fix it?

Let’s explore why large language models hallucinate by looking at how they work. First, making stuff up is exactly what LLMs are designed to do. The chatbot draws responses from the large language model without looking up information in a database or using a search engine.

A large language model contains billions and billions of numbers. It uses these numbers to calculate its responses from scratch, producing new sequences of words on the fly. A large language model is more like a vector than an encyclopedia.

https://medium.com/media/260ffdc0d69d4e1186a4969c41c75c63/href

Large language models generate text by predicting the next word in the sequence. Then the new sequence is fed back into the model, which will guess the next word. This cycle then goes on. Generating almost any kind of text possible. LLMs just love dreaming.

The model captures the statistical likelihood of a word being predicted with certain words. The likelihood is set when a model is trained, where the values in the model are adjusted over and over again until they meet the linguistic patterns of the training data. Once trained, the model calculates the score for each word in the vocabulary, calculating its likelihood to come next.

So basically, all these hyped-up large language models do is hallucinate. But we only notice when it’s wrong. And the problem is that you won’t notice it because these models are so good at what they do. And that makes trusting them hard.

Can we control what these large language models generate? Even though these models are too complicated to be tinkered with, few believe that training them on even more data will reduce the error rate.

You can also ensure performance by breaking responses step-by-step. This method, known as chain-of-thought prompting, can help the model feel confident about the outputs they produce, preventing them from going out of control.

But this does not guarantee 100 percent accuracy. As long as the models are probabilistic, there is a chance that they will produce the wrong output. It is similar to rolling a dice even if you tamper with it to produce a result, there is a small chance it will produce something else.

Another thing is that people believe these models and let their guard down. And these errors go unnoticed. Perhaps, the best fix for hallucinations is to manage the expectations we have of these chatbots and cross-verify the facts.


Why does AI hallucinate? was originally published in Becoming Human: Artificial Intelligence Magazine on Medium, where people are continuing the conversation by highlighting and responding to this story.

How AI and Cloud Technology are Revolutionizing the 2024 Olympics

The Paris 2024 Summer Olympic Games is being said to be a landmark event. The reason is not just for the athletes and their quest for medals. There is another reason. It is the use of technological innovations to enhance the experience for everyone involved. Artificial intelligence (AI) and cloud technology are at the forefront. […]

The Role of AI and IoT in Modern Business

The combination of Artificial Intelligence (AI) and Internet of Things (IoT) devices is changing how businesses work. The two are making businesses more efficient and innovative. The partnership helps companies in various industries to use resources in better-than-before way and improve operations. Simultaneously, the convergence is helping businesses to gain a competitive edge with data-driven […]

Google Cloud Execs Highlight India’s Role in GenAI Revolution

India is emerging as a significant hub for startup innovation. And it is basically driven by the rapid adoption of generative artificial intelligence (GenAI). Google Cloud executives Chen Goldberg and Subram Natarajan lately discussed how Indian startups are leveraging it to drive value and the challenges. Google recognizes the vibrant entrepreneurial ecosystem of India and […]

Nasscom and Meta Partner to Launch Open-Source and Gen AI Startup Challenge

The National Association of Software and Service Companies (NASSCOM) has partnered with Meta to launch the ‘Open-Source Generative AI Grand Challenge.’ The initiative is mainly aimed to inspire startups and developers in utilizing open-source and generative AI technologies in the creation of solutions which are equipped with significant socio-economic impact. The Centre for Development of […]

Unlocking the Power of Hugging Face for NLP Tasks

The field of Natural Language Processing (NLP) has seen significant advancements in recent years, largely driven by the development of sophisticated models capable of understanding and generating human language. One of the key players in this revolution is Hugging Face, an open-source AI company that provides state-of-the-art models for a wide range of NLP tasks. Hugging Face’s Transformers library has become the go-to resource for developers and researchers looking to implement powerful NLP solutions.

Inbound-leads-automatically-with-ai. These models are trained on vast amounts of data and fine-tuned to achieve exceptional performance on specific tasks. The platform also provides tools and resources to help users fine-tune these models on their own datasets, making it highly versatile and user-friendly.

In this blog, we’ll delve into how to use the Hugging Face library to perform several NLP tasks. We’ll explore how to set up the environment, and then walk through examples of sentiment analysis, zero-shot classification, text generation, summarization, and translation. By the end of this blog, you’ll have a solid understanding of how to leverage Hugging Face models to tackle various NLP challenges.

Setting Up the Environment

First, we need to install the Hugging Face Transformers library, which provides access to a wide range of pre-trained models. You can install it using the following command:

!pip install transformers

This library simplifies the process of working with advanced NLP models, allowing you to focus on building your application rather than dealing with the complexities of model training and optimization.

Task 1: Sentiment Analysis

Sentiment analysis determines the emotional tone behind a body of text, identifying it as positive, negative, or neutral. Here’s how it’s done using Hugging Face:

from transformers import pipeline
classifier = pipeline("sentiment-analysis", token = access_token, model='distilbert-base-uncased-finetuned-sst-2-english')
classifier("This is by far the best product I have ever used; it exceeded all my expectations.")

In this example, we use the sentiment-analysis pipeline to classify the sentiments of sentences, determining whether they are positive or negative.

Classifying one single sentence
Classifying multiple sentences

Task 2: Zero-Shot Classification

Zero-shot classification allows the model to classify text into categories without any prior training on those specific categories. Here’s an example:

classifier = pipeline("zero-shot-classification")
classifier(
"Photosynthesis is the process by which green plants use sunlight to synthesize nutrients from carbon dioxide and water.",
candidate_labels=["education", "science", "business"],
)

The zero-shot-classification pipeline classifies the given text into one of the provided labels. In this case, it correctly identifies the text as being related to “science”.

Zero-Shot Classification

Task 3: Text Generation

In this task, we explore text generation using a pre-trained model. The code snippet below demonstrates how to generate text using the GPT-2 model:

generator = pipeline("text-generation", model="distilgpt2")
generator(
"Just finished an amazing book",
max_length=40, num_return_sequences=2,
)

Here, we use the pipeline function to create a text generation pipeline with the distilgpt2 model. We provide a prompt (“Just finished an amazing book”) and specify the maximum length of the generated text. The result is a continuation of the provided prompt.

Text generation model

Task 4: Text Summarization

Next, we use Hugging Face to summarize a long text. The following code shows how to summarize a piece of text using the BART model:

summarizer = pipeline("summarization")
text = """
San Francisco, officially the City and County of San Francisco, is a commercial and cultural center in the northern region of the U.S. state of California. San Francisco is the fourth most populous city in California and the 17th most populous in the United States, with 808,437 residents as of 2022.
"""
summary = summarizer(text, max_length=50, min_length=25, do_sample=False)
print(summary)

The summarization pipeline is used here, and we pass a lengthy piece of text about San Francisco. The model returns a concise summary of the input text.

Text Summarization

Task 5: Translation

In the final task, we demonstrate how to translate text from one language to another. The code snippet below shows how to translate French text to English using the Helsinki-NLP model:

translator = pipeline("translation", model="Helsinki-NLP/opus-mt-fr-en")
translation = translator("L'engagement de l'entreprise envers l'innovation et l'excellence est véritablement inspirant.")
print(translation)

Here, we use the translation pipeline with the Helsinki-NLP/opus-mt-fr-en model. The French input text is translated into English, showcasing the model’s ability to understand and translate between languages.

Text Translation — French to English Language

Conclusion

The Hugging Face library offers powerful tools for a variety of NLP tasks. By using simple pipelines, we can perform sentiment analysis, zero-shot classification, text generation, summarization, and translation with just a few lines of code. This notebook serves as an excellent starting point for exploring the capabilities of Hugging Face models in NLP projects.

Feel free to experiment with different models and tasks to see the full potential of Hugging Face in action!

This brings us to the end of this article. I hope you have understood everything clearly. Make sure you practice as much as possible.

If you wish to check out more resources related to Data Science, Machine Learning, and Deep Learning, you can refer to my GitHub account.

You can connect with me on LinkedIn — Ravjot Singh.

P.S. Claps and follows are highly appreciated.


Unlocking the Power of Hugging Face for NLP Tasks was originally published in Becoming Human: Artificial Intelligence Magazine on Medium, where people are continuing the conversation by highlighting and responding to this story.

Meta Releases Llama 3.1: New Era of Accessible and Customizable AI

Most of the tech giants are aiming to commercialize artificial intelligence (AI). Mark Zuckerberg is taking a different path. His Meta has just unveiled the latest version of its large language model called Llama 3.1. It is made available for free and marks a significant shift in the AI landscape. The exact cost of developing […]

ISRO Celebrates National Space Day with AI and Geospatial Innovation Challenge

India’s space sector has taken a leap forward. Indian Space Research Organisation (ISRO) lately announced ISRO Immersion Startup Challenge initiative in collaboration with IIIT Hyderabad’s National Remote Sensing Centre (NRSC). The event is a significant milestone amid celebration of National Space Day. It is aimed to push the boundaries of space exploration with the help […]