（屏幕嗖嗖声） (screen whooshes)
（面部标志呼啸而过） (face logo whooshes)
（屏幕嗖嗖声） (screen whooshes)
- 本节课内容是: pipeline 函数 - The pipeline function.
pipeline 函数是 Transformers 库中的 The pipeline function is the most high level API
最顶层的 API of the Transformers library.
它将所有步骤重新组合在一起 It regroups together all the steps
从而实现从原始文本到可用预测的转换。 to go from raw texts to usable predictions.
使用的模型是 pipeline 的核心， The model used is at the core of a pipeline,
但 pipeline 还包括 but the pipeline also include
所有必要的预处理， all the necessary pre-processing,
因为模型不期望得到文本，而是数字， since the model does not expect texts, but number,
以及一些后期处理， as well as some post-processing,
使模型的输出可读。 to make the output of the model human-readable.
让我们通过一个情绪分析 pipeline Let's look at a first example
的例子来解释一下。 with the sentiment analysis pipeline.
此 pipeline 对给定的输入执行文本分类 This pipeline performs text classification on a given input
并确定它的情绪是正面的还是负面的。 and determines if it's positive or negative.
在这里，它为给定文本标记正面情绪的标签， Here, it attributed the positive label on the given text,
置信度为 95%。 with a confidence of 95%.
您可以将多个文本传递到同一个 pipeline， You can pass multiple texts to the same pipeline,
它们将被处理并 which will be processed and passed
作为一个批次传递给模型。 through the model together as a batch.
输出是包含单个结果的列表 The output is a list of individual results
与输入文本的顺序相同。 in the same order as the input texts.
在这里，我们为第一个文本找到了相同的标签和分数， Here we find the same label and score for the first text,
第二个文本被判断为否定情绪 and the second text is judged negative
置信度为 99.9%。 with a confidence of 99.9%.
零样本分类 pipeline The zero-shot classification pipeline
是一个更通用的文本分类 pipeline， is a more general text-classification pipeline,
它允许您提供所需的标签。 it allows you to provide the labels you want.
在这里，我们想根据标签对输入文本进行分类， Here we want to classify our input text along the labels,
标签有教育、政治和商业。 education, politics, and business.
pipeline 都能够成功识别 The pipeline successfully recognizes
与其他标签相比，它更多地是关于教育， it's more about education than the other labels,
置信度为 84%。 with a confidence of 84%.
继续执行其他任务， Moving on to other tasks,
文本生成 pipeline 将 the text generation pipeline will
自动完成给定的提示。 auto-complete a given prompt.
输出带有一点随机性， The output is generated with a bit of randomness,
所以每次在给定的提示上调用生成器对象时 so it changes each time you call the generator object
这个结果都会改变。 on a given prompt.
到目前为止，我们已经使用了 pipeline API Up until now, we've used the the pipeline API
结合与每个任务关联的默认模型来演示， with the default model associated to each task,
但您可以将它与任何经过预训练的模型一起使用 but you can use it with any model that has been pretrained
或根据此任务进行微调。 or fine-tuned on this task.
进入模型中心 huggingface.co/models Going on the model hub, huggingface.co/models
您可以按任务过滤可用模型。 you can filter the available models by task.
我们之前示例中使用的默认模型是 gpt2， The default model used in our previous example was gpt2,
但还有更多模型可供选择， but there are many more models available,
且不仅仅是英语。 and not just in English.
让我们回到文本生成 pipeline Let's go back to the text generation pipeline
并用另一个模型 distilgpt2 加载它。 and load it with another model, distilgpt2.
这是 gpt2 的轻量级版本 This is a lighter version of gpt2
由 Hugging Face 团队创建。 created by the Hugging Face team.
将 pipeline 应用于给定提示时， When applying the pipeline to a given prompt,
我们可以指定几个参数 we can specify several arguments
例如生成文本的最大长度， such as the maximum length of the generated texts,
或者我们想要返回的句子数量， or the number of sentences we want to return,
因为这一代有一些随机性。 since there is some randomness in the generation.
通过猜测句子中的下一个单词来生成文本 Generating texts by guessing the next word in a sentence
是 GPT-2 的预训练目标。 was the pretraining objective of GPT-2.
掩码填充 pipeline 是 BERT 的预训练目标， The fill mask pipeline is the pretraining objective of BERT,
这是猜测掩码词的值。 which is to guess the value of masked word.
在这种情况下，我们询问两个最可能的值 In this case, we ask the two most likely values
对于缺失的词，根据模型， for the missing words, according to the model,
并通过数学计算推测可能的答案。 and get mathematical or computational as possible answers.
Transformers 模型可以执行的另一项任务 Another task Transformers model can perform
就是对句子中的每一个词进行分类 is to classify each word in the sentence
而不是整个句子。 instead of the sentence as a whole.
其中一个例子是命名实体识别， One example of this is Named Entity Recognition,
这是识别实体的任务， which is the task of identifying entities,
例如句子中的人、组织或地点。 such as persons, organizations or locations in a sentence.
在这里，模型正确地找到了人 Sylvain， Here, the model correctly finds the person, Sylvain,
组织，是 Hugging Face the organization, Hugging Face,
以及位置，布鲁克林， as well as the location, Brooklyn,
在输入文本中。 inside the input text.
使用的 grouped_entities=True 参数 The grouped_entities=True argument used
就是把 pipeline 组合在一起 is to make the pipeline group together
链接到同一实体的不同词， the different words linked to the same entity,
比如这里的 Hugging 和 Face。 such as Hugging and Face here.
pipeline API 可用的另一个任务 Another task available with the pipeline API
是抽取式问答。 is extractive question answering.
提供上下文和问题， Providing a context and a question,
该模型将识别上下文中的文本范围 the model will identify the span of text in the context
包含问题的答案。 containing the answer to the question.
获取长文的简短摘要 Getting short summaries of very long articles
也是 Transformers 库可以提供的功能， is also something the Transformers library can help with,
这是摘要 pipeline 提供的功能。 with the summarization pipeline.
pipeline API 支持的最后一个任务 Finally, the last task supported by the pipeline API
是翻译。 is translation.
这里我们使用在模型中心 (Model Hub) 提供的 Here we use a French/English model
法语/英语模型 found on the model hub
获取我们输入文本的英文版本。 to get the English version of our input text.
这是所有任务的简要总结 Here is a brief summary of all the tasks
我们在这段视频中进行了调查。 we've looked into in this video.
然后通过模型中心中提供的 Try then out through the inference widgets
推理小部件进行尝试。 in the model hub.
（屏幕嗖嗖声） (screen whooshes)
（徽标嗖嗖声） (logo whooshes)