🚀 ゼロショット分類モデル
このモデルは、kor_nliのmnliとxnliでklue/roberta-baseモデルをファインチューニングしたものです。
🚀 クイックスタート
このモデルは、以下のリンクを参考に作成されました: https://github.com/Huffon/klue-transformers-tutorial.git
✨ 主な機能
- ゼロショット分類タスクに対応
- RoBERTaベースのモデルをkor_nliデータセットでファインチューニング
📦 インストール
インストールに関する具体的な手順は提供されていません。
💻 使用例
基本的な使用法
class ArgumentHandler(ABC):
"""
Base interface for handling arguments for each :class:`~transformers.pipelines.Pipeline`.
"""
@abstractmethod
def __call__(self, *args, **kwargs):
raise NotImplementedError()
class CustomZeroShotClassificationArgumentHandler(ArgumentHandler):
"""
Handles arguments for zero-shot for text classification by turning each possible label into an NLI
premise/hypothesis pair.
"""
def _parse_labels(self, labels):
if isinstance(labels, str):
labels = [label.strip() for label in labels.split(",")]
return labels
def __call__(self, sequences, labels, hypothesis_template):
if len(labels) == 0 or len(sequences) == 0:
raise ValueError("You must include at least one label and at least one sequence.")
if hypothesis_template.format(labels[0]) == hypothesis_template:
raise ValueError(
(
'The provided hypothesis_template "{}" was not able to be formatted with the target labels. '
"Make sure the passed template includes formatting syntax such as {{}} where the label should go."
).format(hypothesis_template)
)
if isinstance(sequences, str):
sequences = [sequences]
labels = self._parse_labels(labels)
sequence_pairs = []
for label in labels:
sequence_pairs.append(f"{sequences} {tokenizer.sep_token} {hypothesis_template.format(label)}")
return sequence_pairs, sequences
高度な使用法
classifier = pipeline(
"zero-shot-classification",
args_parser=CustomZeroShotClassificationArgumentHandler(),
model="pongjin/roberta_with_kornli"
)
sequence = "배당락 D-1 코스피, 2330선 상승세...외인·기관 사자"
candidate_labels =["외환",'환율', "경제", "금융", "부동산","주식"]
classifier(
sequence,
candidate_labels,
hypothesis_template='이는 {}에 관한 것이다.',
)
>>{'sequence': '배당락 D-1 코스피, 2330선 상승세...외인·기관 사자',
'labels': ['주식', '금융', '경제', '외환', '환율', '부동산'],
'scores': [0.5052872896194458,
0.17972524464130402,
0.13852974772453308,
0.09460823982954025,
0.042949128895998,
0.038900360465049744]}
📚 ドキュメント
RoBERTaのようにtoken_type_idsを使用しないモデルの場合、zero-shot pipelineを直接適用することはできません(transformers==4.7.0基準)。そのため、上記のコードのように変換するコードを追加する必要があります。
学習情報
項目 |
詳細 |
モデルタイプ |
klue/roberta-baseをkor_nliでファインチューニングしたモデル |
学習データ |
kor_nliのmnli, xnli |
学習ログ
train_loss |
val_loss |
acc |
epoch |
batch |
lr |
0.326 |
0.538 |
0.811 |
3 |
32 |
2e-5 |
📄 ライセンス
このモデルはApache-2.0ライセンスの下で提供されています。