当前位置:   article > 正文

Transformers 库在NLP任务上的入门与使用_transformers库官网

transformers库官网

0 库

相关资源对应网址如下:

网址
库的 GitHub 地址https://github.com/huggingface/transformers
官方开发文档https://huggingface.co/docs/transformers/index
预训练模型下载地址https://huggingface.co/models

pytorch 和 tensorflow 都可用,但建议用 pytorch,以下代码全都基于 pytorch.

需要安装的库:

  • pytorch
  • transformer
  • datasets
  • evaluate

1 pipeline

1.1 介绍

现有的模型和checkpoint,可以直接拿来用,处理某个任务,如情感分类、文本生成、命名实体识别、问答等。

支持的任务

TaskDescriptionModalityPipeline identifier
Text classificationassign a label to a given sequence of textNLPpipeline(task=“sentiment-analysis”)
Text generationgenerate text that follows a given promptNLPpipeline(task=“text-generation”)
Name entity recognitionassign a label to each token in a sequence (people, organization, location, etc.)NLPpipeline(task=“ner”)
Question answeringextract an answer from the text given some context and a questionNLPpipeline(task=“question-answering”)
Fill-maskpredict the correct masked token in a sequenceNLPpipeline(task=“fill-mask”)
Summarizationgenerate a summary of a sequence of text or documentNLPpipeline(task=“summarization”)
Translationtranslate text from one language into anotherNLPpipeline(task=“translation”)
Image classificationassign a label to an imageComputer visionpipeline(task=“image-classification”)
Image segmentationassign a label to each individual pixel of an image (supports semantic, panoptic, and instance segmentation)Computer visionpipeline(task=“image-segmentation”)
Object detectionpredict the bounding boxes and classes of objects in an imageComputer visionpipeline(task=“object-detection”)
Audio classificationassign a label to an audio fileAudiopipeline(task=“audio-classification”)
Automatic speech recognitionextract speech from an audio file into textAudiopipeline(task=“automatic-speech-recognition”)
Visual question answeringgiven an image and a question, correctly answer a question about the imageMultimodalpipeline(task=“vqa”)

1.2 用于某个任务

1.2.1 情感分析

默认模型
from transformers import pipeline

classifier = pipeline("sentiment-analysis")
  • 1
  • 2
  • 3

测试 “We are very happy to show you the

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/370819
推荐阅读
相关标签