🚀 多语言词性标注模型
本项目提供了使用Hugging Face进行词性标注的脚本,可提取文本中的词性信息,还能自动检测和提取名词与停用词。同时,对多语言词性标注模型的评估框架和训练配置进行了概述。
🚀 快速开始
本项目提供了使用Hugging Face进行词性标注的脚本,可提取文本中的词性信息,还能自动检测和提取名词与停用词。
✨ 主要特性
- 多语言支持:能够处理多种语言的词性标注任务。
- 词性分类:可以准确识别不同词性的类别。
- 停用词提取:自动检测并提取文本中的名词和停用词。
📦 安装指南
本项目依赖于Hugging Face的transformers
库,可使用以下命令进行安装:
pip install transformers
💻 使用示例
基础用法
以下代码展示了如何使用Hugging Face的pipeline
进行词性标注:
from transformers import pipeline
pos_pipeline = pipeline("token-classification", model="jordigonzm/mdeberta-v3-base-multilingual-pos-tagger")
text = "On January 3rd, 2024, the $5.7M prototype—a breakthrough in AI-driven robotics—successfully passed all 37 rigorous performance tests!"
words = text.split(" ")
tokens = pos_pipeline(words)
for word, group_token in zip(words, tokens):
print(f"{word:<15}", end=" ")
for token in group_token:
print(f"{token['word']:<8} → {token['entity']:<8}", end=" | ")
print("\n" + "-" * 80)
高级用法
以下代码展示了如何进行词性标注并提取名词和停用词:
from transformers import pipeline
pos_pipeline = pipeline("ner", model="jordigonzm/mdeberta-v3-base-multilingual-pos-tagger")
text = "Companies interested in providing the service must take care of signage and information boards."
tokens = pos_pipeline(text)
print("\nTokens POS tagging:")
for token in tokens:
print(f"{token['word']:10} → {token['entity']}")
words, buffer, labels = [], [], []
for token in tokens:
raw_word = token["word"]
if raw_word.startswith("▁"):
if buffer:
words.append("".join(buffer))
labels.append(buffer_label)
buffer = [raw_word.replace("▁", "")]
buffer_label = token["entity"]
else:
buffer.append(raw_word)
if buffer:
words.append("".join(buffer))
labels.append(buffer_label)
print("\nPOS tagging results:")
for word, label in zip(words, labels):
print(f"{word:<15} → {label}")
noun_tags = {"NOUN", "PROPN"}
stopword_tags = {"DET", "ADP", "PRON", "AUX", "CCONJ", "SCONJ", "PART"}
filtered_nouns = [word for word, tag in zip(words, labels) if tag in noun_tags]
stopwords = [word for word, tag in zip(words, labels) if tag in stopword_tags]
print("\nFiltered Nouns and Proper Nouns:", filtered_nouns)
print("\nStopwords detected:", stopwords)
📚 详细文档
多语言词性标注概述
本报告概述了多语言词性标注模型的评估框架和潜在的训练配置。该模型基于Transformer架构,并在有限的训练轮次后进行评估。
预期范围
属性 |
详情 |
验证损失 |
通常在0.02 到0.1 之间,具体取决于数据集的复杂性和正则化。 |
总体精度 |
预期范围为96% 到99% ,受数据集多样性和分词质量的影响。 |
总体召回率 |
通常在96% 到99% 之间,受与精度类似的因素影响。 |
总体F1分数 |
预期范围为96% 到99% ,平衡了精度和召回率。 |
总体准确率 |
可能在97% 到99.5% 之间,取决于语言变体和模型的鲁棒性。 |
评估速度 |
通常为100 - 150样本/秒 或 25 - 40步/秒 ,取决于批量大小和硬件。 |
训练配置
属性 |
详情 |
模型 |
基于Transformer的架构(如BERT、RoBERTa、XLM - R) |
训练轮次 |
2 到5 ,取决于收敛情况和验证性能。 |
批量大小 |
1 到16 ,平衡内存限制和稳定性。 |
学习率 |
1e - 6 到5e - 4 ,根据优化动态和预热策略进行调整。 |