🚀 MiniLM-L6-mnli
這是一個用於文本分類和零樣本分類的模型,基於MiniLM-L6架構,在MultiNLI數據集上訓練,速度快但精度略遜於其他模型。
🚀 快速開始
本模型可用於文本分類和零樣本分類任務,以下是使用示例:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name = "MoritzLaurer/MiniLM-L6-mnli"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
premise = "I liked the movie"
hypothesis = "The movie was good."
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
output = model(input["input_ids"].to(device))
prediction = torch.softmax(output["logits"][0], -1).tolist()
label_names = ["entailment", "neutral", "contradiction"]
prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
print(prediction)
✨ 主要特性
- 適用任務:適用於文本分類和零樣本分類任務。
- 基礎模型:基於微軟的MiniLM-L6,速度快,但精度略低於其他模型。
📦 安裝指南
文檔未提及具體安裝步驟,可參考Hugging Face相關庫的安裝方式來安裝所需依賴。
💻 使用示例
基礎用法
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name = "MoritzLaurer/MiniLM-L6-mnli"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
premise = "I liked the movie"
hypothesis = "The movie was good."
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
output = model(input["input_ids"].to(device))
prediction = torch.softmax(output["logits"][0], -1).tolist()
label_names = ["entailment", "neutral", "contradiction"]
prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
print(prediction)
📚 詳細文檔
訓練數據
模型使用MultiNLI數據集進行訓練。
訓練過程
MiniLM-L6-mnli-binary使用Hugging Face的訓練器進行訓練,超參數如下:
training_args = TrainingArguments(
num_train_epochs=5, # total number of training epochs
learning_rate=2e-05,
per_device_train_batch_size=32, # batch size per device during training
per_device_eval_batch_size=32, # batch size for evaluation
warmup_ratio=0.1, # number of warmup steps for learning rate scheduler
weight_decay=0.06, # strength of weight decay
fp16=True # mixed precision training
)
評估結果
模型使用MultiNLI的(匹配)測試集進行評估,準確率為0.814。
🔧 技術細節
- 模型基於微軟的MiniLM-L6架構,在MultiNLI數據集上進行訓練。
- 使用Hugging Face的訓練器進行訓練,並設置了一系列超參數。
📄 許可證
文檔未提及許可證相關信息。
引用信息
如果您想引用此模型,請引用原始的MiniLM論文、相應的NLI數據集,幷包含此模型在Hugging Face hub上的鏈接。
屬性 |
詳情 |
模型類型 |
用於文本分類和零樣本分類的模型 |
訓練數據 |
MultiNLI |
⚠️ 重要提示
請參考原始的MiniLM論文和不同NLI數據集的相關文獻,以瞭解潛在的偏差。