Wednesday, July 29, 2020

Solve NLP task : PyTorch Transformer Pipeline





Question answering (QA) is a computer science discipline within the fields of information retrieval and natural language processing (NLP), which is concerned with building systems that automatically answer questions posed by humans in a natural language.

Sentiment analysis (SA) is the interpretation and classification of emotions (positive, negative and neutral) within text data using text analysis techniques. Sentiment analysis tools allow businesses to identify customer sentiment toward products, brands or services in online feedback.


Here we are going to try out the PyTorch based transformer pipeline (deep learning NLP) to use the SQuAD from Stanford (References [1]).


# Q&A pipeline
!pip install qq transformers 
from transformers import pipeline
qapipe = pipeline('question-answering')
qapipe({
 'question': """how can question answering service produce answers""",
 'context': """One such task is reading comprehension. Given a passage of text, we can ask questions about the passage that can be answered by referencing short excerpts from the text. For instance, if we were to ask about this paragraph, "how can a question be answered in a reading comprehension task" ..."""
})

Output:

{'score': 0.38941961529900837,
 'start': 128,
 'end': 169,
 'answer': 'referencing short excerpts from the text.'}


# Sentiment Analysis pipeline
from transformers import pipeline 
sentiment_pipe= pipeline('sentiment-analysis') 
sentiment_pipe ("I sure would like to see a resurrection of a up dated Seahunt series with the tech they have today it would bring back the kid excitement in me.I grew up on black and white TV and Seahunt with Gunsmoke were my hero's every week.You have my vote for a comeback of a new sea hunt.We need a change of pace in TV and this would work for a world of under water adventure.Oh by the way thank you for an outlet like this to view many viewpoints about TV and the many movies.So any ole way I believe I've got what I wanna say.Would be nice to read some more plus points about sea hunt.If my rhymes would be 10 lines would you let me submit,or leave me out to be in doubt and have me to quit,If this is so then I must go so lets do it.")

Output:
[{'label': 'POSITIVE', 'score': 0.91602623462677}]


Experiments: Above Python codes tried under Google Colab. You can try other pipelines like NER (Named Entity Recognition), Feature Extraction. The Huggingface link is useful References[2].

Conclusion:
With the advancement of deep learning in NLP is rapidly growing, via transformer driven architectures, 
it's pretty convenient to use with minimal coding and put these models in practice, while maintaining higher accuracy
for a given NLP task. In order to use the existing model for a custom data sets, and then do epochs(train/test) on that
custom data sets, that also feasible and most of cases, you can achieve higher accuracy than the 
baseline model. So keep exploring the new transformer based models!

References:
1. The Stanford data set for Q&A is available here. https://rajpurkar.github.io/SQuAD-explore
2. More on Transformer Pipeline: https://huggingface.co/transformers/main_classes/pipelines.html


3 comments:

tejaswini said...

It's instructive and you are clearly entirely educated here. You have made me fully aware of differing sees on this point with fascinating and strong substance.datascience course malaysia

360DigiTMG said...

Its most perceptibly horrendous piece was that the item just worked spasmodically and the data was not exact. You unmistakably canot confront anyone about what you have found if the information isn't right.
training provider in malaysia

AI Courses said...

I need to communicate my deference of your composing aptitude and capacity to make perusers read from the earliest starting point as far as possible. I might want to peruse more up to date presents and on share my musings with you.

https://360digitmg.com/course/artificial-intelligence-ai-and-deep-learning