🚀 土耳其语文本分类
本模型是基于https://github.com/stefan-it/turkish - bert 进行微调的模型,使用了文本分类数据,该数据包含以下7个类别:
code_to_label={
'LABEL_0': '世界 ',
'LABEL_1': '经济 ',
'LABEL_2': '文化 ',
'LABEL_3': '健康 ',
'LABEL_4': '政治 ',
'LABEL_5': '体育 ',
'LABEL_6': '科技 '}
🚀 快速开始
首先,按照以下方式安装transformers库:
pip install transformers
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("savasy/bert-turkish-text-classification")
model = AutoModelForSequenceClassification.from_pretrained("savasy/bert-turkish-text-classification")
nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
nlp("bla bla")
code_to_label = {
'LABEL_0': '世界 ',
'LABEL_1': '经济 ',
'LABEL_2': '文化 ',
'LABEL_3': '健康 ',
'LABEL_4': '政治 ',
'LABEL_5': '体育 ',
'LABEL_6': '科技 '}
code_to_label[nlp("bla bla")[0]['label']]
💻 使用示例
基础用法
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("savasy/bert-turkish-text-classification")
model = AutoModelForSequenceClassification.from_pretrained("savasy/bert-turkish-text-classification")
nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
nlp("bla bla")
code_to_label = {
'LABEL_0': '世界 ',
'LABEL_1': '经济 ',
'LABEL_2': '文化 ',
'LABEL_3': '健康 ',
'LABEL_4': '政治 ',
'LABEL_5': '体育 ',
'LABEL_6': '科技 '}
code_to_label[nlp("bla bla")[0]['label']]
高级用法
import pandas as pd
df = pd.read_csv("7allV03.csv")
df.columns = ["labels", "text"]
df.labels = pd.Categorical(df.labels)
traind_df = ...
eval_df = ...
from simpletransformers.classification import ClassificationModel
import torch, sklearn
model_args = {
"use_early_stopping": True,
"early_stopping_delta": 0.01,
"early_stopping_metric": "mcc",
"early_stopping_metric_minimize": False,
"early_stopping_patience": 5,
"evaluate_during_training_steps": 1000,
"fp16": False,
"num_train_epochs": 3
}
model = ClassificationModel(
"bert",
"dbmdz/bert-base-turkish-cased",
use_cuda=cuda_available,
args=model_args,
num_labels=7
)
model.train_model(train_df, acc=sklearn.metrics.accuracy_score)
📚 详细文档
如需了解土耳其语文本分类的详细用法,请查看 Python笔记本
🔧 技术细节
本模型是基于https://github.com/stefan-it/turkish - bert 进行微调的,使用了以下土耳其语基准数据集进行微调:https://www.kaggle.com/savasy/ttc4900 。对于其他训练模型,请查看https://simpletransformers.ai/ 。
📄 许可证
引用
如需引用,请参考以下论文:
@misc{yildirim2024finetuning,
title={Fine-tuning Transformer-based Encoder for Turkish Language Understanding Tasks},
author={Savas Yildirim},
year={2024},
eprint={2401.17396},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
@book{yildirim2021mastering,
title={Mastering Transformers: Build state-of-the-art models from scratch with advanced natural language processing techniques},
author={Yildirim, Savas and Asgari-Chenaghlu, Meysam},
year={2021},
publisher={Packt Publishing Ltd}
}
📦 安装指南
在使用该模型前,需要安装transformers库:
pip install transformers
📋 信息表格
属性 |
详情 |
模型类型 |
基于微调的BERT模型进行土耳其语文本分类 |
训练数据 |
https://www.kaggle.com/savasy/ttc4900 |