Deberta V3 Large Lemon Spell 5k
モデル概要
モデル特徴
モデル能力
使用事例
🚀 モデルIDのモデルカード
このモデルは、英語テキストの文法エラーを検出して修正するために設計された文法エラー修正(GEC)システムです。microsoft/deberta-v3-large
モデルをファインチューニングして作成されており、言語学習者や文法の精度が必要なアプリケーションに役立ちます。
🚀 クイックスタート
以下のコードを使用して、モデルを始めることができます。
from dataclasses import dataclass
from typing import Optional, Tuple
import torch
from torch import nn
from torch.nn import CrossEntropyLoss
from transformers import AutoConfig, AutoTokenizer
from transformers.file_utils import ModelOutput
from transformers.models.deberta_v2.modeling_deberta_v2 import (
DebertaV2Model,
DebertaV2PreTrainedModel,
)
@dataclass
class XGECToROutput(ModelOutput):
"""
Output type of `XGECToRForTokenClassification.forward()`.
loss (`torch.FloatTensor`, optional)
logits_correction (`torch.FloatTensor`) : The correction logits for each token.
logits_detection (`torch.FloatTensor`) : The detection logits for each token.
hidden_states (`Tuple[torch.FloatTensor]`, optional)
attentions (`Tuple[torch.FloatTensor]`, optional)
"""
loss: Optional[torch.FloatTensor] = None
logits_correction: torch.FloatTensor = None
logits_detection: torch.FloatTensor = None
hidden_states: Optional[Tuple[torch.FloatTensor]] = None
attentions: Optional[Tuple[torch.FloatTensor]] = None
class XGECToRDebertaV3(DebertaV2PreTrainedModel):
"""
This class overrides the GECToR model to include an error detection head in addition to the token classification head.
"""
_keys_to_ignore_on_load_unexpected = [r"pooler"]
_keys_to_ignore_on_load_missing = [r"position_ids"]
def __init__(self, config):
super().__init__(config)
self.num_labels = config.num_labels
self.unk_tag_idx = config.label2id.get("@@UNKNOWN@@", None)
self.deberta = DebertaV2Model(config)
self.classifier = nn.Linear(config.hidden_size, config.num_labels)
if self.unk_tag_idx is not None:
self.error_detector = nn.Linear(config.hidden_size, 3)
else:
self.error_detector = nn.Linear(config.hidden_size, 2)
def forward(
self,
input_ids=None,
attention_mask=None,
token_type_ids=None,
position_ids=None,
inputs_embeds=None,
labels=None,
output_attentions=None,
output_hidden_states=None,
return_dict=None,
):
r"""
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the token classification loss. Indices should be in `[0, ..., config.num_labels - 1]`.
"""
return_dict = (
return_dict if return_dict is not None else self.config.use_return_dict
)
outputs = self.deberta(
input_ids,
attention_mask=attention_mask,
token_type_ids=token_type_ids,
position_ids=position_ids,
inputs_embeds=inputs_embeds,
output_attentions=output_attentions,
output_hidden_states=output_hidden_states,
return_dict=return_dict,
)
sequence_output = outputs[0]
logits_correction = self.classifier(sequence_output)
logits_detection = self.error_detector(sequence_output)
loss = None
if labels is not None:
loss_fct = CrossEntropyLoss()
loss = loss_fct(
logits_correction.view(-1, self.num_labels), labels.view(-1)
)
labels_detection = torch.ones_like(labels)
labels_detection[labels == 0] = 0
labels_detection[labels == -100] = -100 # ignore padding
if self.unk_tag_idx is not None:
labels_detection[labels == self.unk_tag_idx] = 2
loss_detection = loss_fct(
logits_detection.view(-1, 3), labels_detection.view(-1)
)
else:
loss_detection = loss_fct(
logits_detection.view(-1, 2), labels_detection.view(-1)
)
loss += loss_detection
if not return_dict:
output = (
logits_correction,
logits_detection,
) + outputs[2:]
return ((loss,) + output) if loss is not None else output
return XGECToROutput(
loss=loss,
logits_correction=logits_correction,
logits_detection=logits_detection,
hidden_states=outputs.hidden_states,
attentions=outputs.attentions,
)
def get_input_embeddings(self):
return self.deberta.get_input_embeddings()
def set_input_embeddings(self, value):
self.deberta.set_input_embeddings(value)
config = AutoConfig.from_pretrained("manred1997/deberta-v3-large-lemon-spell_5k")
tokenizer = AutoTokenizer.from_pretrained("manred1997/deberta-v3-large-lemon-spell_5k")
model = XGECToRDeberta.from_pretrained(
"manred1997/deberta-v3-large-lemon-spell_5k", config=config
)
✨ 主な機能
モデル詳細
モデルの説明
このモデルは、microsoft/deberta-v3-large
モデルからファインチューニングされた文法エラー修正(GEC)システムです。英語テキストの文法エラーを検出して修正することを目的としており、動詞の時制、名詞の変化、形容詞の使い方などの一般的な文法ミスに焦点を当てています。言語学習者や文法の精度が必要なアプリケーションに特に有用です。
属性 | 详情 |
---|---|
モデルタイプ | シーケンス-to-シーケンス修正を伴うトークン分類 |
言語 (NLP) | 英語 |
ファインチューニング元のモデル | microsoft/deberta-v3-large |
用途
直接利用
このモデルは、英語テキストの文法エラー検出と修正に直接使用できます。ライティングアシスタント、教育ソフトウェア、校正ツールなどに組み込むのに最適です。
下流利用
このモデルは、学術論文、ビジネスコミュニケーション、非公式テキストの修正などの特定のドメインに合わせてファインチューニングすることができます。これにより、コンテキスト固有の文法エラーに対する高精度な修正が可能になります。
適用範囲外の利用
このモデルは、英語以外のテキスト、非文法的な修正(スタイル、トーン、論理など)、基本的な文法構造を超えた複雑なエラーの検出には適していません。
バイアス、リスク、および制限
このモデルは一般的な英語コーパスで学習されているため、非標準の方言(口語など)やドメイン固有の専門用語では性能が低下する可能性があります。学習データの制限により、誤った修正を行ったり、エラーを見逃したりすることがあるため、このようなコンテキストで使用する際には注意が必要です。
推奨事項
このモデルは一般的な性能が高いですが、文法規則が柔軟な専門的または創造的なコンテキストでは、修正内容を手動で確認することをお勧めします。
🔧 技術詳細
学習詳細
学習データ
このモデルは3つの段階で学習されており、各段階で特定のデータセットが必要です。以下に各段階で使用されたデータの説明を示します。
段階 | 使用されたデータセット | 説明 |
---|---|---|
段階1 | PIEコーパスからシャッフルされた900万文(A1部分のみ) | PIEコーパスからの900万文のシャッフルされた文で、A1レベルの文に焦点を当てています。 |
段階2 | NUCLE、FCE、Lang8、W&I + Locnessデータセットのシャッフルされた組み合わせ | Lang8データセットには947,344文が含まれており、52.5%が異なるソース文とターゲット文を持っています。新しいLang8ダンプを使用する場合は、サンプリングを検討してください。 |
段階3 | W&I + Locnessデータセットのシャッフルされたバージョン | W&I + Locnessデータセットの最終的なシャッフルされたバージョンです。 |
評価
テストデータ、要因、および指標
テストデータ
このモデルは、W&I + Locnessテストセットでテストされました。これは、文法エラー修正の標準的なベンチマークです。
指標
主な評価指標としてF0.5が使用されました。これは、モデルが文法エラーを正しく識別して修正する能力を測定します。
結果
F0.5 = 74.61








