🚀 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許可證。