File size: 423 Bytes
030432c |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
from transformers import pipeline
ner_pipeline = pipeline("ner", model="dslim/bert-base-NER", grouped_entities=True)
def extract_ingredients(text):
entities = ner_pipeline(text)
ingredients = []
for ent in entities:
word = ent['word'].lower().strip()
if ent['entity_group'] == 'MISC' and word.isalpha() and len(word) > 2:
ingredients.append(word)
return list(set(ingredients))
|