<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <a href="https
Step1:  Key Phrase Extraction - Keybert
italicised text
bold text
Step2:  Sentiment Analysis - Huggingface
Step3:  Zero Shot Classification - Huggingface
Step4:  Few Shot Classification - Huggingface
NOTE 
Step5:  Named Entity Extraction - Huggingface
Step6:  Question Answering
<ASSISTANT_TASK:>
Python Code:
!pip install transformers
!pip install torch
!pip install keybert
Explanation: <a href="https://colab.research.google.com/github/peterhanlon/botdefender/blob/master/ECI_Presentation.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
Examples from the ECI presentation on Natural Language Processing
End of explanation
from keybert import KeyBERT
kw_model = KeyBERT()
document='''
My electricity isn't working, and I've not had any power for five hours, can you send someone to fix it please.
'''
kw_model.extract_keywords(document, keyphrase_ngram_range=(1, 3), stop_words='english')
Explanation: Key Phrase Extraction - Keybert
italicised text
bold text
End of explanation
from transformers import pipeline
sentiment_pipeline = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion")
data = ["The product is amazing, I really love it", "I was really frustrated they didn't get back to me"]
sentiment_pipeline(data)
Explanation: Sentiment Analysis - Huggingface
End of explanation
from transformers import pipeline
classification_pipeline = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
candidate_labels = ["renewable", "politics", "emissions", "temperature","emergency","advertisement"]
sentence = ["The smoke from the car exhaust was unbearable"]
classification_pipeline (sentence, candidate_labels)
Explanation: Zero Shot Classification - Huggingface
End of explanation
from transformers import pipeline
examples='''
sentence: "My car needs a service"
intent: repair
###
sentence: "My car is dirty"
intent: valet
###
sentence: "I want to sell my car"
intent: sale
###
sentence: "My cars engine is making a funny noise"
intent:'''
generator = pipeline('text-generation', model='EleutherAI/gpt-neo-2.7B')
generator(examples, do_sample=True, max_new_tokens=3, temperature=0.1, end_sequence="###")
Explanation: Few Shot Classification - Huggingface
NOTE : This seems to be too large for free colab, if you have a PC with plenty of memory it will work
End of explanation
from transformers import pipeline
classification_pipeline = pipeline("ner", model="dbmdz/bert-large-cased-finetuned-conll03-english")
sentence = ["Pete wanted to go to London to present NLP stuff for ECI"]
classification_pipeline (sentence)
Explanation: Named Entity Extraction - Huggingface
End of explanation
from transformers import pipeline
classification_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
document="A reusable launch system (RLS, or reusable launch vehicle RLV) is a launch system which is capable of launching a payload into space more than once."
question = ["Whas it an RLS"]
classification_pipeline (question=question, context=document)
Explanation: Question Answering
End of explanation
<END_TASK>