From fabab7a358be619a94ef880c0a1eb454eb13fca0 Mon Sep 17 00:00:00 2001 From: blackdoor571 Date: Fri, 21 Oct 2022 19:58:52 +0900 Subject: [PATCH 1/4] done chapter1.2,1.3 --- chapters/ja/chapter1/2.mdx | 41 ++++ chapters/ja/chapter1/3.mdx | 418 +++++++++++++++++++++++++++++++++++++ 2 files changed, 459 insertions(+) create mode 100644 chapters/ja/chapter1/2.mdx create mode 100644 chapters/ja/chapter1/3.mdx diff --git a/chapters/ja/chapter1/2.mdx b/chapters/ja/chapter1/2.mdx new file mode 100644 index 000000000..4d94d2771 --- /dev/null +++ b/chapters/ja/chapter1/2.mdx @@ -0,0 +1,41 @@ +# 自然言語処理 / NLP(Natural Language Processing) + + + +Before jumping into Transformer models, let's do a quick overview of what natural language processing is and why we care about it. + +Transformerモデルの詳細に飛び込んでいく前に、自然言語処理とはどんなもので、かつ、なぜ我々が注目する必要があるのかの大まかな概要を知っていきましょう。 + +## What is NLP? 自然言語処理とはどんなもの? + +NLP is a field of linguistics and machine learning focused on understanding everything related to human language. The aim of NLP tasks is not only to understand single words individually, but to be able to understand the context of those words. + +自然言語処理とは、人の言語に関連した全てのことへの理解に焦点を当てた、言語学と機械学習の分野です。自然言語処理タスクの目標は、文章を個別に一単語ずつ理解するだけでなく、それらの単語で構成された文章の文脈を理解することです。 + +The following is a list of common NLP tasks, with some examples of each: + +以下のリストで、具体例付きで一般的な自然言語処理タスクを紹介します。 + +- **Classifying whole sentences**: Getting the sentiment of a review, detecting if an email is spam, determining if a sentence is grammatically correct or whether two sentences are logically related or not +- **Classifying each word in a sentence**: Identifying the grammatical components of a sentence (noun, verb, adjective), or the named entities (person, location, organization) +- **Generating text content**: Completing a prompt with auto-generated text, filling in the blanks in a text with masked words +- **Extracting an answer from a text**: Given a question and a context, extracting the answer to the question based on the information provided in the context +- **Generating a new sentence from an input text**: Translating a text into another language, summarizing a text + +- **文章の分類**:レビューの評価、スパムメールの検出、文法的に正しいかどうかの判断、2つの文が論理的に関連しているかどうかの判断 +- **文の中の単語分類**:品詞(名詞、動詞、形容詞)や、固有表現(人、場所、組織)の識別 +- **文章内容の生成**:自動生成されたテキストによる入力テキストの補完、文章の穴埋め +- **文章からの情報抽出**:質問と文脈が与えられたときの、文脈からの情報に基づいた質問に対する答えの抽出 +- **文章の変換**:ある文章の他の言語への翻訳、文章の要約 + +NLP isn't limited to written text though. It also tackles complex challenges in speech recognition and computer vision, such as generating a transcript of an audio sample or a description of an image. + +更に、自然言語処理は文章に限ったものではありません。音声認識やコンピュータビジョンの分野でも、音声サンプルの書き起こしや画像の説明文の生成など、複雑な課題に取り組んでいます。 + +## Why is it challenging? なぜ自然言語処理は困難なのか? +Computers don't process information in the same way as humans. For example, when we read the sentence "I am hungry," we can easily understand its meaning. Similarly, given two sentences such as "I am hungry" and "I am sad," we're able to easily determine how similar they are. For machine learning (ML) models, such tasks are more difficult. The text needs to be processed in a way that enables the model to learn from it. And because language is complex, we need to think carefully about how this processing must be done. There has been a lot of research done on how to represent text, and we will look at some methods in the next chapter. + +コンピュータは人間と同じように情報を処理するわけではありません。例えば、「私はお腹が空いています。」という文章を読むと、その意味を簡単に理解することができます。同様に、「私はお腹が空いています。」と「私は悲しいです。」という2つの文章があれば、その類似性を簡単に判断することができます。しかし、機械学習(ML)モデルにおいては、このようなタスクはより困難です。機械学習モデルが学習できるように、テキストを処理する必要があります。また、言語は複雑なため、どのように処理すべきかを慎重に考える必要があります。テキストをどのように表現するかについては多くの研究がなされており、次の章ではいくつかの方法について見ていきます。 diff --git a/chapters/ja/chapter1/3.mdx b/chapters/ja/chapter1/3.mdx new file mode 100644 index 000000000..ef6f7c218 --- /dev/null +++ b/chapters/ja/chapter1/3.mdx @@ -0,0 +1,418 @@ +# Transformers, what can they do? Transformers, 何ができる? + + + +In this section, we will look at what Transformer models can do and use our first tool from the 🤗 Transformers library: the `pipeline()` function. + +このセクションでは、Transformerモデルができることを見ていき、🤗 Transformersライブラリの最初のツールとして `pipeline()` 関数を使ってみましょう。 + + +👀 See that Open in Colab button on the top right? Click on it to open a Google Colab notebook with all the code samples of this section. This button will be present in any section containing code examples. + +If you want to run the examples locally, we recommend taking a look at the setup. + +👀 右上にOpen in Colabというボタンがありますよね?それをクリックすると、このセクションのすべてのコードサンプルを含むGoogle Colabノートブックが開きます。このボタンは、コードサンプルを含むどのセクションにも存在します。 + +ローカルでサンプルを実行したい場合は、セットアップを参照することをお勧めします。 + + +## Transformers are everywhere! Transformersは至るところに! + +Transformer models are used to solve all kinds of NLP tasks, like the ones mentioned in the previous section. Here are some of the companies and organizations using Hugging Face and Transformer models, who also contribute back to the community by sharing their models: + +Transformerモデルは前節で述べたようなあらゆる種類のNLPタスクを解決するために使用されています。ここでは、Hugging FaceとTransformerモデルを使用している企業や組織を紹介します。それらの組織はまた、モデルを共有することでコミュニティに還元しています。 + +Companies using Hugging Face + +The [🤗 Transformers library](https://github.com/huggingface/transformers) provides the functionality to create and use those shared models. The [Model Hub](https://huggingface.co/models) contains thousands of pretrained models that anyone can download and use. You can also upload your own models to the Hub! + +[🤗 Transformers library](https://github.com/huggingface/transformers)は、それらの共有モデルを作成し、使用するための機能を提供します。[Model Hub](https://huggingface.co/models)には、誰でもダウンロードして使用できる何千もの事前学習済みモデルが含まれています。また、あなた自身のモデルをModel Hubにアップロードすることも可能です。 + + +⚠️ The Hugging Face Hub is not limited to Transformer models. Anyone can share any kind of models or datasets they want! Create a huggingface.co account to benefit from all available features! + + +⚠️Hugging Face Hubはトランスフォーマーモデルに限定されるものではありません。誰でも好きな種類のモデルやデータセットを共有することができます!すべての利用可能な機能の恩恵を受けるためにhuggingface.coのアカウントを作成しましょう! + +Before diving into how Transformer models work under the hood, let's look at a few examples of how they can be used to solve some interesting NLP problems. + +Transformerのモデルがどのように機能するのかを知る前に、いくつかの興味深いNLPの問題を解決するため、Transformerがどのように使われるのか、いくつかの例で見ていきましょう。 + +## Working with pipelines pipelinesを使ったタスク + + + +The most basic object in the 🤗 Transformers library is the `pipeline()` function. It connects a model with its necessary preprocessing and postprocessing steps, allowing us to directly input any text and get an intelligible answer: + +🤗 Transformers ライブラリの中で最も基本的なオブジェクトは `pipeline()` 関数です。これはモデルを必要な前処理と後処理のステップに接続し、任意のテキストを直接入力して理解しやすい答えを得ることを可能にします。 + +```python +from transformers import pipeline +classifier = pipeline("sentiment-analysis") +classifier("I've been waiting for a HuggingFace course my whole life.") +``` + +```python out +[{'label': 'POSITIVE', 'score': 0.9598047137260437}] +``` + +We can even pass several sentences! + +複数の文章を入力することも可能です。 + +```python +classifier( + ["I've been waiting for a HuggingFace course my whole life.", "I hate this so much!"] +) +``` + +```python out +[{'label': 'POSITIVE', 'score': 0.9598047137260437}, + {'label': 'NEGATIVE', 'score': 0.9994558095932007}] +``` + +By default, this pipeline selects a particular pretrained model that has been fine-tuned for sentiment analysis in English. The model is downloaded and cached when you create the `classifier` object. If you rerun the command, the cached model will be used instead and there is no need to download the model again. + +デフォルトでは、このpipelineは英語の感情分析用にファインチューニングされた特定の事前学習モデルを使用します。このモデルは `classifier` オブジェクトを作成する際にダウンロードされ、キャッシュされます。コマンドを再実行すると、キャッシュされたモデルが代わりに使用され、モデルを再度ダウンロードする必要はありません。 + + +There are three main steps involved when you pass some text to a pipeline: + +1. The text is preprocessed into a format the model can understand. +2. The preprocessed inputs are passed to the model. +3. The predictions of the model are post-processed, so you can make sense of them. + + +pipelineにテキストを渡す場合、主に3つのステップがあります。 + +1. テキストはモデルが理解できる形式に前処理される。 +2. 前処理された入力がモデルに渡される。 +3. 予測結果を理解できるように、モデルの後処理が行われる。 + + +Some of the currently [available pipelines](https://huggingface.co/transformers/main_classes/pipelines.html) are: + +- `feature-extraction` (get the vector representation of a text) +- `fill-mask` +- `ner` (named entity recognition) +- `question-answering` +- `sentiment-analysis` +- `summarization` +- `text-generation` +- `translation` +- `zero-shot-classification` + +Let's have a look at a few of these! + +現在[利用可能なpipeline](https://huggingface.co/transformers/main_classes/pipelines.html)の一部を紹介します。 + +- `feature-extraction` (テキストのベクトル表現を取得) +- `fill-mask` +- `ner` (固有表現認識) +- `question-answering` +- `sentiment-analysis` +- `summarization` +- `text-generation` +- `translation` +- `zero-shot-classification` + +では、いくつか見ていきましょう。 + +## Zero-shot classification ゼロショット分類 + +We'll start by tackling a more challenging task where we need to classify texts that haven't been labelled. This is a common scenario in real-world projects because annotating text is usually time-consuming and requires domain expertise. For this use case, the `zero-shot-classification` pipeline is very powerful: it allows you to specify which labels to use for the classification, so you don't have to rely on the labels of the pretrained model. You've already seen how the model can classify a sentence as positive or negative using those two labels — but it can also classify the text using any other set of labels you like. + +まず、ラベル付けされていないテキストを分類する必要があるような、より困難なタスクに取り組むことから始めます。これは実際のプロジェクトでよくあるシナリオです。なぜなら、テキストにアノテーションをつけるのは通常時間がかかり、専門知識が必要だからです。このような場合、`zero-shot-classification` pipelineは非常に強力です。分類に使用するラベルを指定できるので、事前に学習したモデルのラベルに依存する必要がありません。肯定的か否定的かの2つのラベルを使って、モデルがどのようにテキストを分類するかは既に見たとおりです。しかし、他の任意のラベルセットを使ってテキストを分類することもできます。 + + +```python +from transformers import pipeline +classifier = pipeline("zero-shot-classification") +classifier( + "This is a course about the Transformers library", + candidate_labels=["education", "politics", "business"], +) +``` + +```python out +{'sequence': 'This is a course about the Transformers library', + 'labels': ['education', 'business', 'politics'], + 'scores': [0.8445963859558105, 0.111976258456707, 0.043427448719739914]} +``` + +This pipeline is called _zero-shot_ because you don't need to fine-tune the model on your data to use it. It can directly return probability scores for any list of labels you want! + +このpipelineは _zero-shot_ と呼ばれる。なぜなら、これを使うために自前のデータセットでモデルのファインチューニングをする必要がないからです。任意のラベルのリストに対して直接確率スコアを返すことができます。 + + + +✏️ **Try it out!** Play around with your own sequences and labels and see how the model behaves. + +✏️ **試してみよう!** 独自の入力とラベルで遊んでみて、モデルがどのように振る舞うか見てみましょう。 + + + +## Text generation 文章生成 + +Now let's see how to use a pipeline to generate some text. The main idea here is that you provide a prompt and the model will auto-complete it by generating the remaining text. This is similar to the predictive text feature that is found on many phones. Text generation involves randomness, so it's normal if you don't get the same results as shown below. + +では、pipelineを使ってテキストを生成する方法を見てみましょう。主なアイデアは、プロンプトを与えると、モデルが残りのテキストを生成してそれを補完することです。これは、多くの携帯電話に搭載されている予測入力機能に類似しています。テキスト生成にはランダム性が含まれるため、以下と同様な結果が得られないのが通常です。 + +```python +from transformers import pipeline +generator = pipeline("text-generation") +generator("In this course, we will teach you how to") +``` + +```python out +[{'generated_text': 'In this course, we will teach you how to understand and use ' + 'data flow and data interchange when handling user data. We ' + 'will be working with one or more of the most commonly used ' + 'data flows — data flows of various types, as seen by the ' + 'HTTP'}] +``` + +You can control how many different sequences are generated with the argument `num_return_sequences` and the total length of the output text with the argument `max_length`. + +引数`num_return_sequences`で異なるシーケンスの生成数を、引数`max_length`で出力テキストの合計の長さを制御することができます。 + + + +✏️ **Try it out!** Use the `num_return_sequences` and `max_length` arguments to generate two sentences of 15 words each. + +✏️ **試してみよう!** `num_return_sequences` と `max_length` 引数を用いて、15語ずつの2つの文を生成することができます。 + + + + +## Using any model from the Hub in a pipeline pipelineでHubから任意のモデルを使用する + +The previous examples used the default model for the task at hand, but you can also choose a particular model from the Hub to use in a pipeline for a specific task — say, text generation. Go to the [Model Hub](https://huggingface.co/models) and click on the corresponding tag on the left to display only the supported models for that task. You should get to a page like [this one](https://huggingface.co/models?pipeline_tag=text-generation). + +Let's try the [`distilgpt2`](https://huggingface.co/distilgpt2) model! Here's how to load it in the same pipeline as before: + +これまでの例では、タスクに応じたデフォルトのモデルを使用しましたが、特定のタスク(例えばテキスト生成)のpipelineで使用するモデルをHubから選択することも可能です。[Model Hub](https://huggingface.co/models)にアクセスし、左側の対応するタグをクリックすると、そのタスクでサポートされているモデルのみが表示されます。[このようなページ](https://huggingface.co/models?pipeline_tag=text-generation)が表示されるはずです。 + +それでは、[`distilgpt2`](https://huggingface.co/distilgpt2)モデルを試してみましょう! 先ほどと同じpipelineでロードする方法を説明します。 + +```python +from transformers import pipeline +generator = pipeline("text-generation", model="distilgpt2") +generator( + "In this course, we will teach you how to", + max_length=30, + num_return_sequences=2, +) +``` + +```python out +[{'generated_text': 'In this course, we will teach you how to manipulate the world and ' + 'move your mental and physical capabilities to your advantage.'}, + {'generated_text': 'In this course, we will teach you how to become an expert and ' + 'practice realtime, and with a hands on experience on both real ' + 'time and real'}] +``` + +You can refine your search for a model by clicking on the language tags, and pick a model that will generate text in another language. The Model Hub even contains checkpoints for multilingual models that support several languages. + +Once you select a model by clicking on it, you'll see that there is a widget enabling you to try it directly online. This way you can quickly test the model's capabilities before downloading it. + +言語タグをクリックして検索するモデルを絞り込み、他の言語でテキストを生成するモデルを選ぶことができます。Model Hubには、複数の言語をサポートする多言語モデルのチェックポイントもあります。 + +モデルをクリックで選択すると、オンラインで直接試用できるウィジェットが表示されます。このようにして、ダウンロードする前にモデルの機能をすばやくテストすることができます。 + + + +✏️ **Try it out!** Use the filters to find a text generation model for another language. Feel free to play with the widget and use it in a pipeline! + +✏️ **試してみよう!** フィルタ-を使って、他の言語のテキスト生成モデルを探してみましょう。ウィジェットで自由に遊んだり、pipelineで使ってみてください! + + + + +### The Inference API 推論API + +All the models can be tested directly through your browser using the Inference API, which is available on the Hugging Face [website](https://huggingface.co/). You can play with the model directly on this page by inputting custom text and watching the model process the input data. + +The Inference API that powers the widget is also available as a paid product, which comes in handy if you need it for your workflows. See the [pricing page](https://huggingface.co/pricing) for more details. + +すべてのモデルは、Hugging Face [ウェブサイト](https://huggingface.co/)で公開されているInference APIを使って、ブラウザから直接テストすることが可能です。このページでは、カスタムテキストを入力し、モデルが入力データを処理する様子を見ることで、直接モデルで遊ぶことができます。 + +このウィジェットを動かすInference APIは、有料製品としても提供されており、ワークフローに必要な場合は便利です。詳しくは[価格ページ](https://huggingface.co/pricing)をご覧ください。 + +## Mask filling 空所穴埋め + +The next pipeline you'll try is `fill-mask`. The idea of this task is to fill in the blanks in a given text: + +次に試すpipelineは`fill-mask`です。このタスクのアイデアは、与えられたテキストの空白を埋めることです。 + +```python +from transformers import pipeline +unmasker = pipeline("fill-mask") +unmasker("This course will teach you all about models.", top_k=2) +``` + +```python out +[{'sequence': 'This course will teach you all about mathematical models.', + 'score': 0.19619831442832947, + 'token': 30412, + 'token_str': ' mathematical'}, + {'sequence': 'This course will teach you all about computational models.', + 'score': 0.04052725434303284, + 'token': 38163, + 'token_str': ' computational'}] +``` + +The `top_k` argument controls how many possibilities you want to be displayed. Note that here the model fills in the special `` word, which is often referred to as a *mask token*. Other mask-filling models might have different mask tokens, so it's always good to verify the proper mask word when exploring other models. One way to check it is by looking at the mask word used in the widget. + +`top_k` 引数は、いくつの可能性を表示させたいかをコントロールします。ここでは、モデルが特別な `` という単語を埋めていることに注意してください。これはしばしば *mask token* と呼ばれます。他の空所穴埋めモデルは異なるマスクトークンを持つかもしれないので、他のモデルを探索するときには常に適切なマスクワードを確認するのが良いでしょう。それを確認する1つの方法は、ウィジェットで使用されているマスクワードを見ることです。 + + + +✏️ **Try it out!** Search for the `bert-base-cased` model on the Hub and identify its mask word in the Inference API widget. What does this model predict for the sentence in our `pipeline` example above? + +✏️ **試してみよう!** Hub で `bert-base-cased` モデルを検索し、推論API ウィジェットでそのマスクワードを特定します。このモデルは上記の `pipeline` の例文に対して何を予測するでしょうか? + + + +## Named entity recognition 固有表現認識 + +Named entity recognition (NER) is a task where the model has to find which parts of the input text correspond to entities such as persons, locations, or organizations. Let's look at an example: + +固有表現認識(NER)は、入力されたテキストのどの部分が人物、場所、組織などの固有表現に対応するかをモデルが見つけ出すタスクです。例を見てみましょう。 + +```python +from transformers import pipeline +ner = pipeline("ner", grouped_entities=True) +ner("My name is Sylvain and I work at Hugging Face in Brooklyn.") +``` + +```python out +[{'entity_group': 'PER', 'score': 0.99816, 'word': 'Sylvain', 'start': 11, 'end': 18}, + {'entity_group': 'ORG', 'score': 0.97960, 'word': 'Hugging Face', 'start': 33, 'end': 45}, + {'entity_group': 'LOC', 'score': 0.99321, 'word': 'Brooklyn', 'start': 49, 'end': 57} +] +``` + +Here the model correctly identified that Sylvain is a person (PER), Hugging Face an organization (ORG), and Brooklyn a location (LOC). + +We pass the option `grouped_entities=True` in the pipeline creation function to tell the pipeline to regroup together the parts of the sentence that correspond to the same entity: here the model correctly grouped "Hugging" and "Face" as a single organization, even though the name consists of multiple words. In fact, as we will see in the next chapter, the preprocessing even splits some words into smaller parts. For instance, `Sylvain` is split into four pieces: `S`, `##yl`, `##va`, and `##in`. In the post-processing step, the pipeline successfully regrouped those pieces. + +ここでは、モデルはSylvainが人(PER)、Hugging Faceが組織(ORG)、Brooklynが場所(LOC)であることを正しく識別しています。 + +pipelineの作成機能でオプション `grouped_entities=True` を渡すと、同じエンティティに対応する文の部分を再グループ化するようpipelineに指示します。ここでは、名前が複数の単語で構成されていても、モデルは "Hugging" と "Face" を一つの組織として正しくグループ化しています。実際、次の章で説明するように、前処理ではいくつかの単語をより小さなパーツに分割することさえあります。例えば、`Sylvain`は4つの部分に分割されます。`S`, `##yl`, `##va`, and `##in`.です。後処理の段階で、pipelineはこれらの断片をうまく再グループ化しました。 + + + +✏️ **Try it out!** Search the Model Hub for a model able to do part-of-speech tagging (usually abbreviated as POS) in English. What does this model predict for the sentence in the example above? + +✏️ **試してみよう!** Model Hubで英語の品詞タグ付け(通常POSと略される)を行えるモデルを検索してください。このモデルは、上の例の文に対して何を予測するでしょうか? + + + +## Question answering 質問応答 + +The `question-answering` pipeline answers questions using information from a given context: + +質問応答pipelineは、与えられた文脈から得た情報を使って質問に答えます。 + +```python +from transformers import pipeline +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", +) +``` + +```python out +{'score': 0.6385916471481323, 'start': 33, 'end': 45, 'answer': 'Hugging Face'} +``` + +Note that this pipeline works by extracting information from the provided context; it does not generate the answer. + +このpipelineは、提供されたコンテキストから情報を抽出することで動作し、答えを生成するわけではないことに注意してください。 + +## Summarization 要約 + +Summarization is the task of reducing a text into a shorter text while keeping all (or most) of the important aspects referenced in the text. Here's an example: + +要約とは、文章中の重要な部分をすべて(あるいはほとんど)維持したまま、より短い文章にするタスクです。以下はその例です。 + +```python +from transformers import pipeline +summarizer = pipeline("summarization") +summarizer( + """ + America has changed dramatically during recent years. Not only has the number of + graduates in traditional engineering disciplines such as mechanical, civil, + electrical, chemical, and aeronautical engineering declined, but in most of + the premier American universities engineering curricula now concentrate on + and encourage largely the study of engineering science. As a result, there + are declining offerings in engineering subjects dealing with infrastructure, + the environment, and related issues, and greater concentration on high + technology subjects, largely supporting increasingly complex scientific + developments. While the latter is important, it should not be at the expense + of more traditional engineering. + Rapidly developing economies such as China and India, as well as other + industrial countries in Europe and Asia, continue to encourage and advance + the teaching of engineering. Both China and India, respectively, graduate + six and eight times as many traditional engineers as does the United States. + Other industrial countries at minimum maintain their output, while America + suffers an increasingly serious decline in the number of engineering graduates + and a lack of well-educated engineers. +""" +) +``` + +```python out +[{'summary_text': ' America has changed dramatically during recent years . The ' + 'number of engineering graduates in the U.S. has declined in ' + 'traditional engineering disciplines such as mechanical, civil ' + ', electrical, chemical, and aeronautical engineering . Rapidly ' + 'developing economies such as China and India, as well as other ' + 'industrial countries in Europe and Asia, continue to encourage ' + 'and advance engineering .'}] +``` + +Like with text generation, you can specify a `max_length` or a `min_length` for the result. + +テキスト生成と同様に、結果に対して `max_length` や `min_length` を指定することができます。 + + +## Translation 翻訳 + +For translation, you can use a default model if you provide a language pair in the task name (such as `"translation_en_to_fr"`), but the easiest way is to pick the model you want to use on the [Model Hub](https://huggingface.co/models). Here we'll try translating from French to English: + +翻訳の場合、タスク名に言語ペアを指定すれば(`"translation_en_to_fr"`など)デフォルトのモデルを使うこともできますが、一番簡単なのは [Model Hub](https://huggingface.co/models) で使いたいモデルを選ぶことです。ここでは、フランス語から英語への翻訳を試してみます。 + +```python +from transformers import pipeline +translator = pipeline("translation", model="Helsinki-NLP/opus-mt-fr-en") +translator("Ce cours est produit par Hugging Face.") +``` + +```python out +[{'translation_text': 'This course is produced by Hugging Face.'}] +``` + +Like with text generation and summarization, you can specify a `max_length` or a `min_length` for the result. + +テキスト生成や要約と同様に、結果に対して `max_length` や `min_length` を指定することができます。 + + + +✏️ **Try it out!** Search for translation models in other languages and try to translate the previous sentence into a few different languages. + +✏️ **試してみよう!** 他言語の翻訳モデルを検索して、前の文章をいくつかの異なる言語に翻訳してみましょう。 + + + +The pipelines shown so far are mostly for demonstrative purposes. They were programmed for specific tasks and cannot perform variations of them. In the next chapter, you'll learn what's inside a `pipeline()` function and how to customize its behavior. + +これまで紹介したpipelineは、ほとんどがデモンストレーションのためのものです。これらは特定のタスクのためにプログラムされたものであり、それらのバリエーションを実行することはできません。次の章では、`pipeline()`関数の中身と、その動作をカスタマイズする方法を学びます。 From 3b6de2b4a68b2e96274805eed3f291dea3cd8b09 Mon Sep 17 00:00:00 2001 From: blackdoor571 Date: Fri, 4 Nov 2022 19:00:21 +0900 Subject: [PATCH 2/4] modify 2.mdx, 3.mdx --- chapters/ja/chapter1/2.mdx | 23 ++----- chapters/ja/chapter1/3.mdx | 133 ++++++------------------------------- 2 files changed, 23 insertions(+), 133 deletions(-) diff --git a/chapters/ja/chapter1/2.mdx b/chapters/ja/chapter1/2.mdx index 4d94d2771..11fb226da 100644 --- a/chapters/ja/chapter1/2.mdx +++ b/chapters/ja/chapter1/2.mdx @@ -5,37 +5,22 @@ classNames="absolute z-10 right-0 top-0" /> -Before jumping into Transformer models, let's do a quick overview of what natural language processing is and why we care about it. - Transformerモデルの詳細に飛び込んでいく前に、自然言語処理とはどんなもので、かつ、なぜ我々が注目する必要があるのかの大まかな概要を知っていきましょう。 -## What is NLP? 自然言語処理とはどんなもの? - -NLP is a field of linguistics and machine learning focused on understanding everything related to human language. The aim of NLP tasks is not only to understand single words individually, but to be able to understand the context of those words. +## 自然言語処理とはどんなもの? 自然言語処理とは、人の言語に関連した全てのことへの理解に焦点を当てた、言語学と機械学習の分野です。自然言語処理タスクの目標は、文章を個別に一単語ずつ理解するだけでなく、それらの単語で構成された文章の文脈を理解することです。 -The following is a list of common NLP tasks, with some examples of each: - 以下のリストで、具体例付きで一般的な自然言語処理タスクを紹介します。 -- **Classifying whole sentences**: Getting the sentiment of a review, detecting if an email is spam, determining if a sentence is grammatically correct or whether two sentences are logically related or not -- **Classifying each word in a sentence**: Identifying the grammatical components of a sentence (noun, verb, adjective), or the named entities (person, location, organization) -- **Generating text content**: Completing a prompt with auto-generated text, filling in the blanks in a text with masked words -- **Extracting an answer from a text**: Given a question and a context, extracting the answer to the question based on the information provided in the context -- **Generating a new sentence from an input text**: Translating a text into another language, summarizing a text - - **文章の分類**:レビューの評価、スパムメールの検出、文法的に正しいかどうかの判断、2つの文が論理的に関連しているかどうかの判断 - **文の中の単語分類**:品詞(名詞、動詞、形容詞)や、固有表現(人、場所、組織)の識別 - **文章内容の生成**:自動生成されたテキストによる入力テキストの補完、文章の穴埋め - **文章からの情報抽出**:質問と文脈が与えられたときの、文脈からの情報に基づいた質問に対する答えの抽出 - **文章の変換**:ある文章の他の言語への翻訳、文章の要約 -NLP isn't limited to written text though. It also tackles complex challenges in speech recognition and computer vision, such as generating a transcript of an audio sample or a description of an image. - -更に、自然言語処理は文章に限ったものではありません。音声認識やコンピュータビジョンの分野でも、音声サンプルの書き起こしや画像の説明文の生成など、複雑な課題に取り組んでいます。 +さらに、自然言語処理は文章に限ったものではありません。音声認識やコンピュータビジョンの分野でも、音声サンプルの書き起こしや画像の説明文の生成など、複雑な課題に取り組んでいます。 -## Why is it challenging? なぜ自然言語処理は困難なのか? -Computers don't process information in the same way as humans. For example, when we read the sentence "I am hungry," we can easily understand its meaning. Similarly, given two sentences such as "I am hungry" and "I am sad," we're able to easily determine how similar they are. For machine learning (ML) models, such tasks are more difficult. The text needs to be processed in a way that enables the model to learn from it. And because language is complex, we need to think carefully about how this processing must be done. There has been a lot of research done on how to represent text, and we will look at some methods in the next chapter. +## なぜ自然言語処理は困難なのか? -コンピュータは人間と同じように情報を処理するわけではありません。例えば、「私はお腹が空いています。」という文章を読むと、その意味を簡単に理解することができます。同様に、「私はお腹が空いています。」と「私は悲しいです。」という2つの文章があれば、その類似性を簡単に判断することができます。しかし、機械学習(ML)モデルにおいては、このようなタスクはより困難です。機械学習モデルが学習できるように、テキストを処理する必要があります。また、言語は複雑なため、どのように処理すべきかを慎重に考える必要があります。テキストをどのように表現するかについては多くの研究がなされており、次の章ではいくつかの方法について見ていきます。 +コンピュータは人間と同じように情報を処理するわけではありません。例えば、「私はお腹が空いています。」という文章を読むと、人間はその意味を簡単に理解することができます。同様に、「私はお腹が空いています。」と「私は悲しいです。」という2つの文章があれば、その類似性を人間は簡単に判断することができます。しかし、機械学習(ML)モデルにおいては、このようなタスクはより困難です。機械学習モデルが学習できるように、テキストを処理する必要があります。また、言語は複雑なため、どのように処理すべきかを慎重に考える必要があります。テキストをどのように表現するかについては多くの研究がなされており、次の章ではいくつかの方法について見ていきます。 diff --git a/chapters/ja/chapter1/3.mdx b/chapters/ja/chapter1/3.mdx index ef6f7c218..73a205308 100644 --- a/chapters/ja/chapter1/3.mdx +++ b/chapters/ja/chapter1/3.mdx @@ -1,4 +1,4 @@ -# Transformers, what can they do? Transformers, 何ができる? +# Transformersで何ができる? -In this section, we will look at what Transformer models can do and use our first tool from the 🤗 Transformers library: the `pipeline()` function. このセクションでは、Transformerモデルができることを見ていき、🤗 Transformersライブラリの最初のツールとして `pipeline()` 関数を使ってみましょう。 -👀 See that Open in Colab button on the top right? Click on it to open a Google Colab notebook with all the code samples of this section. This button will be present in any section containing code examples. - -If you want to run the examples locally, we recommend taking a look at the setup. - 👀 右上にOpen in Colabというボタンがありますよね?それをクリックすると、このセクションのすべてのコードサンプルを含むGoogle Colabノートブックが開きます。このボタンは、コードサンプルを含むどのセクションにも存在します。 ローカルでサンプルを実行したい場合は、セットアップを参照することをお勧めします。 -## Transformers are everywhere! Transformersは至るところに! - -Transformer models are used to solve all kinds of NLP tasks, like the ones mentioned in the previous section. Here are some of the companies and organizations using Hugging Face and Transformer models, who also contribute back to the community by sharing their models: +## Transformersは至るところに! Transformerモデルは前節で述べたようなあらゆる種類のNLPタスクを解決するために使用されています。ここでは、Hugging FaceとTransformerモデルを使用している企業や組織を紹介します。それらの組織はまた、モデルを共有することでコミュニティに還元しています。 Companies using Hugging Face -The [🤗 Transformers library](https://github.com/huggingface/transformers) provides the functionality to create and use those shared models. The [Model Hub](https://huggingface.co/models) contains thousands of pretrained models that anyone can download and use. You can also upload your own models to the Hub! - [🤗 Transformers library](https://github.com/huggingface/transformers)は、それらの共有モデルを作成し、使用するための機能を提供します。[Model Hub](https://huggingface.co/models)には、誰でもダウンロードして使用できる何千もの事前学習済みモデルが含まれています。また、あなた自身のモデルをModel Hubにアップロードすることも可能です。 -⚠️ The Hugging Face Hub is not limited to Transformer models. Anyone can share any kind of models or datasets they want! Create a huggingface.co account to benefit from all available features! - - ⚠️Hugging Face Hubはトランスフォーマーモデルに限定されるものではありません。誰でも好きな種類のモデルやデータセットを共有することができます!すべての利用可能な機能の恩恵を受けるためにhuggingface.coのアカウントを作成しましょう! + -Before diving into how Transformer models work under the hood, let's look at a few examples of how they can be used to solve some interesting NLP problems. +
Transformerのモデルがどのように機能するのかを知る前に、いくつかの興味深いNLPの問題を解決するため、Transformerがどのように使われるのか、いくつかの例で見ていきましょう。 -## Working with pipelines pipelinesを使ったタスク +## pipelineを使ってタスクを実行する -The most basic object in the 🤗 Transformers library is the `pipeline()` function. It connects a model with its necessary preprocessing and postprocessing steps, allowing us to directly input any text and get an intelligible answer: - 🤗 Transformers ライブラリの中で最も基本的なオブジェクトは `pipeline()` 関数です。これはモデルを必要な前処理と後処理のステップに接続し、任意のテキストを直接入力して理解しやすい答えを得ることを可能にします。 ```python @@ -61,8 +48,6 @@ classifier("I've been waiting for a HuggingFace course my whole life.") [{'label': 'POSITIVE', 'score': 0.9598047137260437}] ``` -We can even pass several sentences! - 複数の文章を入力することも可能です。 ```python @@ -76,39 +61,14 @@ classifier( {'label': 'NEGATIVE', 'score': 0.9994558095932007}] ``` -By default, this pipeline selects a particular pretrained model that has been fine-tuned for sentiment analysis in English. The model is downloaded and cached when you create the `classifier` object. If you rerun the command, the cached model will be used instead and there is no need to download the model again. - デフォルトでは、このpipelineは英語の感情分析用にファインチューニングされた特定の事前学習モデルを使用します。このモデルは `classifier` オブジェクトを作成する際にダウンロードされ、キャッシュされます。コマンドを再実行すると、キャッシュされたモデルが代わりに使用され、モデルを再度ダウンロードする必要はありません。 - -There are three main steps involved when you pass some text to a pipeline: - -1. The text is preprocessed into a format the model can understand. -2. The preprocessed inputs are passed to the model. -3. The predictions of the model are post-processed, so you can make sense of them. - - pipelineにテキストを渡す場合、主に3つのステップがあります。 1. テキストはモデルが理解できる形式に前処理される。 2. 前処理された入力がモデルに渡される。 3. 予測結果を理解できるように、モデルの後処理が行われる。 - -Some of the currently [available pipelines](https://huggingface.co/transformers/main_classes/pipelines.html) are: - -- `feature-extraction` (get the vector representation of a text) -- `fill-mask` -- `ner` (named entity recognition) -- `question-answering` -- `sentiment-analysis` -- `summarization` -- `text-generation` -- `translation` -- `zero-shot-classification` - -Let's have a look at a few of these! - 現在[利用可能なpipeline](https://huggingface.co/transformers/main_classes/pipelines.html)の一部を紹介します。 - `feature-extraction` (テキストのベクトル表現を取得) @@ -121,11 +81,9 @@ Let's have a look at a few of these! - `translation` - `zero-shot-classification` -では、いくつか見ていきましょう。 - -## Zero-shot classification ゼロショット分類 +では、いくつか見ていきましょう! -We'll start by tackling a more challenging task where we need to classify texts that haven't been labelled. This is a common scenario in real-world projects because annotating text is usually time-consuming and requires domain expertise. For this use case, the `zero-shot-classification` pipeline is very powerful: it allows you to specify which labels to use for the classification, so you don't have to rely on the labels of the pretrained model. You've already seen how the model can classify a sentence as positive or negative using those two labels — but it can also classify the text using any other set of labels you like. +## ゼロショット分類 まず、ラベル付けされていないテキストを分類する必要があるような、より困難なタスクに取り組むことから始めます。これは実際のプロジェクトでよくあるシナリオです。なぜなら、テキストにアノテーションをつけるのは通常時間がかかり、専門知識が必要だからです。このような場合、`zero-shot-classification` pipelineは非常に強力です。分類に使用するラベルを指定できるので、事前に学習したモデルのラベルに依存する必要がありません。肯定的か否定的かの2つのラベルを使って、モデルがどのようにテキストを分類するかは既に見たとおりです。しかし、他の任意のラベルセットを使ってテキストを分類することもできます。 @@ -145,21 +103,15 @@ classifier( 'scores': [0.8445963859558105, 0.111976258456707, 0.043427448719739914]} ``` -This pipeline is called _zero-shot_ because you don't need to fine-tune the model on your data to use it. It can directly return probability scores for any list of labels you want! - -このpipelineは _zero-shot_ と呼ばれる。なぜなら、これを使うために自前のデータセットでモデルのファインチューニングをする必要がないからです。任意のラベルのリストに対して直接確率スコアを返すことができます。 +このpipelineは _zero-shot_ と呼ばれます。なぜなら、これを使うために自前のデータセットでモデルのファインチューニングをする必要がないからです。任意のラベルのリストに対して直接確率スコアを返すことができます。 -✏️ **Try it out!** Play around with your own sequences and labels and see how the model behaves. - ✏️ **試してみよう!** 独自の入力とラベルで遊んでみて、モデルがどのように振る舞うか見てみましょう。 -## Text generation 文章生成 - -Now let's see how to use a pipeline to generate some text. The main idea here is that you provide a prompt and the model will auto-complete it by generating the remaining text. This is similar to the predictive text feature that is found on many phones. Text generation involves randomness, so it's normal if you don't get the same results as shown below. +## 文章生成 では、pipelineを使ってテキストを生成する方法を見てみましょう。主なアイデアは、プロンプトを与えると、モデルが残りのテキストを生成してそれを補完することです。これは、多くの携帯電話に搭載されている予測入力機能に類似しています。テキスト生成にはランダム性が含まれるため、以下と同様な結果が得られないのが通常です。 @@ -177,24 +129,17 @@ generator("In this course, we will teach you how to") 'HTTP'}] ``` -You can control how many different sequences are generated with the argument `num_return_sequences` and the total length of the output text with the argument `max_length`. - 引数`num_return_sequences`で異なるシーケンスの生成数を、引数`max_length`で出力テキストの合計の長さを制御することができます。 -✏️ **Try it out!** Use the `num_return_sequences` and `max_length` arguments to generate two sentences of 15 words each. -✏️ **試してみよう!** `num_return_sequences` と `max_length` 引数を用いて、15語ずつの2つの文を生成することができます。 +✏️ **試してみよう!** `num_return_sequences` と `max_length` 引数を用いて、15語ずつの2つの文を生成してみましょう! -## Using any model from the Hub in a pipeline pipelineでHubから任意のモデルを使用する - -The previous examples used the default model for the task at hand, but you can also choose a particular model from the Hub to use in a pipeline for a specific task — say, text generation. Go to the [Model Hub](https://huggingface.co/models) and click on the corresponding tag on the left to display only the supported models for that task. You should get to a page like [this one](https://huggingface.co/models?pipeline_tag=text-generation). - -Let's try the [`distilgpt2`](https://huggingface.co/distilgpt2) model! Here's how to load it in the same pipeline as before: +## pipelineでHubから任意のモデルを使用する これまでの例では、タスクに応じたデフォルトのモデルを使用しましたが、特定のタスク(例えばテキスト生成)のpipelineで使用するモデルをHubから選択することも可能です。[Model Hub](https://huggingface.co/models)にアクセスし、左側の対応するタグをクリックすると、そのタスクでサポートされているモデルのみが表示されます。[このようなページ](https://huggingface.co/models?pipeline_tag=text-generation)が表示されるはずです。 @@ -218,36 +163,24 @@ generator( 'time and real'}] ``` -You can refine your search for a model by clicking on the language tags, and pick a model that will generate text in another language. The Model Hub even contains checkpoints for multilingual models that support several languages. - -Once you select a model by clicking on it, you'll see that there is a widget enabling you to try it directly online. This way you can quickly test the model's capabilities before downloading it. - 言語タグをクリックして検索するモデルを絞り込み、他の言語でテキストを生成するモデルを選ぶことができます。Model Hubには、複数の言語をサポートする多言語モデルのチェックポイントもあります。 モデルをクリックで選択すると、オンラインで直接試用できるウィジェットが表示されます。このようにして、ダウンロードする前にモデルの機能をすばやくテストすることができます。 -✏️ **Try it out!** Use the filters to find a text generation model for another language. Feel free to play with the widget and use it in a pipeline! - -✏️ **試してみよう!** フィルタ-を使って、他の言語のテキスト生成モデルを探してみましょう。ウィジェットで自由に遊んだり、pipelineで使ってみてください! +✏️ **試してみよう!** フィルターを使って、他の言語のテキスト生成モデルを探してみましょう。ウィジェットで自由に遊んだり、pipelineで使ってみてください! -### The Inference API 推論API - -All the models can be tested directly through your browser using the Inference API, which is available on the Hugging Face [website](https://huggingface.co/). You can play with the model directly on this page by inputting custom text and watching the model process the input data. - -The Inference API that powers the widget is also available as a paid product, which comes in handy if you need it for your workflows. See the [pricing page](https://huggingface.co/pricing) for more details. +### 推論API -すべてのモデルは、Hugging Face [ウェブサイト](https://huggingface.co/)で公開されているInference APIを使って、ブラウザから直接テストすることが可能です。このページでは、カスタムテキストを入力し、モデルが入力データを処理する様子を見ることで、直接モデルで遊ぶことができます。 +すべてのモデルは、Hugging Face [ウェブサイト](https://huggingface.co/)で公開されているInference APIを使って、ブラウザから直接テストすることが可能です。このページでは、任意の文字列を入力し、モデルが入力データを処理する様子を見ることで、直接モデルで遊ぶことができます。 このウィジェットを動かすInference APIは、有料製品としても提供されており、ワークフローに必要な場合は便利です。詳しくは[価格ページ](https://huggingface.co/pricing)をご覧ください。 -## Mask filling 空所穴埋め - -The next pipeline you'll try is `fill-mask`. The idea of this task is to fill in the blanks in a given text: +## 空所穴埋め 次に試すpipelineは`fill-mask`です。このタスクのアイデアは、与えられたテキストの空白を埋めることです。 @@ -268,21 +201,15 @@ unmasker("This course will teach you all about models.", top_k=2) 'token_str': ' computational'}] ``` -The `top_k` argument controls how many possibilities you want to be displayed. Note that here the model fills in the special `` word, which is often referred to as a *mask token*. Other mask-filling models might have different mask tokens, so it's always good to verify the proper mask word when exploring other models. One way to check it is by looking at the mask word used in the widget. - `top_k` 引数は、いくつの可能性を表示させたいかをコントロールします。ここでは、モデルが特別な `` という単語を埋めていることに注意してください。これはしばしば *mask token* と呼ばれます。他の空所穴埋めモデルは異なるマスクトークンを持つかもしれないので、他のモデルを探索するときには常に適切なマスクワードを確認するのが良いでしょう。それを確認する1つの方法は、ウィジェットで使用されているマスクワードを見ることです。 -✏️ **Try it out!** Search for the `bert-base-cased` model on the Hub and identify its mask word in the Inference API widget. What does this model predict for the sentence in our `pipeline` example above? - ✏️ **試してみよう!** Hub で `bert-base-cased` モデルを検索し、推論API ウィジェットでそのマスクワードを特定します。このモデルは上記の `pipeline` の例文に対して何を予測するでしょうか? -## Named entity recognition 固有表現認識 - -Named entity recognition (NER) is a task where the model has to find which parts of the input text correspond to entities such as persons, locations, or organizations. Let's look at an example: +## 固有表現認識 固有表現認識(NER)は、入力されたテキストのどの部分が人物、場所、組織などの固有表現に対応するかをモデルが見つけ出すタスクです。例を見てみましょう。 @@ -299,25 +226,17 @@ ner("My name is Sylvain and I work at Hugging Face in Brooklyn.") ] ``` -Here the model correctly identified that Sylvain is a person (PER), Hugging Face an organization (ORG), and Brooklyn a location (LOC). - -We pass the option `grouped_entities=True` in the pipeline creation function to tell the pipeline to regroup together the parts of the sentence that correspond to the same entity: here the model correctly grouped "Hugging" and "Face" as a single organization, even though the name consists of multiple words. In fact, as we will see in the next chapter, the preprocessing even splits some words into smaller parts. For instance, `Sylvain` is split into four pieces: `S`, `##yl`, `##va`, and `##in`. In the post-processing step, the pipeline successfully regrouped those pieces. - ここでは、モデルはSylvainが人(PER)、Hugging Faceが組織(ORG)、Brooklynが場所(LOC)であることを正しく識別しています。 pipelineの作成機能でオプション `grouped_entities=True` を渡すと、同じエンティティに対応する文の部分を再グループ化するようpipelineに指示します。ここでは、名前が複数の単語で構成されていても、モデルは "Hugging" と "Face" を一つの組織として正しくグループ化しています。実際、次の章で説明するように、前処理ではいくつかの単語をより小さなパーツに分割することさえあります。例えば、`Sylvain`は4つの部分に分割されます。`S`, `##yl`, `##va`, and `##in`.です。後処理の段階で、pipelineはこれらの断片をうまく再グループ化しました。 -✏️ **Try it out!** Search the Model Hub for a model able to do part-of-speech tagging (usually abbreviated as POS) in English. What does this model predict for the sentence in the example above? - ✏️ **試してみよう!** Model Hubで英語の品詞タグ付け(通常POSと略される)を行えるモデルを検索してください。このモデルは、上の例の文に対して何を予測するでしょうか? -## Question answering 質問応答 - -The `question-answering` pipeline answers questions using information from a given context: +## 質問応答 質問応答pipelineは、与えられた文脈から得た情報を使って質問に答えます。 @@ -334,13 +253,9 @@ question_answerer( {'score': 0.6385916471481323, 'start': 33, 'end': 45, 'answer': 'Hugging Face'} ``` -Note that this pipeline works by extracting information from the provided context; it does not generate the answer. - このpipelineは、提供されたコンテキストから情報を抽出することで動作し、答えを生成するわけではないことに注意してください。 -## Summarization 要約 - -Summarization is the task of reducing a text into a shorter text while keeping all (or most) of the important aspects referenced in the text. Here's an example: +## 要約 要約とは、文章中の重要な部分をすべて(あるいはほとんど)維持したまま、より短い文章にするタスクです。以下はその例です。 @@ -380,14 +295,10 @@ summarizer( 'and advance engineering .'}] ``` -Like with text generation, you can specify a `max_length` or a `min_length` for the result. - テキスト生成と同様に、結果に対して `max_length` や `min_length` を指定することができます。 -## Translation 翻訳 - -For translation, you can use a default model if you provide a language pair in the task name (such as `"translation_en_to_fr"`), but the easiest way is to pick the model you want to use on the [Model Hub](https://huggingface.co/models). Here we'll try translating from French to English: +## 翻訳 翻訳の場合、タスク名に言語ペアを指定すれば(`"translation_en_to_fr"`など)デフォルトのモデルを使うこともできますが、一番簡単なのは [Model Hub](https://huggingface.co/models) で使いたいモデルを選ぶことです。ここでは、フランス語から英語への翻訳を試してみます。 @@ -401,18 +312,12 @@ translator("Ce cours est produit par Hugging Face.") [{'translation_text': 'This course is produced by Hugging Face.'}] ``` -Like with text generation and summarization, you can specify a `max_length` or a `min_length` for the result. - テキスト生成や要約と同様に、結果に対して `max_length` や `min_length` を指定することができます。 -✏️ **Try it out!** Search for translation models in other languages and try to translate the previous sentence into a few different languages. - ✏️ **試してみよう!** 他言語の翻訳モデルを検索して、前の文章をいくつかの異なる言語に翻訳してみましょう。 -The pipelines shown so far are mostly for demonstrative purposes. They were programmed for specific tasks and cannot perform variations of them. In the next chapter, you'll learn what's inside a `pipeline()` function and how to customize its behavior. - これまで紹介したpipelineは、ほとんどがデモンストレーションのためのものです。これらは特定のタスクのためにプログラムされたものであり、それらのバリエーションを実行することはできません。次の章では、`pipeline()`関数の中身と、その動作をカスタマイズする方法を学びます。 From 5f2493a73f8d29209db97e1da26cc4dbc5b0862b Mon Sep 17 00:00:00 2001 From: blackdoor571 Date: Fri, 4 Nov 2022 20:01:26 +0900 Subject: [PATCH 3/4] modify _toctree.yml --- chapters/ja/_toctree.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/chapters/ja/_toctree.yml b/chapters/ja/_toctree.yml index c1d0fcd7f..bc41da1f9 100644 --- a/chapters/ja/_toctree.yml +++ b/chapters/ja/_toctree.yml @@ -7,6 +7,10 @@ sections: - local: chapter1/1 title: イントロダクション + - local: chapter1/2 + title: 自然言語処理 / NLP(Natural Language Processing) + - local: chapter1/3 + title: Transformersで何ができる? - title: 4. モデルとトークナイザーの共有 sections: From 7a365f36445abe00e3453b75a18ef30cae2f0b30 Mon Sep 17 00:00:00 2001 From: Younes Belkada <49240599+younesbelkada@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:08:55 +0100 Subject: [PATCH 4/4] make style --- chapters/ja/chapter1/3.mdx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/chapters/ja/chapter1/3.mdx b/chapters/ja/chapter1/3.mdx index 73a205308..93803b215 100644 --- a/chapters/ja/chapter1/3.mdx +++ b/chapters/ja/chapter1/3.mdx @@ -40,6 +40,7 @@ Transformerのモデルがどのように機能するのかを知る前に、い ```python from transformers import pipeline + classifier = pipeline("sentiment-analysis") classifier("I've been waiting for a HuggingFace course my whole life.") ``` @@ -90,6 +91,7 @@ pipelineにテキストを渡す場合、主に3つのステップがありま ```python from transformers import pipeline + classifier = pipeline("zero-shot-classification") classifier( "This is a course about the Transformers library", @@ -117,6 +119,7 @@ classifier( ```python from transformers import pipeline + generator = pipeline("text-generation") generator("In this course, we will teach you how to") ``` @@ -147,6 +150,7 @@ generator("In this course, we will teach you how to") ```python from transformers import pipeline + generator = pipeline("text-generation", model="distilgpt2") generator( "In this course, we will teach you how to", @@ -186,6 +190,7 @@ generator( ```python from transformers import pipeline + unmasker = pipeline("fill-mask") unmasker("This course will teach you all about models.", top_k=2) ``` @@ -215,6 +220,7 @@ unmasker("This course will teach you all about models.", top_k=2) ```python from transformers import pipeline + ner = pipeline("ner", grouped_entities=True) ner("My name is Sylvain and I work at Hugging Face in Brooklyn.") ``` @@ -242,6 +248,7 @@ pipelineの作成機能でオプション `grouped_entities=True` を渡すと ```python from transformers import pipeline + question_answerer = pipeline("question-answering") question_answerer( question="Where do I work?", @@ -261,6 +268,7 @@ question_answerer( ```python from transformers import pipeline + summarizer = pipeline("summarization") summarizer( """ @@ -304,6 +312,7 @@ summarizer( ```python from transformers import pipeline + translator = pipeline("translation", model="Helsinki-NLP/opus-mt-fr-en") translator("Ce cours est produit par Hugging Face.") ```