Transformers from HuggingFace :)
Introducing transformers.
- Sentiment analysis
- Zero-shot classification
- Text generation
- Mask filling
- Named entity recognition
- Question answering
- Summarization
- Translation
from transformers import pipeline
classifier = pipeline('sentiment-analysis')
classifier("Ihave waiting for a course my whole life.")
alist = ["Covid is good", "I love covid"]
classifier(alist)
classifier = pipeline("zero-shot-classification")
classifier("This is a sensitive topic on transport and libarary",
candidate_labels=["education", "math", "business"])
generator = pipeline("text-generation")
generator("In this notebook, we will")
gen_gpt2 = pipeline("text-generation", model="distilgpt2")
gen_gpt2("In this pandas notebook, we will", max_lenght=20)
unmasker = pipeline("fill-mask")
unmasker("This notebook will show <mask> direction", top_k=2)
ner = pipeline("ner", grouped_entities=True)
ner("I am Dan P who carry out research at Monash Uni in Melbourne City")
qa = pipeline("question-answering")
qa(question="Where to I work",
context="I am Dan P who carry out research at Monash Uni in Melbourne City")
summarizer = pipeline("summarization")
article = """
The ongoing discussions within the presidential palace in Kabul are “utterly extraordinary” after two decades of war, CNN International Security Editor Nick Paton Walsh reports.
“This has been a morning of stunning events and that looks like we are heading towards some sort of transitional government here,” Paton Walsh said. He said names are being floated around, though nothing is confirmed, and President Ashraf Ghani would need to agree to step aside to make way for a transitional administration.
Yesterday Ghani made a brief but sombre address to the nation in which he said he was consulting with elders and other leaders both inside and outside of the country. In the short speech, he told the Afghan people his "focus is to avoid further instability, aggression and displacement," but he did not resign.
As talks on Sunday continue, Paton Walsh said there hasn’t been evidence of Taliban fighters moving into the city. Earlier panic appeared to be a clash around a bank where people were trying to withdraw money.
“I've heard sporadic gunfire here but that seems to be traffic disputes. A quick drive around the city has shown traffic has dissipated until you get towards the airport, so utter chaos and panic here. The traffic in the skies we saw around the embassy appears to have quietened as well so perhaps that might suggest some of that operation is winding up,” he continued.
The apparently last-ditch diplomatic efforts would hopefully avoid the Taliban presumably moving to its next phase of slowly entering the city, which Paton Walsh said would “not be remotely pleasant for anybody living here.”
“There will be elements of resistance too so I think everybody would prefer to avoid that kind of situation,” he added.
"""
summarizer(article)
translator = pipeline("translation", model="t5-base")
translator("Hi, my name is Dan")