DEV Community

AviKKi
AviKKi

Posted on

[Tutorial] State-of-the-art NLP with single line of code 🤗

In the past deep learning has become very easy for common people to use and train; with just a few lines of code you can teach a computer to differentiate between cat and dog photos.

After the introduction of transformers, deep learning models are achieving state of the art results at most of the Natural Language processing tasks, and with Huggingface's 🤗 Pypi library transformers you can now use these deep learning models with a few line of codes.

Below jupyter notebook has the instructions for it -
Jupyter Notebook

My first reaction to it.

Sentiment Analysis

>>> from transformers import pipeline
>>> s = pipeline("sentiment-analysis")
>>> s("Obama is not a bad person")
[{'label': 'POSITIVE', 'score': 0.9990673065185547}]
Enter fullscreen mode Exit fullscreen mode

A tradition model that works on Bag-of-Words would look at the word bad and say the statement is Negative, but this model can understand the meaning of not a bad.

Text Generation

>>> g = pipeline("text-generation")
>>> result  = g("How frustrating it is trying to organize your work using")
>>> print(result[0]['generated_text'])
How frustrating it is trying to organize your work using a calendar

If your plan is to use any calendar at all, you might have one or more of those issues which you can add to your calendar. You can use your calendar to organize activities
>>>
Enter fullscreen mode Exit fullscreen mode

Although this just generates random text, you can add more context in the initial sentence and it is much better than hidden markov chain model.

This can be used for writing articles, captions for your social media posts etc.

Summarization

I summarized first 3 paragraphs of this dev.to article and this was the output

Auto-scaling instances are supposed to handle traffic fluctuation regardless of the number of users and requests.

The unnecessary resources should be eliminated, and the required ones should be triggered following the demand.

Amazon Auto Scaling solves the problem by automatically keeping the currently important instances active and removing the ones that are no longer needed
Enter fullscreen mode Exit fullscreen mode

I can save so much of my time now, summarizing Youtube video's subtitle, and articles in my daily news feed.

Thank you for reading

There is a lot you can do with this library, I'll be writing some tutorials on this in near future, follow me for updates.

Oldest comments (1)

Collapse
 
gilbishkosma profile image
Gilbish

wow, this is cool.