🚀 意圖分類模型
本模型可對客戶請求進行意圖分類,通過微調T5模型,利用包含合成數據的提示,能動態地將客戶請求分類到預定義的類別中。
🚀 快速開始
模型使用示例
class IntentClassifier:
def __init__(self, model_name="serj/intent-classifier", device="cuda"):
self.model = T5ForConditionalGeneration.from_pretrained(model_name).to(device)
self.tokenizer = T5Tokenizer.from_pretrained(model_name)
self.device = device
def build_prompt(text, prompt="", company_name="", company_specific=""):
if company_name == "Pizza Mia":
company_specific = "This company is a pizzeria place."
if company_name == "Online Banking":
company_specific = "This company is an online banking."
return f"Company name: {company_name} is doing: {company_specific}\nCustomer: {text}.\nEND MESSAGE\nChoose one topic that matches customer's issue.\n{prompt}\nClass name: "
def predict(self, text, prompt_options, company_name, company_portion) -> str:
input_text = build_prompt(text, prompt_options, company_name, company_portion)
input_ids = self.tokenizer.encode(input_text, return_tensors="pt", max_length=512, truncation=True).to(self.device)
output = self.model.generate(input_ids)
decoded_output = self.tokenizer.decode(output[0], skip_special_tokens=True)
return decoded_output
m = IntentClassifier("serj/intent-classifier")
print(m.predict("Hey, after recent changes, I want to cancel subscription, please help.",
"OPTIONS:\n refund\n cancel subscription\n damaged item\n return item\n", "Company",
"Products and subscriptions"))
提示結構說明
Topic %% Customer: text.
END MESSAGE
OPTIONS:
each class separated by %
Choose one topic that matches customer's issue.
Class name:
你必須在文本末尾加上句號,否則會得到奇怪的結果,這是模型的訓練要求。
✨ 主要特性
本模型通過微調Flan - T5 - Base模型,利用包含合成數據的提示對客戶請求進行意圖分類,可動態地將客戶請求分類到預定義的類別中。
📦 安裝指南
文檔未提供具體安裝步驟,暫不展示。
📚 詳細文檔
模型詳情
模型描述
這是一個🤗 transformers模型的模型卡片,已推送到Hub,此模型卡片是自動生成的。
- 開發者:Serj Smorodinsky
- 模型類型:Flan - T5 - Base
- 語言(NLP):[待補充更多信息]
- 許可證:[待補充更多信息]
- 微調基礎模型:Flan - T5 - Base
模型來源
- 倉庫地址:https://github.com/SerjSmor/intent_classification
訓練詳情
訓練數據
- 訓練數據倉庫:https://github.com/SerjSmor/intent_classification
- 未來將添加HF數據集。
訓練過程
- 訓練腳本地址:https://github.com/SerjSmor/intent_classification/blob/main/t5_generator_trainer.py
- 使用HF trainer進行訓練:
training_args = TrainingArguments(
output_dir='./results',
num_train_epochs=epochs,
per_device_train_batch_size=batch_size,
per_device_eval_batch_size=batch_size,
warmup_steps=500,
weight_decay=0.01,
logging_dir='./logs',
logging_steps=10,
evaluation_strategy="epoch"
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataset,
eval_dataset=val_dataset,
tokenizer=tokenizer,
)
評估
最新版本的模型以少樣本方式在2個合成數據集和clinc_oos的前41個類別上進行了微調。所有數據集每個類別有10 - 20個樣本,訓練數據不包括Atis數據集。
- Atis零樣本測試集評估:加權F1值為87%
- 接下來將進行Clinc測試集評估。
硬件
Nvidia RTX3060 12Gb