190 lines
6.0 KiB
Markdown
190 lines
6.0 KiB
Markdown
|
|
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
|
||
|
|
|
||
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||
|
|
the License. You may obtain a copy of the License at
|
||
|
|
|
||
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
|
||
|
|
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||
|
|
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||
|
|
specific language governing permissions and limitations under the License.
|
||
|
|
|
||
|
|
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
|
||
|
|
rendered properly in your Markdown viewer.
|
||
|
|
|
||
|
|
-->
|
||
|
|
|
||
|
|
# Model outputs
|
||
|
|
|
||
|
|
すべてのモデルには、[`~utils.ModelOutput`] のサブクラスのインスタンスである出力があります。それらは
|
||
|
|
モデルによって返されるすべての情報を含むデータ構造ですが、タプルまたは
|
||
|
|
辞書。
|
||
|
|
|
||
|
|
これがどのようになるかを例で見てみましょう。
|
||
|
|
|
||
|
|
```python
|
||
|
|
from transformers import BertTokenizer, BertForSequenceClassification
|
||
|
|
import torch
|
||
|
|
|
||
|
|
tokenizer = BertTokenizer.from_pretrained("google-bert/bert-base-uncased")
|
||
|
|
model = BertForSequenceClassification.from_pretrained("google-bert/bert-base-uncased")
|
||
|
|
|
||
|
|
inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
|
||
|
|
labels = torch.tensor([1]).unsqueeze(0) # Batch size 1
|
||
|
|
outputs = model(**inputs, labels=labels)
|
||
|
|
```
|
||
|
|
|
||
|
|
`outputs`オブジェクトは[`~modeling_outputs.SequenceClassifierOutput`]である。
|
||
|
|
これは、オプションで `loss`、`logits`、オプションで `hidden_states`、オプションで `attentions` 属性を持つことを意味します。
|
||
|
|
オプションの `attentions` 属性を持つことを意味する。ここでは、`labels`を渡したので`loss`があるが、`hidden_states`と`attentions`はない。
|
||
|
|
`output_hidden_states=True`や`output_attentions=True`を渡していないので、`hidden_states`と`attentions`はない。
|
||
|
|
`output_attentions=True`を渡さなかったからだ。
|
||
|
|
|
||
|
|
<Tip>
|
||
|
|
|
||
|
|
`output_hidden_states=True`を渡すと、`outputs.hidden_states[-1]`が `outputs.last_hidden_states` と正確に一致することを期待するかもしれない。
|
||
|
|
しかし、必ずしもそうなるとは限りません。モデルによっては、最後に隠された状態が返されたときに、正規化やその後の処理を適用するものもあります。
|
||
|
|
|
||
|
|
</Tip>
|
||
|
|
|
||
|
|
|
||
|
|
通常と同じように各属性にアクセスできます。その属性がモデルから返されなかった場合は、
|
||
|
|
は `None`を取得します。ここで、たとえば`outputs.loss`はモデルによって計算された損失であり、`outputs.attentions`は
|
||
|
|
`None`。
|
||
|
|
|
||
|
|
`outputs`オブジェクトをタプルとして考える場合、`None`値を持たない属性のみが考慮されます。
|
||
|
|
たとえば、ここには 2 つの要素、`loss`、次に`logits`があります。
|
||
|
|
|
||
|
|
```python
|
||
|
|
outputs[:2]
|
||
|
|
```
|
||
|
|
|
||
|
|
たとえば、タプル `(outputs.loss, Outputs.logits)` を返します。
|
||
|
|
|
||
|
|
`outputs`オブジェクトを辞書として考慮する場合、「None」を持たない属性のみが考慮されます。
|
||
|
|
価値観。たとえば、ここには`loss` と `logits`という 2 つのキーがあります。
|
||
|
|
|
||
|
|
ここでは、複数のモデル タイプで使用される汎用モデルの出力を文書化します。具体的な出力タイプは次のとおりです。
|
||
|
|
対応するモデルのページに記載されています。
|
||
|
|
|
||
|
|
## ModelOutput
|
||
|
|
|
||
|
|
[[autodoc]] utils.ModelOutput
|
||
|
|
- to_tuple
|
||
|
|
|
||
|
|
## BaseModelOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.BaseModelOutput
|
||
|
|
|
||
|
|
## BaseModelOutputWithPooling
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.BaseModelOutputWithPooling
|
||
|
|
|
||
|
|
## BaseModelOutputWithCrossAttentions
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.BaseModelOutputWithCrossAttentions
|
||
|
|
|
||
|
|
## BaseModelOutputWithPoolingAndCrossAttentions
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.BaseModelOutputWithPoolingAndCrossAttentions
|
||
|
|
|
||
|
|
## BaseModelOutputWithPast
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.BaseModelOutputWithPast
|
||
|
|
|
||
|
|
## BaseModelOutputWithPastAndCrossAttentions
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.BaseModelOutputWithPastAndCrossAttentions
|
||
|
|
|
||
|
|
## Seq2SeqModelOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.Seq2SeqModelOutput
|
||
|
|
|
||
|
|
## CausalLMOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.CausalLMOutput
|
||
|
|
|
||
|
|
## CausalLMOutputWithCrossAttentions
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.CausalLMOutputWithCrossAttentions
|
||
|
|
|
||
|
|
## CausalLMOutputWithPast
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.CausalLMOutputWithPast
|
||
|
|
|
||
|
|
## MaskedLMOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.MaskedLMOutput
|
||
|
|
|
||
|
|
## Seq2SeqLMOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.Seq2SeqLMOutput
|
||
|
|
|
||
|
|
## NextSentencePredictorOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.NextSentencePredictorOutput
|
||
|
|
|
||
|
|
## SequenceClassifierOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.SequenceClassifierOutput
|
||
|
|
|
||
|
|
## Seq2SeqSequenceClassifierOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.Seq2SeqSequenceClassifierOutput
|
||
|
|
|
||
|
|
## MultipleChoiceModelOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.MultipleChoiceModelOutput
|
||
|
|
|
||
|
|
## TokenClassifierOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.TokenClassifierOutput
|
||
|
|
|
||
|
|
## QuestionAnsweringModelOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.QuestionAnsweringModelOutput
|
||
|
|
|
||
|
|
## Seq2SeqQuestionAnsweringModelOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.Seq2SeqQuestionAnsweringModelOutput
|
||
|
|
|
||
|
|
## Seq2SeqSpectrogramOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.Seq2SeqSpectrogramOutput
|
||
|
|
|
||
|
|
## SemanticSegmenterOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.SemanticSegmenterOutput
|
||
|
|
|
||
|
|
## ImageClassifierOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.ImageClassifierOutput
|
||
|
|
|
||
|
|
## ImageClassifierOutputWithNoAttention
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.ImageClassifierOutputWithNoAttention
|
||
|
|
|
||
|
|
## DepthEstimatorOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.DepthEstimatorOutput
|
||
|
|
|
||
|
|
## Wav2Vec2BaseModelOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.Wav2Vec2BaseModelOutput
|
||
|
|
|
||
|
|
## XVectorOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.XVectorOutput
|
||
|
|
|
||
|
|
## Seq2SeqTSModelOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.Seq2SeqTSModelOutput
|
||
|
|
|
||
|
|
## Seq2SeqTSPredictionOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.Seq2SeqTSPredictionOutput
|
||
|
|
|
||
|
|
## SampleTSPredictionOutput
|
||
|
|
|
||
|
|
[[autodoc]] modeling_outputs.SampleTSPredictionOutput
|