🚀 InstaFoodRoBERTa-NER
InstaFoodRoBERTa-NER 是一个经过微调的BERT模型,可用于社交媒体上非正规文本(如Instagram、X、Reddit)中食品实体的命名实体识别。它经过训练,能够识别单一实体:食品(FOOD)。
🚀 快速开始
本模型可与Transformers的 pipeline 结合使用,用于命名实体识别(NER)。
from transformers import AutoTokenizer, AutoModelForTokenClassification
from transformers import pipeline
tokenizer = AutoTokenizer.from_pretrained("Dizex/InstaFoodRoBERTa-NER")
model = AutoModelForTokenClassification.from_pretrained("Dizex/InstaFoodRoBERTa-NER")
pipe = pipeline("ner", model=model, tokenizer=tokenizer)
example = "Today's meal: Fresh olive poké bowl topped with chia seeds. Very delicious!"
ner_entity_results = pipe(example, aggregation_strategy="simple")
print(ner_entity_results)
若要将提取的食品实体转换为字符串列表,可使用以下代码:
def convert_entities_to_list(text, entities: list[dict]) -> list[str]:
ents = []
for ent in entities:
e = {"start": ent["start"], "end": ent["end"], "label": ent["entity_group"]}
if ents and -1 <= ent["start"] - ents[-1]["end"] <= 1 and ents[-1]["label"] == e["label"]:
ents[-1]["end"] = e["end"]
continue
ents.append(e)
return [text[e["start"]:e["end"]] for e in ents]
print(convert_entities_to_list(example, ner_entity_results))
运行上述代码将得到如下输出:
['olive poké bowl', 'chia seeds']
✨ 主要特性
- 针对性强:专门用于社交媒体非正规文本中的食品实体命名实体识别。
- 数据公开:基于公开的数据集进行微调训练,具有良好的可复现性。
📚 详细文档
模型描述
InstaFoodRoBERTa-NER 是一个基于 roberta-base 进行微调的模型。它在一个包含400条与食品相关的英文Instagram帖子的数据集上进行了微调。该 数据集 是开源的。
预期用途
本模型主要用于社交媒体上非正规文本(如Instagram、X、Reddit)中食品实体的命名实体识别。
🔧 技术细节
指标 |
值 |
F1值 |
0.91 |
精确率 |
0.89 |
召回率 |
0.93 |
📄 许可证
本项目采用MIT许可证。