Pochopení záměrů a entit

Building Chatbots in Python

Alan Nichol

Co-founder and CTO, Rasa

Příklad

Building Chatbots in Python

Záměry

restaurant_search lze vyjádřit mnoha způsoby:

  • Mám hlad
  • Ukaž mi dobré pizzerie
  • Chci vzít přítele na sushi
    • Může být také request_booking
Building Chatbots in Python

Entity

  • NER = rozpoznávání pojmenovaných entit
Building Chatbots in Python

Regulární výrazy pro rozpoznávání záměrů

  • Jednodušší než přístupy strojového učení
  • Velmi výpočetně efektivní
  • Nevýhoda:
    • Ladění regulárních výrazů může být obtížné
Building Chatbots in Python

Použití regulárních výrazů

  • '|' odpovídá operátoru OR
re.search(r"(hello|hey|hi)", "hey there!") is not None
True
re.search(r"(hello|hey|hi)", "which one?") is not None
True
Building Chatbots in Python

Použití regulárních výrazů

  • \b označuje začátek nebo konec slova
    re.search(r"\b(hello|hey|hi)\b", "hey there!") is not None
    
True
re.search(r"\b(hello|hey|hi)\b", "which one?") is not None
False
Building Chatbots in Python

Rozpoznávání entit pomocí regexu

pattern = re.compile('[A-Z]{1}[a-z]*')

message = """ Mary is a friend of mine, she studied at Oxford and now works at Google"""
pattern.findall(message)
['Mary', 'Oxford', 'Google']
Building Chatbots in Python

Lass uns üben!

Building Chatbots in Python

Preparing Video For Download...