Coder Social home page Coder Social logo

lara-hungarian-nlp's Introduction

Lara is a super fast, lightweight Python3 NLP library for ChatBot AI development in Hungarian language.

Instead of being an all purpose NLP tool, Lara was created to fit the quirks and uniqueness of the Hungarian (online) language as much as possible. The library is capable of matching inflected forms of keywords in text messages written in Hungarian. It also comes with functions for text processing, and can even identify common expressions and small talk topics in discussions.

Lara is still in beta, so minor changes can still be expected in its API.

Table of contents

  1. About Lara
    1. Find intents
    2. Extract information
    3. Handle common topics
    4. Create ML features
    5. And much more
  2. Misc.

About Lara

Here is a short list of things you can easily do with Lara in Hungarian. For full documentation and further examples, CHECK OUT THE WIKI.

Find intents

With the Intents() Class, developers can easily match almost every possible inflected form of any keyword in Hungarian language. For example:

from lara import parser

ragozott_forma	= {
	"to_do"		: [{"stem":"csinál","wordclass":"verb"}],
}
ragozott_talalat= parser.Intents(ragozott_forma)

Will match the intent "to_do" in the following sentences:

  • Ő mit csinál a szobában?
  • Mit fogok még csinálni?
  • Mikor csináltad meg a szekrényt?
  • Megcsináltatták a berendezést.
  • Teljesen kicsinálva érzem magamat ettől a melegtől.
  • Csinálhatott volna mást is.
  • Visszacsinalnad az ekezeteket a billentyuzetemen, kerlek?

By defining the wordclass and stem of a keyword, Lara will generate possible patterns for text matching, without having to rely on large dictionaries!

from lara import parser

alma_intents	= {
	"alma"		: [{"stem":"alma","wordclass":"noun"}],
	"szed"		: [{"stem":"szed","wordclass":"verb"}],
	"piros"		: [{"stem":"piros","wordclass":"adjective"}]
}
alma_test		= parser.Intents(alma_intents)
print(alma_test.match("Mikor szedjük le a pirosabb almákat?"))

>>> {'alma': 1, 'szed': 2, 'piros': 2}

Extract information

It allows simple text processing:

from lara import parser

tweet		= 'A robotok elveszik a munkát! #NLP #ChatBot'
hashtags	= parser.Extract(tweet).hashtags()
print(hashtags)

>>> ['#nlp','#chatbot']

And normalization of extracted strings:

from lara import parser

sms		= 'Hívj fel! A számom 30/123 4567!'
info		= parser.Extract(sms)
print(info.phone_numbers(False))
print(info.phone_numbers(True))

>>> ['30/123 4567']
>>> ['+36 30 1234567']

It uses Black Magic™:

from lara import parser

sorcery		= 'Hívj fel ezen a számon 2018 IV. huszadikán mondjuk délután nyolc perccel háromnegyed kettő előtt!'
info		= parser.Extract(sorcery)
print(info.dates())
print(info.times())
	
>>> ['2018-04-20']
>>> ['13:37']

Handle common topics

Is able to engage in small talk:

from lara import parser, entities

user_text	= 'Te egy ember vagy, vagy egy intelligens számítógép vagy?'

chitchat	= entities.smalltalk()
chitchat_match	= parser.Intents(chitchat).match_set(user_text)
if 'are_you_a_robot' in chitchat_match:
	print('Egy számítógépet akkor nevezhetünk intelligensnek, ha át tud verni egy embert, hogy őt is embernek higgye.')
		
>>> Egy számítógépet akkor nevezhetünk intelligensnek, ha át tud verni egy embert, hogy őt is embernek higgye.

Understands when the user is just trying to mess with your ChatBot, instead of actually sending a request:

from lara import parser, entities

user_text	= 'Hasta la vista baby!'

references	= entities.popculture()
references_match= parser.Intents(references).match_set(user_text)
if references_match:
	print('Értem, egy másik AI-ra utaltál az üzenetedben.')
	if 'terminator' in references_match:
		print('Visszatérek!')
	elif 'matrix' in references_match:
		print('Minden dolog, aminek kezdete van, véget is ér.')
else:
	print('Ez egy valós üzenetnek tűnik!')
		
>>> Értem, egy másik AI-ra utaltál az üzenetedben.
>>> Visszatérek!

Create ML features

Can create features from short Hungarian texts for Machine Learning models, without large dictionaries:

from lara import tippmix, nlp

text 	= '''
	A szövegbányászat a strukturálatlan vagy kis mértékben strukturált 
	szöveges állományokból történő ismeret kinyerésének tudománya; 
	olyan különböző dokumentumforrásokból származó szöveges ismeretek
	és információk gépi intelligenciával történő kigyűjtése és 
	reprezentációja, amely a feldolgozás előtt rejtve és feltáratlanul 
	maradt az elemző előtt. 
	'''

clean	= nlp.remove_stopwords(text)
stems	= tippmix.stemmer(clean)
bigrams = nlp.ngram(stems,2)
print(bigrams)

>>> ['szövegbányász strukturál', 'strukturál kis', 'kis mér', 'mér strukturál', 'strukturál szöveg', 'szöveg állományok', ... 'mar elemz']

And much more

from lara import nlp

huszt	= ['Bús düledékeiden, Husztnak romvára megállék;',
	'Csend vala, felleg alól szállt fel az éjjeli hold.']

for line in husz:
	print(nlp.metre(line))
	
>>> ['-', 'u', 'u', '-', 'u', 'u', '-', '-', '-', '-', '-', 'u', 'u', '-', '-']
>>> ['-', 'u', 'u', '-', 'u', 'u', '-', '-', 'u', 'u', '-', 'u', 'u', '-']

Misc.

This project is licensed under the MIT License - see the LICENSE.md file for details. Feel free to use it for your own ChatBot solutions, since

Every civilization was built off the back of a disposable workforce... But I can only make so many.

Code by Richard Nagyfi, created at Kitchen Budapest in collaboration with the Institute of Advanced Studies. Special thanks to Peter Varo.

lara-hungarian-nlp's People

Contributors

sedthh avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.