DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Build a Multilingual Chatbot With FastAPI and Google Cloud Translation
  • Snowflake Cortex Analyst: Unleashing the Power of Conversational AI for Text-to-SQL
  • Building an Interactive Chatbot With Streamlit, LangChain, and Bedrock
  • Mastering AI Agents: How Agentic Design Patterns Make Agents Smarter

Trending

  • Comparing SaaS vs. PaaS for Kafka and Flink Data Streaming
  • Emerging Data Architectures: The Future of Data Management
  • Mastering React App Configuration With Webpack
  • Chaos Engineering for Microservices
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Chatbot for Customer Support

Chatbot for Customer Support

These days there are many use cases for conversational AI. In the following article, we go through implementing a chatbot using Java and Apache OpenNLP.

By 
Ima Miri user avatar
Ima Miri
·
Mar. 12, 21 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
9.0K Views

Join the DZone community and get the full member experience.

Join For Free

These days there are many use cases for conversational AI. Conversational AI refers to the use of messaging apps, speech-based assistants, and chatbots to automate communication and create personalized customer experiences at scale. In this article, you will learn about the chatbot.

In the following project, we go through implementing a chatbot using Java and Apache OpenNLP.

Apache OpenNLP

Apache OpenNLP is an open-source Java library that is used to process Natural Language text. Apache OpenNLP provides various services such as the following:

  • Tokenization
  • Part of speech tagging
  • Sentence segmentation
  • Chunking
  • Parsing
  • Named entity extraction
  • Co-reference resolution

How Chatbot Works

Firstly, the user sends a message and the chatbot will reply, but how it works? A chatbot can be used for different scenarios based on business requirements. The most common use cases are customer support, search to buy and sell, booking.

In the chatbot project that I worked on, there were two main scenarios for the chatbot, one customer support and another one search an item. I will cover the chatbot for customer support in this article and search for an item in another article.

Customer Support Scenario

In this scenario, the user asks the chatbot for reporting an issue or for help on how to work with the website. Based on our business needs, we had multiple scenarios to cover. Therefore, we needed to reply to the user correctly based on the type of questions. Here are two main steps we took to provide the best reply to user message

1. Training the Data

Here are some of the examples of categories we covered:

  • SCAM_LOSTMONEY: Didn't pay for it.
  • SCAM_LOSTMONEY: Didn't ship.
  • SMS_FRAUD: This got a weird SMS.
  • SMS_FRAUD: This a fake reply.
  • SMS_FRAUD: Received a strange message.
  • REPORT_AD: This is against policies.
  • REPORT_AD: This is violating policy.
  • ACCOUNTS I am not able to sign in.
  • ACCOUNTS I can't log in.

To train the data, we used DocumentCategorizerMe.  DocumentCategorizerMe gets a txt file and generates a training set in .bin format. Here is the code:

Java
 




x
17


 
1
final Optional trainingFile = getTrainingFile(“model.txt”);
2

          
3
final DoccatModel model = trainAndGetCategoryModel(trainingFile.get(), 3);
4

          
5
final InputStreamFactory factory = new MarkableFileInputStreamFactory(convertPathToTempFile(trainingFile));
6

          
7
final ObjectStream lineStream = new PlainTextByLineStream(factory, "UTF-8"
8
);
9

          
10
final TrainingParameters parameters = ModelUtil.createDefaultTrainingParameters();
11
parameters.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(trainingCutoff));
12

          
13
this.categoriser = DocumentCategorizerME.train(
14
        "en", new DocumentSampleStream(lineStream),
15
        parameters,
16
        new DoccatFactory()
17
    );



2. Scoring the Category

It’s required that the chatbot provides the best reply to users. Due to multiple categories to cover the customer support message, we needed to make sure that the chosen category has the highest confidence. The following code shows how to score the category using DocumentCategorizerMe.scoreMap():

Java
 




xxxxxxxxxx
1


 
1

          
2
final Optional> result = this.categoriser.scoreMap(inputMessage).entrySet()
3
        .stream()
4
        .filter(e -> NumberUtils.compare(e.getValue(), scoreThreshold) >= 0)
5
        .max((e1, e2) -> e1.getValue().compareTo(e2.getValue()));



Based on the above code, if the user message is “Is this a fake message?”, the highest score should be for SMS_FRAUD and not the REPORT_AD. And, the chatbot can simply reply to the user.

Example Chatbot scenario infographic.

This was only one use case of the chatbot.

Chatbot

Opinions expressed by DZone contributors are their own.

Related

  • Build a Multilingual Chatbot With FastAPI and Google Cloud Translation
  • Snowflake Cortex Analyst: Unleashing the Power of Conversational AI for Text-to-SQL
  • Building an Interactive Chatbot With Streamlit, LangChain, and Bedrock
  • Mastering AI Agents: How Agentic Design Patterns Make Agents Smarter

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!