the most basic object in the 🤗 Transformers llibrary
It can:
feature-extraction(get a vector representing the text)
fill-task
ner(entity recognition)
question-answering
sentiment-analysis
summarization
text-generation
translation
zero-shot classification
Zero-shot Classification
you can casually assign the labels
python
1
2
3
4
5
classifier = pipeline("zero-shot-classification")classifier("I play Genshin Impact!", candidate_labels=["op","2-dimensional"])
1
2
3
4
5
classifier = pipeline("zero-shot-classification")
classifier(
"I play Genshin Impact!",
candidate_labels=["op","2-dimensional"]
)
Text Generation
involves randomness
python
1
2
3
4
5
6
generator=pipeline("text-generation")generator("prompts", max_length=15,#the max length of the text num_return_sequence=3#How many texts are gonna generated)
1
2
3
4
5
6
generator=pipeline("text-generation")
generator(
"prompts",
max_length=15, #the max length of the text num_return_sequence=3#How many texts are gonna generated)
Mask filling
python
1
2
unmasker=pipeline("fill-mask")unmasker("I play <mask> Impact!",top_k=2)#top_k decides the time it does;<mask> depends on what model you are using
1
2
unmasker=pipeline("fill-mask")
unmasker("I play <mask> Impact!",top_k=2) #top_k decides the time it does;<mask> depends on what model you are using
Named entity recognition
python
1
ner=pipeline("ner",grouped_entities=True)#'grouped_entities=True' is used to enable the model to put multi-words together
1
ner=pipeline("ner",grouped_entities=True)#'grouped_entities=True' is used to enable the model to put multi-words together
Question answering
answer a question using given context
extracting answers from the context instead of generating answers
python
1
2
3
4
5
question_answerer=pipeline("question-answering")question_answerer( question="where do I work?", context="My name is Sylvain and I work at Hugging Face in Brooklyn")
1
2
3
4
5
question_answerer=pipeline("question-answering")
question_answerer(
question="where do I work?",
context="My name is Sylvain and I work at Hugging Face in Brooklyn")
加载评论中...