허깅페이스 자연어처리,Hub,transformer

장태중·2024년 4월 24일

transformers : provides APIs and tools to easily download and train state-of-the-art pretrained models.

pipline- The pipeline() is the easiest and fastest way to use a pretrained model for inference

1) Text classification : assign a label to a given sequence of text NLP
: pipeline(task=“sentiment-analysis”)

2) Text generation : generate text given a prompt NLP
: pipeline(task=“text-generation”)

3) Summarization : generate a summary of a sequence of text or document NLP
: pipeline(task=“summarization”)

If you want to use a specific model from the hub you can ignore the task if the model on the hub already defines it

  • pipe = pipeline(model="FacebookAI/roberta-large-mnli")
    pipe("This restaurant is awesome")
    [{'label': 'NEUTRAL', 'score': 0.7313136458396912}]
  • pipe = pipeline("text-classification")
    pipe("This restaurant is awesome")
    [{'label': 'POSITIVE', 'score': 0.9998743534088135}]

-To call a pipeline on many items, you can call it with a list.

  • pipe = pipeline("text-classification")
    pipe(["This restaurant is awesome", "This restaurant is awful"])
    [{'label': 'POSITIVE', 'score': 0.9998743534088135},
    {'label': 'NEGATIVE', 'score': 0.9996669292449951}]
profile
나답게, 한걸음씩. 첫 술에 배부르지 말자

0개의 댓글