Zephyrnet Logo

Analyse Twitter Streaming data with Node.js & free NLP API

Date:

NLP Model Setup & usage of Thadeus NPM package

First step is behind us, now let’s create an account in Thadeus AI platform and teach our NLP model.

For now let us pause the development part in order to prepare and teach our model. Please let me quickly explain how ThadeusAi works.

Go to Thadeus AI, create an account and login in a dashboard. After logging into the dashboard, you have to create a “Workspace” — it’s a single NLP model. In your workspace management page, you create intents with at least 5 examples. You can think about intents like they were message categories. For example, you can create an intent “love” and provide many tweets (in our case) which are saying that Cyberpunk 2077 is a great game. Hopefully the below screenshots of my trained model will help you to imagine how it works.

And examples used in my intent:

Of course, the more examples in intents, the better the model works, so 5 is an absolute minimum. After a new intent is added, remember to re-train your AI. Note that you can also use “Test Talk” to test your model anytime.

You can also add examples with Thadeus API. For instance, you can create intents examples from a CSV file instead of manually adding them in the dashboard.

What is more, the team from ThadeusAI also prepared an NPM package so it’s really simple to integrate with your Node.js application.

Once you have your model prepared and taught, let’s move back to our application and add intent recognition with our trained model.

const { Thadeus } = require('thadeus');const thadeus = new Thadeus({
apiSecret: process.env.THADEUS_API_SECRET,
apiKey: process.env.THADEUS_API_KEY,
workspaceId: process.env.THADEUS_WORKSPACE_ID,
});

Initialise the Thadeus client with your workspace credentials and id (generated in ThadeusAI dashboard).

const stream = client.stream('statuses/filter', {track: 'cyberpunk', tweet_mode: 'extended', language: 'en'});stream.on('data', async (data) => {
if (!data.retweeted_status) {
const tweetText = data?.extended_tweet?.full_text || data.text;
console.log('tweet', tweetText);
const predictions = await thadeus.predictIntents(tweetText);
console.log('predictions', predictions);
console.log('n===============n');
}
});

I have updated our previous code with the predict intents method. Now every tweet will be sent to our NLP model and it will return predictions about intents. ThadeusAI also offers entity recognition, but for now it only works with predefined ones for every workspace. Some time in the near future, Thadeus is likely to add custom entities support which should be working similarly to intents.

Source: https://chatbotslife.com/analyse-twitter-streaming-data-with-node-js-free-nlp-api-25e528157bdb?source=rss—-a49517e4c30b—4

spot_img

Latest Intelligence

spot_img